From: Mike Yuan Date: Tue, 4 Mar 2025 17:49:04 +0000 (+0100) Subject: missing_syscall: drop raw_getpid() X-Git-Tag: v258-rc1~1185^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F36609%2Fhead;p=thirdparty%2Fsystemd.git missing_syscall: drop raw_getpid() This used to be relevant since in old versions of glibc an internal cache is maintained, while we might sidestep their invalidation with raw_clone(). After glibc 2.25 getpid() is a trivial wrapper for the syscall, and hence there's no need to have a separate raw_getpid(). --- diff --git a/src/basic/missing_syscall.h b/src/basic/missing_syscall.h index aae07a3f37d..296e39b919d 100644 --- a/src/basic/missing_syscall.h +++ b/src/basic/missing_syscall.h @@ -63,16 +63,6 @@ static inline int missing_ioprio_set(int which, int who, int ioprio) { /* ======================================================================= */ -static inline pid_t raw_getpid(void) { -#if defined(__alpha__) - return (pid_t) syscall(__NR_getxpid); -#else - return (pid_t) syscall(__NR_getpid); -#endif -} - -/* ======================================================================= */ - #if !HAVE_KCMP static inline int missing_kcmp(pid_t pid1, pid_t pid2, int type, unsigned long idx1, unsigned long idx2) { return syscall(__NR_kcmp, pid1, pid2, type, idx1, idx2); diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 80eeca6c0a8..c19890b7c36 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1441,7 +1441,7 @@ pid_t getpid_cached(void) { case CACHED_PID_UNSET: { /* Not initialized yet, then do so now */ pid_t new_pid; - new_pid = raw_getpid(); + new_pid = getpid(); if (!installed) { /* __register_atfork() either returns 0 or -ENOMEM, in its glibc implementation. Since it's @@ -1462,7 +1462,7 @@ pid_t getpid_cached(void) { } case CACHED_PID_BUSY: /* Somebody else is currently initializing */ - return raw_getpid(); + return getpid(); default: /* Properly initialized */ return current_value; diff --git a/src/basic/signal-util.c b/src/basic/signal-util.c index 7abee0d29f5..f5afe343076 100644 --- a/src/basic/signal-util.c +++ b/src/basic/signal-util.c @@ -280,13 +280,13 @@ void propagate_signal(int sig, siginfo_t *siginfo) { /* To be called from a signal handler. Will raise the same signal again, in our process + in our threads. * - * Note that we use raw_getpid() instead of getpid_cached(). We might have forked with raw_clone() + * Note that we use getpid() instead of getpid_cached(). We might have forked with raw_clone() * earlier (see PID 1), and hence let's go to the raw syscall here. In particular as this is not * performance sensitive code. * * Note that we use kill() rather than raise() as fallback, for similar reasons. */ - p = raw_getpid(); + p = getpid(); if (rt_tgsigqueueinfo(p, gettid(), sig, siginfo) < 0) assert_se(kill(p, sig) >= 0); diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 0f00089eece..e9a461b141b 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -581,7 +581,7 @@ TEST(getpid_cached) { siginfo_t si; pid_t a, b, c, d, e, f, child; - a = raw_getpid(); + a = getpid(); b = getpid_cached(); c = getpid(); @@ -593,7 +593,7 @@ TEST(getpid_cached) { if (child == 0) { /* In child */ - a = raw_getpid(); + a = getpid(); b = getpid_cached(); c = getpid(); @@ -602,7 +602,7 @@ TEST(getpid_cached) { _exit(EXIT_SUCCESS); } - d = raw_getpid(); + d = getpid(); e = getpid_cached(); f = getpid(); diff --git a/src/test/test-raw-clone.c b/src/test/test-raw-clone.c index 23ec7d1aa08..a43e2c2c29a 100644 --- a/src/test/test-raw-clone.c +++ b/src/test/test-raw-clone.c @@ -14,13 +14,13 @@ TEST(raw_clone) { parent = getpid(); log_info("before clone: getpid()→"PID_FMT, parent); - assert_se(raw_getpid() == parent); + assert_se(getpid() == parent); pid = raw_clone(0); assert_se(pid >= 0); - pid2 = raw_getpid(); - log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" raw_getpid()→"PID_FMT, + pid2 = getpid(); + log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" getpid()→"PID_FMT, pid, getpid(), pid2); if (pid == 0) { assert_se(pid2 != parent);