mailing list of musl libc
 help / color / mirror / code / Atom feed
2fbe23caeb506f85d1d652e9cc691abd8672da50 blob 961 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
#include <errno.h>
#include <pthread.h>
#include "libc.h"
#include "lock.h"

static struct atfork_funcs {
	void (*prepare)(void);
	void (*parent)(void);
	void (*child)(void);
	struct atfork_funcs *prev, *next;
} *funcs;

static volatile int lock[1];

void __fork_handler(int who)
{
	struct atfork_funcs *p;
	if (!funcs) return;
	if (who < 0) {
		LOCK(lock);
		for (p=funcs; p; p = p->next) {
			if (p->prepare) p->prepare();
			funcs = p;
		}
	} else {
		for (p=funcs; p; p = p->prev) {
			if (!who && p->parent) p->parent();
			else if (who && p->child) p->child();
			funcs = p;
		}
		UNLOCK(lock);
	}
}

int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void))
{
	struct atfork_funcs *new = malloc(sizeof *new);
	if (!new) return ENOMEM;

	LOCK(lock);
	new->next = funcs;
	new->prev = 0;
	new->prepare = prepare;
	new->parent = parent;
	new->child = child;
	if (funcs) funcs->prev = new;
	funcs = new;
	UNLOCK(lock);
	return 0;
}
debug log:

solving 2fbe23ca ...
found 2fbe23ca in https://inbox.vuxu.org/musl/20221112133101.253026-1-izbyshev@ispras.ru/
found 76497401 in https://git.vuxu.org/mirror/musl/
preparing index
index prepared:
100644 764974016576d6fe816f89da88220e78b86f46af	src/thread/pthread_atfork.c

applying [1/1] https://inbox.vuxu.org/musl/20221112133101.253026-1-izbyshev@ispras.ru/
diff --git a/src/thread/pthread_atfork.c b/src/thread/pthread_atfork.c
index 76497401..2fbe23ca 100644

Checking patch src/thread/pthread_atfork.c...
Applied patch src/thread/pthread_atfork.c cleanly.

index at:
100644 2fbe23caeb506f85d1d652e9cc691abd8672da50	src/thread/pthread_atfork.c

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).