]> Sergey Matveev's repositories - st.git/blobdiff - st.c
fix a problem that the standard streams are unexpectedly closed
[st.git] / st.c
diff --git a/st.c b/st.c
index ebdf3609b6a8eb6605791a91894868175b0ecc86..a9338e1a5771762cd0e53fb2f215dccd3378737e 100644 (file)
--- a/st.c
+++ b/st.c
@@ -793,14 +793,15 @@ ttynew(const char *line, char *cmd, const char *out, char **args)
                break;
        case 0:
                close(iofd);
+               close(m);
                setsid(); /* create a new process group */
                dup2(s, 0);
                dup2(s, 1);
                dup2(s, 2);
                if (ioctl(s, TIOCSCTTY, NULL) < 0)
                        die("ioctl TIOCSCTTY failed: %s\n", strerror(errno));
-               close(s);
-               close(m);
+               if (s > 2)
+                       close(s);
 #ifdef __OpenBSD__
                if (pledge("stdio getpw proc exec", NULL) == -1)
                        die("pledge\n");