getty: fix for NOCTTY killing us with SIGHUP
authorDenys Vlasenko <vda.linux@googlemail.com>
Thu, 26 Apr 2012 08:53:48 +0000 (10:53 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Thu, 26 Apr 2012 08:53:48 +0000 (10:53 +0200)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
loginutils/getty.c

index afb411b981f593c3fea6d6d3fd8b5cfcd1e8be03..bbb5a96b4237731e767041e711bda8eb6d7dceee 100644 (file)
@@ -561,8 +561,14 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
                 */
                fd = open("/dev/tty", O_RDWR | O_NONBLOCK);
                if (fd >= 0) {
+                       /* TIOCNOTTY sends SIGHUP to the foreground
+                        * process group - which may include us!
+                        * Make sure to not die on it:
+                        */
+                       sighandler_t old = signal(SIGHUP, SIG_IGN);
                        ioctl(fd, TIOCNOTTY);
                        close(fd);
+                       signal(SIGHUP, old);
                }
        }