]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
login: never send signals to init
authorSamanta Navarro <ferivoz@riseup.net>
Wed, 11 Jan 2023 11:57:21 +0000 (11:57 +0000)
committerSamanta Navarro <ferivoz@riseup.net>
Wed, 11 Jan 2023 11:57:55 +0000 (11:57 +0000)
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 <ferivoz@riseup.net>
login-utils/login.c

index 2c146b977781631f4bef943690f343b92ac71571..74bdf38a424f2795fc785d0e522887c1857f62ca 100644 (file)
@@ -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 */
 }
 
 /*