]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
stdout and stderr should be made O_NONBLOCK so that we don't end up blocking
authorBen Harris <bjh21@bjh21.me.uk>
Mon, 24 Sep 2007 19:26:08 +0000 (19:26 +0000)
committerBen Harris <bjh21@bjh21.me.uk>
Mon, 24 Sep 2007 19:26:08 +0000 (19:26 +0000)
the entire process because stdout is busy.

Arguably, this shouldn't apply to stderr when we're printing our own error
messages to it, but I'll leave that fix for another time.

[originally from svn r7738]

unix/uxplink.c

index 6b56d2af1fc5d61db6b7102006a91265b8921639..c1117e4391cc38c24f0c920744e1e66a5c417b5d 100644 (file)
@@ -385,7 +385,7 @@ void try_output(int is_stderr)
     ret = write(fd, senddata, sendlen);
     if (ret > 0)
        bufchain_consume(chain, ret);
-    else if (ret < 0) {
+    else if (ret < 0 && errno != EWOULDBLOCK) {
        perror(is_stderr ? "stderr: write" : "stdout: write");
        exit(1);
     }
@@ -883,6 +883,23 @@ int main(int argc, char **argv)
     local_tty = (tcgetattr(0, &orig_termios) == 0);
     atexit(cleanup_termios);
     ldisc_update(NULL, 1, 1);
+
+    {
+       int fl;
+       /*
+        * Make sure that stdout/err are non-blocking.
+        */
+       if ((fl = fcntl(1, F_GETFL)) == -1 ||
+           fcntl(1, F_SETFL, fl | O_NONBLOCK) == -1) {
+           perror("stdout");
+           exit(1);
+       }
+       if ((fl = fcntl(2, F_GETFL)) == -1 ||
+           fcntl(2, F_SETFL, fl | O_NONBLOCK) == -1) {
+           perror("stderr");
+           exit(1);
+       }
+    }
     sending = FALSE;
     now = GETTICKCOUNT();