udhcpc: fix a problem with binary-encoded options #2
[oweals/busybox.git] / loginutils / getty.c
index afb411b981f593c3fea6d6d3fd8b5cfcd1e8be03..e5d13bed6b8161d8822edd3e260fb99cff2b9ee8 100644 (file)
@@ -548,8 +548,15 @@ int getty_main(int argc UNUSED_PARAM, char **argv)
                 * a session leader - which is quite possible for getty!
                 */
                pid = getpid();
-               if (getsid(0) != pid)
+               if (getsid(0) != pid) {
+                       //for debugging:
+                       //bb_perror_msg_and_die("setsid failed:"
+                       //      " pid %d ppid %d"
+                       //      " sid %d pgid %d",
+                       //      pid, getppid(),
+                       //      getsid(0), getpgid(0));
                        bb_perror_msg_and_die("setsid");
+               }
                /* Looks like we are already a session leader.
                 * In this case (setsid failed) we may still have ctty,
                 * and it may be different from tty we need to control!
@@ -561,8 +568,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);
                }
        }