]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
do not call __register_atfork directly
authorMatija Skala <mskala@gmx.com>
Sat, 12 Feb 2022 05:05:54 +0000 (06:05 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 14 Feb 2022 09:49:43 +0000 (10:49 +0100)
this way it is cleaner and more portable and systemd links against libpthread anyway

src/basic/process-util.c

index 0bf7448043cfba712caeb6850e4055a6b5fade20..369edce816b2dc341c7580cfac7f255ea44cbfb2 100644 (file)
@@ -4,6 +4,7 @@
 #include <errno.h>
 #include <limits.h>
 #include <linux/oom.h>
+#include <pthread.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -1161,12 +1162,6 @@ void reset_cached_pid(void) {
         cached_pid = CACHED_PID_UNSET;
 }
 
-/* We use glibc __register_atfork() + __dso_handle directly here, as they are not included in the glibc
- * headers. __register_atfork() is mostly equivalent to pthread_atfork(), but doesn't require us to link against
- * libpthread, as it is part of glibc anyway. */
-extern int __register_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void), void *dso_handle);
-extern void* __dso_handle _weak_;
-
 pid_t getpid_cached(void) {
         static bool installed = false;
         pid_t current_value;
@@ -1194,7 +1189,7 @@ pid_t getpid_cached(void) {
                          * only half-documented (glibc doesn't document it but LSB does — though only superficially)
                          * we'll check for errors only in the most generic fashion possible. */
 
-                        if (__register_atfork(NULL, NULL, reset_cached_pid, __dso_handle) != 0) {
+                        if (pthread_atfork(NULL, NULL, reset_cached_pid) != 0) {
                                 /* OOM? Let's try again later */
                                 cached_pid = CACHED_PID_UNSET;
                                 return new_pid;