]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: getpid() → getpid_cached()
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Aug 2020 14:33:02 +0000 (16:33 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 22 Jun 2023 23:07:59 +0000 (17:07 -0600)
This doesn't really matter, but let's be systematic and prefer
getpid_cached() in our codebase.

src/basic/random-util.c
src/libsystemd/sd-event/test-event.c
src/libsystemd/sd-journal/journal-send.c
src/notify/notify.c
src/nspawn/nspawn.c
src/udev/udevd.c

index 98bcc7444c51489bc49ac8a82e95b0fe697fabaa..9a7d3480c03617f89b07a84887ce0531a1bcf2cd 100644 (file)
@@ -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(),
         };
 
index 50b6a793ce2088b344aedc305169ead17319cff4..7eb8fa10fcd4b0c382470d9e94b4e5b266b807c7 100644 (file)
@@ -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;
 
index d3e45756751463eff7b8a9b44cd8dd44fdac0fc2..da035a3a783d4bb8d08678aefcfa3b63d5033c2d 100644 (file)
@@ -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)
index f30790bc70b0f95d5d560386974315b61b653cac..675fbda752a33ad60bd12e0ee699224affaf8ede 100644 (file)
@@ -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)
index ab61184d9f914332c6e7f2df36b476b068996e3d..97a2c386e6bc82e27a835aa0f14bb903191930d7 100644 (file)
@@ -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);
index cf00576cfbe12bc9b83f1bbb26708c08fa6e876e..8cf359733851eb1fc5a53e5531302f953d4c2716 100644 (file)
@@ -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));