diff --git a/src/basic/random-util.c b/src/basic/random-util.c index 98bcc7444c5..9a7d3480c03 100644 --- a/src/basic/random-util.c +++ b/src/basic/random-util.c @@ -26,6 +26,7 @@ #include "missing_syscall.h" #include "missing_threads.h" #include "parse-util.h" +#include "process-util.h" #include "random-util.h" #include "sha256.h" #include "time-util.h" @@ -48,7 +49,7 @@ static void fallback_random_bytes(void *p, size_t n) { .call_id = fallback_counter++, .stamp_mono = now(CLOCK_MONOTONIC), .stamp_real = now(CLOCK_REALTIME), - .pid = getpid(), + .pid = getpid_cached(), .tid = gettid(), }; diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index 50b6a793ce2..7eb8fa10fcd 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -122,7 +122,7 @@ static int signal_handler(sd_event_source *s, const struct signalfd_siginfo *si, zero(plain_si); plain_si.si_signo = SIGUSR2; plain_si.si_code = SI_QUEUE; - plain_si.si_pid = getpid(); + plain_si.si_pid = getpid_cached(); plain_si.si_uid = getuid(); plain_si.si_value.sival_int = 4711; diff --git a/src/libsystemd/sd-journal/journal-send.c b/src/libsystemd/sd-journal/journal-send.c index d3e45756751..da035a3a783 100644 --- a/src/libsystemd/sd-journal/journal-send.c +++ b/src/libsystemd/sd-journal/journal-send.c @@ -22,6 +22,7 @@ #include "journal-send.h" #include "memfd-util.h" #include "missing_syscall.h" +#include "process-util.h" #include "socket-util.h" #include "stdio-util.h" #include "string-util.h" @@ -85,7 +86,7 @@ void close_journal_fd(void) { if (!RUNNING_ON_VALGRIND) return; - if (getpid() != gettid()) + if (getpid_cached() != gettid()) return; if (fd_plus_one <= 0) diff --git a/src/notify/notify.c b/src/notify/notify.c index f30790bc70b..675fbda752a 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -18,6 +18,7 @@ #include "main-func.h" #include "parse-util.h" #include "pretty-print.h" +#include "process-util.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" @@ -170,11 +171,11 @@ static int parse_argv(int argc, char *argv[]) { * manager's PID (which might be distinct from * 1, if we are a --user instance), that'd just * be confusing for the service manager */ - arg_pid = getpid(); + arg_pid = getpid_cached(); } else if (streq(optarg, "parent")) arg_pid = getppid(); else if (streq(optarg, "self")) - arg_pid = getpid(); + arg_pid = getpid_cached(); else { r = parse_pid(optarg, &arg_pid); if (r < 0) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index ab61184d9f9..97a2c386e6b 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5257,7 +5257,7 @@ static int run_container( if (r == 0) { _cleanup_close_ int parent_netns_fd = -EBADF; - r = namespace_open(getpid(), NULL, NULL, &parent_netns_fd, NULL, NULL); + r = namespace_open(getpid_cached(), NULL, NULL, &parent_netns_fd, NULL, NULL); if (r < 0) { log_error_errno(r, "Failed to open parent network namespace: %m"); _exit(EXIT_FAILURE); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index cf00576cfbe..8cf35973385 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -818,7 +818,7 @@ static int worker_spawn(Manager *manager, Event *event) { return log_error_errno(r, "Failed to fork() worker: %m"); } if (r == 0) { - DEVICE_TRACE_POINT(worker_spawned, event->dev, getpid()); + DEVICE_TRACE_POINT(worker_spawned, event->dev, getpid_cached()); /* Worker process */ r = worker_main(manager, worker_monitor, sd_device_ref(event->dev));