blob: 9e5c9433691325177af196fc32570bf6421d0c2f [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>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003Date: Thu, 25 Oct 2018 09:57:07 +0200
4Subject: [PATCH] musl: process-util
Brad Bishop316dfdd2018-06-25 12:45:53 -04005MIME-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
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080021index 1412f03..45f5049 100644
Brad Bishop316dfdd2018-06-25 12:45:53 -040022--- a/src/systemd/src/basic/process-util.c
23+++ b/src/systemd/src/basic/process-util.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080024@@ -21,6 +21,9 @@
Brad Bishop316dfdd2018-06-25 12:45:53 -040025 #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>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080034@@ -1153,11 +1156,13 @@ void reset_cached_pid(void) {
Brad Bishop316dfdd2018-06-25 12:45:53 -040035 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. */
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080042 extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void *dso_handle);
Brad Bishop316dfdd2018-06-25 12:45:53 -040043 extern void* __dso_handle __attribute__ ((__weak__));
44+#endif
45
46 pid_t getpid_cached(void) {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080047 static bool installed = false;
48@@ -1186,7 +1191,11 @@ pid_t getpid_cached(void) {
49 * only half-documented (glibc doesn't document it but LSB does — though only superficially)
50 * we'll check for errors only in the most generic fashion possible. */
Brad Bishop316dfdd2018-06-25 12:45:53 -040051
52+#ifdef __GLIBC__
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080053 if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) {
Brad Bishop316dfdd2018-06-25 12:45:53 -040054+#else
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055+ if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) {
Brad Bishop316dfdd2018-06-25 12:45:53 -040056+#endif
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080057 /* OOM? Let's try again later */
58 cached_pid = CACHED_PID_UNSET;
59 return new_pid;
Brad Bishop316dfdd2018-06-25 12:45:53 -040060--
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800612.14.5
Brad Bishop316dfdd2018-06-25 12:45:53 -040062