Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1 | From d513c8bfc982dbd976617178b040c512c95710b6 Mon Sep 17 00:00:00 2001 |
| 2 | From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 3 | Date: Thu, 25 Oct 2018 09:57:07 +0200 |
| 4 | Subject: [PATCH] musl: process-util |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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 | src/systemd/src/basic/process-util.c | 9 +++++++++ |
| 18 | 1 file changed, 9 insertions(+) |
| 19 | |
| 20 | diff --git a/src/systemd/src/basic/process-util.c b/src/systemd/src/basic/process-util.c |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 21 | index 1412f03..45f5049 100644 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 22 | --- a/src/systemd/src/basic/process-util.c |
| 23 | +++ b/src/systemd/src/basic/process-util.c |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 24 | @@ -21,6 +21,9 @@ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 34 | @@ -1153,11 +1156,13 @@ void reset_cached_pid(void) { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 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. */ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 42 | extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void *dso_handle); |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 43 | extern void* __dso_handle __attribute__ ((__weak__)); |
| 44 | +#endif |
| 45 | |
| 46 | pid_t getpid_cached(void) { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 47 | 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 Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 51 | |
| 52 | +#ifdef __GLIBC__ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 53 | if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 54 | +#else |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 55 | + if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 56 | +#endif |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 57 | /* OOM? Let's try again later */ |
| 58 | cached_pid = CACHED_PID_UNSET; |
| 59 | return new_pid; |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 60 | -- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame^] | 61 | 2.14.5 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 62 | |