ash: make code simpler, and do not do close(-1) - it's rude
authorDenis Vlasenko <vda.linux@googlemail.com>
Mon, 26 Nov 2007 05:37:07 +0000 (05:37 -0000)
committerDenis Vlasenko <vda.linux@googlemail.com>
Mon, 26 Nov 2007 05:37:07 +0000 (05:37 -0000)
shell/ash.c

index 7f7531650132c5ea47ef25d95b59f13881b668bb..8f388f59b22e804f4c0b42b6e6a962e801b37e84 100644 (file)
@@ -3461,14 +3461,17 @@ setjobctl(int on)
         * That sometimes helps to acquire controlling tty.
         * Obviously, a workaround for bugs when someone
         * failed to provide a controlling tty to bash! :) */
-                       fd += 3;
-                       while (!isatty(fd) && --fd >= 0)
-                               ;
+                       fd = 2;
+                       while (!isatty(fd))
+                               if (--fd < 0)
+                                       goto out;
                }
                fd = fcntl(fd, F_DUPFD, 10);
-               close(ofd);
+               if (ofd >= 0)
+                       close(ofd);
                if (fd < 0)
                        goto out;
+               /* fd is a tty at this point */
                close_on_exec_on(fd);
                do { /* while we are in the background */
                        pgrp = tcgetpgrp(fd);
@@ -3502,7 +3505,8 @@ setjobctl(int on)
                setsignal(SIGTTOU);
                setsignal(SIGTTIN);
  close:
-               close(fd);
+               if (fd >= 0)
+                       close(fd);
                fd = -1;
        }
        ttyfd = fd;