fix public clone function to be safe and usable by applications
[musl] / src / process / _Fork.c
index e765086..9c07792 100644 (file)
@@ -5,21 +5,13 @@
 #include "lock.h"
 #include "pthread_impl.h"
 #include "aio_impl.h"
+#include "fork_impl.h"
 
 static void dummy(int x) { }
 weak_alias(dummy, __aio_atfork);
 
-pid_t _Fork(void)
+void __post_Fork(int ret)
 {
-       pid_t ret;
-       sigset_t set;
-       __block_all_sigs(&set);
-       LOCK(__abort_lock);
-#ifdef SYS_fork
-       ret = __syscall(SYS_fork);
-#else
-       ret = __syscall(SYS_clone, SIGCHLD, 0);
-#endif
        if (!ret) {
                pthread_t self = __pthread_self();
                self->tid = __syscall(SYS_set_tid_address, &__thread_list_lock);
@@ -32,6 +24,20 @@ pid_t _Fork(void)
        }
        UNLOCK(__abort_lock);
        if (!ret) __aio_atfork(1);
+}
+
+pid_t _Fork(void)
+{
+       pid_t ret;
+       sigset_t set;
+       __block_all_sigs(&set);
+       LOCK(__abort_lock);
+#ifdef SYS_fork
+       ret = __syscall(SYS_fork);
+#else
+       ret = __syscall(SYS_clone, SIGCHLD, 0);
+#endif
+       __post_Fork(ret);
        __restore_sigs(&set);
        return __syscall_ret(ret);
 }