diff --git a/sysdeps/nacl/exit-thread.c b/sysdeps/nacl/exit-thread.c index bef2d103..5723796c 100644 --- a/sysdeps/nacl/exit-thread.c +++ b/sysdeps/nacl/exit-thread.c @@ -2,9 +2,18 @@ #include #include #include +#include void __exit_thread (int val) { + /* + * The NaCl IRT fork function copies the process memory as a whole to the child, so we need to + * flush the stdio buffers before calling it. + * Issue #12:https://github.com/Lind-Project/native_client/issues/12 + */ + fflush(stdout); + fflush(stderr); + /* We are about to die: make our pd "almost free" and wake up waiter. */ struct pthread* pd = THREAD_SELF; int count; diff --git a/sysdeps/nacl/fork.c b/sysdeps/nacl/fork.c index a12395cc..a63db314 100644 --- a/sysdeps/nacl/fork.c +++ b/sysdeps/nacl/fork.c @@ -1,6 +1,7 @@ #include #include #include +#include unsigned long int *__fork_generation_pointer; @@ -11,6 +12,14 @@ unsigned long int *__fork_generation_pointer; */ int __libc_fork(void) { + /* + * The NaCl IRT fork function copies the process memory as a whole to the child, so we need to + * flush the stdio buffers before calling it. + * Issue #12:https://github.com/Lind-Project/native_client/issues/12 + */ + fflush(stdout); + fflush(stderr); + int ret = __nacl_irt_fork(); if (!ret && __fork_generation_pointer) *__fork_generation_pointer += 4;