use libc-internal malloc for pthread_atfork
[musl] / src / thread / pthread_atfork.c
index a40d7f6..26d3254 100644 (file)
@@ -1,5 +1,12 @@
 #include <pthread.h>
+#include <errno.h>
 #include "libc.h"
+#include "lock.h"
+
+#define malloc __libc_malloc
+#define calloc undef
+#define realloc undef
+#define free undef
 
 static struct atfork_funcs {
        void (*prepare)(void);
@@ -8,7 +15,7 @@ static struct atfork_funcs {
        struct atfork_funcs *prev, *next;
 } *funcs;
 
-static volatile int lock[2];
+static volatile int lock[1];
 
 void __fork_handler(int who)
 {
@@ -33,7 +40,7 @@ void __fork_handler(int who)
 int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
 {
        struct atfork_funcs *new = malloc(sizeof *new);
-       if (!new) return -1;
+       if (!new) return ENOMEM;
 
        LOCK(lock);
        new->next = funcs;