Here is a new patch for this issue.

I went for the first solution for now, I suppose it’s a good enough™
fix for now. A better one should go to CHICKEN 5.

>From c66052c91e1622e0b3dc10cd01fc0dacf7d9827c Mon Sep 17 00:00:00 2001
From: Kooda <ko...@upyum.com>
Date: Sat, 19 Mar 2016 13:21:43 +0100
Subject: [PATCH] Cleanup process exit

This fixes bug #1269

See this mail thread for details:
http://lists.nongnu.org/archive/html/chicken-hackers/2016-03/msg00022.html
---
 chicken.h     | 2 +-
 posixunix.scm | 4 +++-
 runtime.c     | 6 +++---
 3 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/chicken.h b/chicken.h
index be5f308..0c985cf 100644
--- a/chicken.h
+++ b/chicken.h
@@ -906,7 +906,7 @@ typedef void (C_ccall *C_proc)(C_word, C_word *) C_noret;
 # define C_vfprintf                 vfprintf
 # define C_fflush                   fflush
 # define C_getchar                  getchar
-# define C_exit                     exit
+# define C_exit(x)                  { C_fflush(NULL); _exit(x); }
 # define C_dlopen                   dlopen
 # define C_dlclose                  dlclose
 # define C_dlsym                    dlsym
diff --git a/posixunix.scm b/posixunix.scm
index f56960d..ae1b9b0 100644
--- a/posixunix.scm
+++ b/posixunix.scm
@@ -1573,6 +1573,8 @@ EOF
 (define process-fork
   (let ((fork (foreign-lambda int "C_fork")))
     (lambda (#!optional thunk killothers)
+      ;; flush all stdio streams before fork
+      ((foreign-lambda int "fflush" c-pointer) #f)
       (let ((pid (fork)))
        (when (fx= -1 pid) 
          (posix-error #:process-error 'process-fork "cannot create child 
process"))
@@ -1582,7 +1584,7 @@ EOF
                 (lambda (thunk) (thunk)))
             (lambda ()
               (thunk)
-              ((foreign-lambda void "_exit" int) 0) ))
+              ((foreign-lambda void "C_exit" int) 0) ))
            pid)))))
 
 (define process-execute
diff --git a/runtime.c b/runtime.c
index 8e89ea3..2ac8c2f 100644
--- a/runtime.c
+++ b/runtime.c
@@ -1311,7 +1311,7 @@ void CHICKEN_parse_command_line(int argc, char *argv[], 
C_word *heap, C_word *st
                 " -:S              do not handle segfaults or other serious 
conditions\n"
                 "\n  SIZE may have a `k' (`K'), `m' (`M') or `g' (`G') suffix, 
meaning size\n"
                 "  times 1024, 1048576, and 1073741824, respectively.\n\n");
-         exit(0);
+         C_exit(0);
 
        case 'h':
          switch(*ptr) {
@@ -1527,7 +1527,7 @@ void C_ccall termination_continuation(C_word c, C_word 
*av)
     C_dbg(C_text("debug"), C_text("application terminated normally\n"));
   }
 
-  exit(0);
+  C_exit(0);
 }
 
 
@@ -4274,7 +4274,7 @@ void C_ccall C_stop_timer(C_word c, C_word *av)
 
 C_word C_exit_runtime(C_word code)
 {
-  exit(C_unfix(code));
+  C_exit(C_unfix(code));
   return 0;                    /* to please the compiler... */
 }
 
-- 
2.1.4

_______________________________________________
Chicken-hackers mailing list
Chicken-hackers@nongnu.org
https://lists.nongnu.org/mailman/listinfo/chicken-hackers

Reply via email to