blob: fc55ce85f6c7a3cd16cf018252d792d963d309e8 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From d513c8bfc982dbd976617178b040c512c95710b6 Mon Sep 17 00:00:00 2001
2From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
3Date: Thu, 22 Mar 2018 18:29:00 +0100
4Subject: [PATCH 4/4] musl: process-util
5MIME-Version: 1.0
6Content-Type: text/plain; charset=UTF-8
7Content-Transfer-Encoding: 8bit
8
9Upstream-Status: Pending
10
11Stolen from [1] and prettyfied slightly
12
13[1] https://github.com/voidlinux/void-packages/tree/master/srcpkgs/NetworkManager/patches
14
15Signed-off-by: Andreas MΓΌller <schnitzeltony@gmail.com>
16---
17 src/systemd/src/basic/process-util.c | 9 +++++++++
18 1 file changed, 9 insertions(+)
19
20diff --git a/src/systemd/src/basic/process-util.c b/src/systemd/src/basic/process-util.c
21index 272030d..485f1db 100644
22--- a/src/systemd/src/basic/process-util.c
23+++ b/src/systemd/src/basic/process-util.c
24@@ -36,6 +36,9 @@
25 #include <sys/wait.h>
26 #include <syslog.h>
27 #include <unistd.h>
28+#ifndef __GLIBC__
29+#include <pthread.h>
30+#endif
31 #if 0 /* NM_IGNORED */
32 #if HAVE_VALGRIND_VALGRIND_H
33 #include <valgrind/valgrind.h>
34@@ -1015,11 +1018,13 @@ static void reset_cached_pid(void) {
35 cached_pid = CACHED_PID_UNSET;
36 }
37
38+#ifdef __GLIBC__
39 /* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc
40 * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against
41 * libpthread, as it is part of glibc anyway. */
42 extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void * __dso_handle);
43 extern void* __dso_handle __attribute__ ((__weak__));
44+#endif
45
46 pid_t getpid_cached(void) {
47 pid_t current_value;
48@@ -1042,7 +1047,11 @@ pid_t getpid_cached(void) {
49
50 new_pid = getpid();
51
52+#ifdef __GLIBC__
53 if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) {
54+#else
55+ if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) {
56+#endif
57 /* OOM? Let's try again later */
58 cached_pid = CACHED_PID_UNSET;
59 return new_pid;
60--
612.14.3
62