From 776b0b278adc28e9661f0e329d95c0f446f9c769 Mon Sep 17 00:00:00 2001 From: Yashaswi Makula Date: Wed, 29 May 2024 01:09:27 +0000 Subject: [PATCH] stdout buffering flush --- sysdeps/nacl/exit-thread.c | 9 +++++++++ sysdeps/nacl/fork.c | 9 +++++++++ 2 files changed, 18 insertions(+) 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;