OSDN Git Service

When messing with fd NONBLOCK status, put things back the way we found
authorEric Andersen <andersen@codepoet.org>
Mon, 25 Feb 2002 15:06:10 +0000 (15:06 -0000)
committerEric Andersen <andersen@codepoet.org>
Mon, 25 Feb 2002 15:06:10 +0000 (15:06 -0000)
them afterwards.  As was, this hosed things up for fds shared with a
parent process.  Very bad for shells...  Oops.
 -Erik

libc/stdio/stdio.c

index 3f475ae..63fb6bd 100644 (file)
@@ -203,8 +203,11 @@ void __stdio_flush_buffers(void)
        if (WRITEABLE(fp)) {
            /* Set the underlying fd to non-block mode to ensure
             * that calls to _exit() and abort() will not block */
-           fcntl(fp->fd, F_SETFL, O_NONBLOCK);
+           long flags;
+           fcntl(fp->fd, F_GETFL, &flags);
+           fcntl(fp->fd, F_SETFL, flags|O_NONBLOCK);
            fflush(fp);
+           fcntl(fp->fd, F_SETFL, flags);
        }
     }
 }