diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2023-01-30 18:47:18 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2023-01-30 18:48:36 +0100 |
commit | 93ae7464e6e460f25b73e4ffefd2d9a6499eae30 (patch) | |
tree | 43bb098ff21711a3e2cd10ae35c9a7791e66fc57 | |
parent | 1fdb33bd07e52cea832a6584c79e9aa11987da1f (diff) | |
download | busybox-w32-93ae7464e6e460f25b73e4ffefd2d9a6499eae30.tar.gz busybox-w32-93ae7464e6e460f25b73e4ffefd2d9a6499eae30.tar.bz2 busybox-w32-93ae7464e6e460f25b73e4ffefd2d9a6499eae30.zip |
hush: restore SIGHUP handling, this time explain why we do what we do
function old new delta
check_and_run_traps 229 278 +49
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | shell/hush.c | 48 |
1 files changed, 28 insertions, 20 deletions
diff --git a/shell/hush.c b/shell/hush.c index 80a39925f..e6be70078 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -1829,12 +1829,13 @@ static void restore_G_args(save_arg_t *sv, char **argv) | |||
1829 | * SIGQUIT: ignore | 1829 | * SIGQUIT: ignore |
1830 | * SIGTERM (interactive): ignore | 1830 | * SIGTERM (interactive): ignore |
1831 | * SIGHUP (interactive): | 1831 | * SIGHUP (interactive): |
1832 | * send SIGCONT to stopped jobs, send SIGHUP to all jobs and exit | 1832 | * Send SIGCONT to stopped jobs, send SIGHUP to all jobs and exit. |
1833 | //HUP: we don't need to do this, kernel does this for us | 1833 | * Kernel would do this for us ("orphaned process group" handling |
1834 | //HUP: ("orphaned process group" handling according to POSIX). | 1834 | * according to POSIX) if we are a session leader and thus our death |
1835 | //HUP: We still have a SIGHUP handler, just to have tty pgrp restored | 1835 | * frees the controlling tty, but to be bash-compatible, we also do it |
1836 | //HUP: (otherwise e.g. Midnight Commander backgrounds when hush | 1836 | * for every interactive shell's death by SIGHUP. |
1837 | //HUP: started from it gets killed by SIGHUP). | 1837 | * (Also, we need to restore tty pgrp, otherwise e.g. Midnight Commander |
1838 | * backgrounds when hush started from it gets killed by SIGHUP). | ||
1838 | * SIGTTIN, SIGTTOU, SIGTSTP (if job control is on): ignore | 1839 | * SIGTTIN, SIGTTOU, SIGTSTP (if job control is on): ignore |
1839 | * Note that ^Z is handled not by trapping SIGTSTP, but by seeing | 1840 | * Note that ^Z is handled not by trapping SIGTSTP, but by seeing |
1840 | * that all pipe members are stopped. Try this in bash: | 1841 | * that all pipe members are stopped. Try this in bash: |
@@ -2183,20 +2184,27 @@ static int check_and_run_traps(void) | |||
2183 | break; | 2184 | break; |
2184 | #if ENABLE_HUSH_JOB | 2185 | #if ENABLE_HUSH_JOB |
2185 | case SIGHUP: { | 2186 | case SIGHUP: { |
2186 | //HUP//TODO: why are we doing this? ash and dash don't do this, | 2187 | /* if (G_interactive_fd) - no need to check, the handler |
2187 | //HUP//they have no handler for SIGHUP at all, | 2188 | * is only installed if we *are* interactive */ |
2188 | //HUP//they rely on kernel to send SIGHUP+SIGCONT to orphaned process groups | 2189 | { |
2189 | //HUP struct pipe *job; | 2190 | /* bash compat: "Before exiting, an interactive |
2190 | //HUP debug_printf_exec("%s: sig:%d default SIGHUP handler\n", __func__, sig); | 2191 | * shell resends the SIGHUP to all jobs, running |
2191 | //HUP /* bash is observed to signal whole process groups, | 2192 | * or stopped. Stopped jobs are sent SIGCONT |
2192 | //HUP * not individual processes */ | 2193 | * to ensure that they receive the SIGHUP." |
2193 | //HUP for (job = G.job_list; job; job = job->next) { | 2194 | */ |
2194 | //HUP if (job->pgrp <= 0) | 2195 | struct pipe *job; |
2195 | //HUP continue; | 2196 | debug_printf_exec("%s: sig:%d default SIGHUP handler\n", __func__, sig); |
2196 | //HUP debug_printf_exec("HUPing pgrp %d\n", job->pgrp); | 2197 | /* bash is observed to signal whole process groups, |
2197 | //HUP if (kill(- job->pgrp, SIGHUP) == 0) | 2198 | * not individual processes */ |
2198 | //HUP kill(- job->pgrp, SIGCONT); | 2199 | for (job = G.job_list; job; job = job->next) { |
2199 | //HUP } | 2200 | if (job->pgrp <= 0) |
2201 | continue; | ||
2202 | debug_printf_exec("HUPing pgrp %d\n", job->pgrp); | ||
2203 | if (kill(- job->pgrp, SIGHUP) == 0) | ||
2204 | kill(- job->pgrp, SIGCONT); | ||
2205 | } | ||
2206 | } | ||
2207 | /* this restores tty pgrp, then kills us with SIGHUP */ | ||
2200 | sigexit(SIGHUP); | 2208 | sigexit(SIGHUP); |
2201 | } | 2209 | } |
2202 | #endif | 2210 | #endif |