浏览代码

Per discussion with Manuel, when we call __stdio_flush_buffers
from abort() and from _exit(), we need to ensure that flushing
will not cause us to block. So use fcntl to set the fd's to
non-block mode...

Eric Andersen 23 年之前
父节点
当前提交
96da9a8ea6
共有 1 个文件被更改,包括 9 次插入1 次删除
  1. 9 1
      libc/stdio/stdio.c

+ 9 - 1
libc/stdio/stdio.c

@@ -198,7 +198,15 @@ char _free_buffer_index = FIXED_BUFFERS;
  */
 void __stdio_flush_buffers(void)
 {
-	fflush(NULL);				/* Files will be closed on _exit call. */
+    FILE *fp;
+    for (fp = __IO_list; fp; fp = fp->next) {
+	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);
+	    fflush(fp);
+	}
+    }
 }
 
 /*