[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox-cvs
Subject:    [git commit] hush: restore tty pgrp on SIGHUP
From:       Denys Vlasenko <vda.linux () googlemail ! com>
Date:       2023-01-30 15:49:48
Message-ID: 20230130155216.6E6C0821C2 () busybox ! osuosl ! org
[Download RAW message or body]

commit: https://git.busybox.net/busybox/commit/?id=1fdb33bd07e52cea832a6584c79e9aa11987da1f
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

Found one case where SIGHUP does need some handling.

ash does not restore tty pgrp when killed by SIGHUP, and
this means process which started ash needs to restore it,
or it would get backgrounded when trying to use tty.

function                                             old     new   delta
check_and_run_traps                                  214     229     +15

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
---
 shell/hush.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/shell/hush.c b/shell/hush.c
index 9b87e28cf..80a39925f 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -1831,7 +1831,10 @@ static void restore_G_args(save_arg_t *sv, char **argv)
  * SIGHUP (interactive):
  *    send SIGCONT to stopped jobs, send SIGHUP to all jobs and exit
 //HUP: we don't need to do this, kernel does this for us
-//HUP: ("orphaned process group" handling according to POSIX)
+//HUP: ("orphaned process group" handling according to POSIX).
+//HUP: We still have a SIGHUP handler, just to have tty pgrp restored
+//HUP: (otherwise e.g. Midnight Commander backgrounds when hush
+//HUP: started from it gets killed by SIGHUP).
  * SIGTTIN, SIGTTOU, SIGTSTP (if job control is on): ignore
  *    Note that ^Z is handled not by trapping SIGTSTP, but by seeing
  *    that all pipe members are stopped. Try this in bash:
@@ -1933,7 +1936,7 @@ enum {
 	SPECIAL_INTERACTIVE_SIGS = 0
 		| (1 << SIGTERM)
 		| (1 << SIGINT)
-//HUP		| (1 << SIGHUP)
+		| (1 << SIGHUP)
 		,
 	SPECIAL_JOBSTOP_SIGS = 0
 #if ENABLE_HUSH_JOB
@@ -2179,7 +2182,7 @@ static int check_and_run_traps(void)
 			last_sig = sig;
 			break;
 #if ENABLE_HUSH_JOB
-//HUP		case SIGHUP: {
+		case SIGHUP: {
 //HUP//TODO: why are we doing this? ash and dash don't do this,
 //HUP//they have no handler for SIGHUP at all,
 //HUP//they rely on kernel to send SIGHUP+SIGCONT to orphaned process groups
@@ -2194,8 +2197,8 @@ static int check_and_run_traps(void)
 //HUP				if (kill(- job->pgrp, SIGHUP) == 0)
 //HUP					kill(- job->pgrp, SIGCONT);
 //HUP			}
-//HUP			sigexit(SIGHUP);
-//HUP		}
+			sigexit(SIGHUP);
+		}
 #endif
 #if ENABLE_HUSH_FAST
 		case SIGCHLD:
_______________________________________________
busybox-cvs mailing list
busybox-cvs@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox-cvs
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic