From: Samanta Navarro Date: Wed, 11 Jan 2023 11:57:21 +0000 (+0000) Subject: login: never send signals to init X-Git-Tag: v2.39-rc1~167 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=4bbda92cdd0ceacc982f759d97d35b1617a8beba;p=thirdparty%2Futil-linux.git login: never send signals to init If the signal handler is triggered after a failed fork attempt, then child_pid will be -1. This in turn leads to a positive test and a subsequent call of kill(1, signal). If signal was SIGTERM, then there will be also another kill(1, SIGHUP) call. Test explicitly for a positive child_pid value to prevent these cases. Signed-off-by: Samanta Navarro --- diff --git a/login-utils/login.c b/login-utils/login.c index 2c146b9777..74bdf38a42 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -203,12 +203,12 @@ static void timedout(int sig __attribute__((__unused__))) */ static void sig_handler(int signal) { - if (child_pid) + if (child_pid > 0) { kill(-child_pid, signal); - else + if (signal == SIGTERM) + kill(-child_pid, SIGHUP); /* because the shell often ignores SIGTERM */ + } else got_sig = 1; - if (signal == SIGTERM) - kill(-child_pid, SIGHUP); /* because the shell often ignores SIGTERM */ } /*