fix bug whereby most atexit-registered functions got skipped
[musl] / src / stdio / __stdio_write.c
index dd97cf6..cef7bbd 100644 (file)
@@ -18,10 +18,15 @@ size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len)
        int iovcnt = 2;
        ssize_t cnt;
        for (;;) {
-               pthread_cleanup_push(cleanup, f);
-               cnt = syscall_cp(SYS_writev, f->fd, iov, iovcnt);
-               pthread_cleanup_pop(0);
+               if (libc.main_thread) {
+                       pthread_cleanup_push(cleanup, f);
+                       cnt = syscall_cp(SYS_writev, f->fd, iov, iovcnt);
+                       pthread_cleanup_pop(0);
+               } else {
+                       cnt = syscall(SYS_writev, f->fd, iov, iovcnt);
+               }
                if (cnt == rem) {
+                       f->wend = f->buf + f->buf_size;
                        f->wpos = f->wbase = f->buf;
                        return len;
                }