]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: move container_get_leader() to process-util.[ch]
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 5 Nov 2022 16:40:01 +0000 (17:40 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Nov 2022 12:41:13 +0000 (13:41 +0100)
basic/util.[ch] is a grab-bag of unrelated functions. Let's move a few
of the remaning functions to better locations.

src/basic/process-util.c
src/basic/process-util.h
src/basic/util.c
src/basic/util.h
src/libsystemd/sd-bus/bus-container.c
src/shared/logs-show.c

index 0213f5913f5fed4da784e50150e806aa97b0e124..6e4a56b0aac14790a3145daf53feafb7c61ec9ac 100644 (file)
 
 #include "alloc-util.h"
 #include "architecture.h"
+#include "env-file.h"
 #include "env-util.h"
 #include "errno-util.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
+#include "hostname-util.h"
 #include "locale-util.h"
 #include "log.h"
 #include "macro.h"
@@ -35,6 +37,7 @@
 #include "missing_sched.h"
 #include "missing_syscall.h"
 #include "namespace-util.h"
+#include "parse-util.h"
 #include "path-util.h"
 #include "process-util.h"
 #include "raw-clone.h"
@@ -253,6 +256,47 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
         return 0;
 }
 
+int container_get_leader(const char *machine, pid_t *pid) {
+        _cleanup_free_ char *s = NULL, *class = NULL;
+        const char *p;
+        pid_t leader;
+        int r;
+
+        assert(machine);
+        assert(pid);
+
+        if (streq(machine, ".host")) {
+                *pid = 1;
+                return 0;
+        }
+
+        if (!hostname_is_valid(machine, 0))
+                return -EINVAL;
+
+        p = strjoina("/run/systemd/machines/", machine);
+        r = parse_env_file(NULL, p,
+                           "LEADER", &s,
+                           "CLASS", &class);
+        if (r == -ENOENT)
+                return -EHOSTDOWN;
+        if (r < 0)
+                return r;
+        if (!s)
+                return -EIO;
+
+        if (!streq_ptr(class, "container"))
+                return -EIO;
+
+        r = parse_pid(s, &leader);
+        if (r < 0)
+                return r;
+        if (leader <= 1)
+                return -EIO;
+
+        *pid = leader;
+        return 0;
+}
+
 static int update_argv(const char name[], size_t l) {
         static int can_do = -1;
 
index ed2f73673e7aaea7e58a3537b4ee5d7a4e45ebda..d5986ad64699d4a78cf67e50d0295ec7091a9ea3 100644 (file)
@@ -50,6 +50,8 @@ int get_process_environ(pid_t pid, char **ret);
 int get_process_ppid(pid_t pid, pid_t *ret);
 int get_process_umask(pid_t pid, mode_t *ret);
 
+int container_get_leader(const char *machine, pid_t *pid);
+
 int wait_for_terminate(pid_t pid, siginfo_t *status);
 
 typedef enum WaitFlags {
index c47ea4584b9b9db41023560328007806ba90604f..74f5ad7236ae8393769d38820def34d3f6aea1eb 100644 (file)
 int saved_argc = 0;
 char **saved_argv = NULL;
 
-int container_get_leader(const char *machine, pid_t *pid) {
-        _cleanup_free_ char *s = NULL, *class = NULL;
-        const char *p;
-        pid_t leader;
-        int r;
-
-        assert(machine);
-        assert(pid);
-
-        if (streq(machine, ".host")) {
-                *pid = 1;
-                return 0;
-        }
-
-        if (!hostname_is_valid(machine, 0))
-                return -EINVAL;
-
-        p = strjoina("/run/systemd/machines/", machine);
-        r = parse_env_file(NULL, p,
-                           "LEADER", &s,
-                           "CLASS", &class);
-        if (r == -ENOENT)
-                return -EHOSTDOWN;
-        if (r < 0)
-                return r;
-        if (!s)
-                return -EIO;
-
-        if (!streq_ptr(class, "container"))
-                return -EIO;
-
-        r = parse_pid(s, &leader);
-        if (r < 0)
-                return r;
-        if (leader <= 1)
-                return -EIO;
-
-        *pid = leader;
-        return 0;
-}
-
 int version(void) {
         printf("systemd " STRINGIFY(PROJECT_VERSION) " (" GIT_VERSION ")\n%s\n",
                systemd_features);
index 347e4fe4b03dc63c338fabd35d69b3ead40a3dc1..6438555c6ca3cf50a4857fc2a86facd1c65420e7 100644 (file)
@@ -66,8 +66,6 @@ static inline unsigned log2u_round_up(unsigned x) {
         return log2u(x - 1) + 1;
 }
 
-int container_get_leader(const char *machine, pid_t *pid);
-
 int version(void);
 
 void disable_coredumps(void);
index b3c0279c0bd8a49a614d81d91a8f24257117e152..b9a38269d9d0518d5fde59dec49b99bad02541c5 100644 (file)
@@ -10,7 +10,6 @@
 #include "namespace-util.h"
 #include "process-util.h"
 #include "string-util.h"
-#include "util.h"
 
 int bus_container_connect_socket(sd_bus *b) {
         _cleanup_close_pair_ int pair[2] = { -1, -1 };
index 2b180a8c0f6845632a36498b7f8ef135f16d81bd..7972fc009e582a732e88b1c678d2f466eae63290 100644 (file)
@@ -40,7 +40,6 @@
 #include "terminal-util.h"
 #include "time-util.h"
 #include "utf8.h"
-#include "util.h"
 #include "web-util.h"
 
 /* up to three lines (each up to 100 characters) or 300 characters, whichever is less */