Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | From 4f2fb1e1f785bad22df8f3d96cb4792acf21f315 Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com> |
| 3 | Date: Thu, 25 Oct 2018 09:57:07 +0200 |
| 4 | Subject: [PATCH] musl: process-util |
| 5 | MIME-Version: 1.0 |
| 6 | Content-Type: text/plain; charset=UTF-8 |
| 7 | Content-Transfer-Encoding: 8bit |
| 8 | |
| 9 | Upstream-Status: Pending |
| 10 | |
| 11 | Stolen from [1] and prettyfied slightly |
| 12 | |
| 13 | [1] https://github.com/voidlinux/void-packages/tree/master/srcpkgs/NetworkManager/patches |
| 14 | |
| 15 | Signed-off-by: Andreas Müller <schnitzeltony@gmail.com> |
| 16 | |
| 17 | --- |
| 18 | shared/systemd/src/basic/process-util.c | 9 +++++++++ |
| 19 | 1 file changed, 9 insertions(+) |
| 20 | |
| 21 | diff --git a/shared/systemd/src/basic/process-util.c b/shared/systemd/src/basic/process-util.c |
| 22 | index b0afb5c..7adc8bd 100644 |
| 23 | --- a/shared/systemd/src/basic/process-util.c |
| 24 | +++ b/shared/systemd/src/basic/process-util.c |
| 25 | @@ -21,6 +21,9 @@ |
| 26 | #include <sys/wait.h> |
| 27 | #include <syslog.h> |
| 28 | #include <unistd.h> |
| 29 | +#ifndef __GLIBC__ |
| 30 | +#include <pthread.h> |
| 31 | +#endif |
| 32 | #if 0 /* NM_IGNORED */ |
| 33 | #if HAVE_VALGRIND_VALGRIND_H |
| 34 | #include <valgrind/valgrind.h> |
| 35 | @@ -1168,11 +1171,13 @@ void reset_cached_pid(void) { |
| 36 | cached_pid = CACHED_PID_UNSET; |
| 37 | } |
| 38 | |
| 39 | +#ifdef __GLIBC__ |
| 40 | /* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc |
| 41 | * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against |
| 42 | * libpthread, as it is part of glibc anyway. */ |
| 43 | extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void *dso_handle); |
| 44 | extern void* __dso_handle _weak_; |
| 45 | +#endif |
| 46 | |
| 47 | pid_t getpid_cached(void) { |
| 48 | static bool installed = false; |
| 49 | @@ -1201,7 +1206,11 @@ pid_t getpid_cached(void) { |
| 50 | * only half-documented (glibc doesn't document it but LSB does — though only superficially) |
| 51 | * we'll check for errors only in the most generic fashion possible. */ |
| 52 | |
| 53 | +#ifdef __GLIBC__ |
| 54 | if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) { |
| 55 | +#else |
| 56 | + if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) { |
| 57 | +#endif |
| 58 | /* OOM? Let's try again later */ |
| 59 | cached_pid = CACHED_PID_UNSET; |
| 60 | return new_pid; |