udhcpc: fix a problem with binary-encoded options #2
[oweals/busybox.git] / loginutils / getty.c
index 1f417591bdb104796f4f2dcec84694f4ddc77a6a..e5d13bed6b8161d8822edd3e260fb99cff2b9ee8 100644 (file)
@@ -294,8 +294,10 @@ static void init_tty_attrs(int speed)
        /* non-raw output; add CR to each NL */
        G.tty_attrs.c_oflag = OPOST | ONLCR;
 
-       G.tty_attrs.c_cc[VMIN] = 1; /* block reads if < 1 char is available */
-       G.tty_attrs.c_cc[VTIME] = 0; /* no timeout (reads block forever) */
+       /* reads would block only if < 1 char is available */
+       G.tty_attrs.c_cc[VMIN] = 1;
+       /* no timeout (reads block forever) */
+       G.tty_attrs.c_cc[VTIME] = 0;
 #ifdef __linux__
        G.tty_attrs.c_line = 0;
 #endif
@@ -546,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!
@@ -559,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);
                }
        }