* move tty_close() up so that we can call it in tty_init()
 * bump tfd's assignment into its own line
 * realize that those if conditions are identical

Index: tty.c
===================================================================
RCS file: /cvs/src/bin/ksh/tty.c,v
retrieving revision 1.10
diff -u -p -r1.10 tty.c
--- tty.c       10 Aug 2014 02:44:26 -0000      1.10
+++ tty.c       12 Sep 2015 05:19:50 -0000
@@ -6,6 +6,15 @@
 #include "tty.h"
 #undef EXTERN
 
+void
+tty_close(void)
+{
+       if (tty_fd >= 0) {
+               close(tty_fd);
+               tty_fd = -1;
+       }
+}
+
 /* Initialize tty_fd.  Used for saving/reseting tty modes upon
  * foreground job completion and for setting up tty process group.
  */
@@ -15,19 +24,15 @@ tty_init(int init_ttystate)
        int     do_close = 1;
        int     tfd;
 
-       if (tty_fd >= 0) {
-               close(tty_fd);
-               tty_fd = -1;
-       }
+       tty_close();
        tty_devtty = 1;
 
-       if ((tfd = open("/dev/tty", O_RDWR, 0)) < 0) {
+       tfd = open("/dev/tty", O_RDWR, 0);
+       if (tfd < 0) {
                tty_devtty = 0;
                warningf(false, "No controlling tty (open /dev/tty: %s)",
                    strerror(errno));
-       }
 
-       if (tfd < 0) {
                do_close = 0;
                if (isatty(0))
                        tfd = 0;
@@ -45,13 +50,4 @@ tty_init(int init_ttystate)
                tcgetattr(tty_fd, &tty_state);
        if (do_close)
                close(tfd);
-}
-
-void
-tty_close(void)
-{
-       if (tty_fd >= 0) {
-               close(tty_fd);
-               tty_fd = -1;
-       }
 }

Reply via email to