diff --git a/libguile/posix.c b/libguile/posix.c index b0fcad5fd..088e75631 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1209,6 +1209,13 @@ SCM_DEFINE (scm_execle, "execle", 2, 0, 1, #undef FUNC_NAME #ifdef HAVE_FORK +static void * +do_fork (void *pidp) +{ + * (int *) pidp = fork (); + return NULL; +} + SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0, (), "Creates a new \"child\" process by duplicating the current \"parent\" process.\n" @@ -1236,7 +1243,13 @@ SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0, " further behavior unspecified. See \"Processes\" in the\n" " manual, for more information.\n"), scm_current_warning_port ()); - pid = fork (); + + /* Take the alloc lock to make sure it is released when the child + process starts. Failing to do that the child process could start + in a state where the alloc lock is taken and will never be + released. */ + GC_call_with_alloc_lock (do_fork, &pid); + if (pid == -1) SCM_SYSERROR; return scm_from_int (pid);