]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
process-util: move a couple of process-related calls over
authorLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 13:24:58 +0000 (14:24 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 27 Oct 2015 13:24:58 +0000 (14:24 +0100)
13 files changed:
src/basic/process-util.c
src/basic/process-util.h
src/basic/util.c
src/basic/util.h
src/core/busname.c
src/core/dbus-execute.c
src/core/load-fragment.c
src/core/mount.c
src/core/socket.c
src/core/swap.c
src/nspawn/nspawn-settings.c
src/shared/bus-util.c
src/shared/conf-parser.c

index a737686ab0ccd8687ab0ad95e345aadc99c334c5..7631928d5f11a0ba9c73930412204edacc534c12 100644 (file)
 #include <assert.h>
 #include <ctype.h>
 #include <errno.h>
+#include <sched.h>
 #include <signal.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <string.h>
+#include <sys/personality.h>
 #include <sys/prctl.h>
 #include <sys/types.h>
 #include <sys/wait.h>
 #include "fd-util.h"
 #include "fileio.h"
 #include "fs-util.h"
+#include "ioprio.h"
 #include "log.h"
 #include "process-util.h"
 #include "signal-util.h"
+#include "string-table.h"
 #include "string-util.h"
 #include "user-util.h"
 #include "util.h"
@@ -633,3 +637,120 @@ bool is_main_thread(void) {
 
         return cached > 0;
 }
+
+noreturn void freeze(void) {
+
+        /* Make sure nobody waits for us on a socket anymore */
+        close_all_fds(NULL, 0);
+
+        sync();
+
+        for (;;)
+                pause();
+}
+
+bool oom_score_adjust_is_valid(int oa) {
+        return oa >= OOM_SCORE_ADJ_MIN && oa <= OOM_SCORE_ADJ_MAX;
+}
+
+unsigned long personality_from_string(const char *p) {
+
+        /* Parse a personality specifier. We introduce our own
+         * identifiers that indicate specific ABIs, rather than just
+         * hints regarding the register size, since we want to keep
+         * things open for multiple locally supported ABIs for the
+         * same register size. We try to reuse the ABI identifiers
+         * used by libseccomp. */
+
+#if defined(__x86_64__)
+
+        if (streq(p, "x86"))
+                return PER_LINUX32;
+
+        if (streq(p, "x86-64"))
+                return PER_LINUX;
+
+#elif defined(__i386__)
+
+        if (streq(p, "x86"))
+                return PER_LINUX;
+
+#elif defined(__s390x__)
+
+        if (streq(p, "s390"))
+                return PER_LINUX32;
+
+        if (streq(p, "s390x"))
+                return PER_LINUX;
+
+#elif defined(__s390__)
+
+        if (streq(p, "s390"))
+                return PER_LINUX;
+#endif
+
+        return PERSONALITY_INVALID;
+}
+
+const char* personality_to_string(unsigned long p) {
+
+#if defined(__x86_64__)
+
+        if (p == PER_LINUX32)
+                return "x86";
+
+        if (p == PER_LINUX)
+                return "x86-64";
+
+#elif defined(__i386__)
+
+        if (p == PER_LINUX)
+                return "x86";
+
+#elif defined(__s390x__)
+
+        if (p == PER_LINUX)
+                return "s390x";
+
+        if (p == PER_LINUX32)
+                return "s390";
+
+#elif defined(__s390__)
+
+        if (p == PER_LINUX)
+                return "s390";
+
+#endif
+
+        return NULL;
+}
+
+static const char *const ioprio_class_table[] = {
+        [IOPRIO_CLASS_NONE] = "none",
+        [IOPRIO_CLASS_RT] = "realtime",
+        [IOPRIO_CLASS_BE] = "best-effort",
+        [IOPRIO_CLASS_IDLE] = "idle"
+};
+
+DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, INT_MAX);
+
+static const char *const sigchld_code_table[] = {
+        [CLD_EXITED] = "exited",
+        [CLD_KILLED] = "killed",
+        [CLD_DUMPED] = "dumped",
+        [CLD_TRAPPED] = "trapped",
+        [CLD_STOPPED] = "stopped",
+        [CLD_CONTINUED] = "continued",
+};
+
+DEFINE_STRING_TABLE_LOOKUP(sigchld_code, int);
+
+static const char* const sched_policy_table[] = {
+        [SCHED_OTHER] = "other",
+        [SCHED_BATCH] = "batch",
+        [SCHED_IDLE] = "idle",
+        [SCHED_FIFO] = "fifo",
+        [SCHED_RR] = "rr"
+};
+
+DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX);
index 85fc8d8eb78be4835ae699df54ac957cc14c6182..72633ebf70581ff29ec5d26e5aa3c115cdfb2c6d 100644 (file)
@@ -27,6 +27,7 @@
 #include <signal.h>
 
 #include "formats-util.h"
+#include "macro.h"
 
 #define procfs_file_alloca(pid, field)                                  \
         ({                                                              \
@@ -71,5 +72,28 @@ bool pid_is_unwaited(pid_t pid);
 
 bool is_main_thread(void);
 
+noreturn void freeze(void);
+
+bool oom_score_adjust_is_valid(int oa);
+
+#ifndef PERSONALITY_INVALID
+/* personality(7) documents that 0xffffffffUL is used for querying the
+ * current personality, hence let's use that here as error
+ * indicator. */
+#define PERSONALITY_INVALID 0xffffffffLU
+#endif
+
+unsigned long personality_from_string(const char *p);
+const char *personality_to_string(unsigned long);
+
+int ioprio_class_to_string_alloc(int i, char **s);
+int ioprio_class_from_string(const char *s);
+
+const char *sigchld_code_to_string(int i) _const_;
+int sigchld_code_from_string(const char *s) _pure_;
+
+int sched_policy_to_string_alloc(int i, char **s);
+int sched_policy_from_string(const char *s);
+
 #define PTR_TO_PID(p) ((pid_t) ((uintptr_t) p))
 #define PID_TO_PTR(p) ((void*) ((uintptr_t) p))
index 2451da3658cafc08d48f95dac27ab6f107f67f27..7d9dad472b925d23c0f8c47aa67768d034cb17ff 100644 (file)
@@ -125,17 +125,6 @@ size_t page_size(void) {
         return pgsz;
 }
 
-noreturn void freeze(void) {
-
-        /* Make sure nobody waits for us on a socket anymore */
-        close_all_fds(NULL, 0);
-
-        sync();
-
-        for (;;)
-                pause();
-}
-
 static int do_execute(char **directories, usec_t timeout, char *argv[]) {
         _cleanup_hashmap_free_free_ Hashmap *pids = NULL;
         _cleanup_set_free_free_ Set *seen = NULL;
@@ -374,36 +363,6 @@ int block_get_whole_disk(dev_t d, dev_t *ret) {
         return -ENOENT;
 }
 
-static const char *const ioprio_class_table[] = {
-        [IOPRIO_CLASS_NONE] = "none",
-        [IOPRIO_CLASS_RT] = "realtime",
-        [IOPRIO_CLASS_BE] = "best-effort",
-        [IOPRIO_CLASS_IDLE] = "idle"
-};
-
-DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(ioprio_class, int, INT_MAX);
-
-static const char *const sigchld_code_table[] = {
-        [CLD_EXITED] = "exited",
-        [CLD_KILLED] = "killed",
-        [CLD_DUMPED] = "dumped",
-        [CLD_TRAPPED] = "trapped",
-        [CLD_STOPPED] = "stopped",
-        [CLD_CONTINUED] = "continued",
-};
-
-DEFINE_STRING_TABLE_LOOKUP(sigchld_code, int);
-
-static const char* const sched_policy_table[] = {
-        [SCHED_OTHER] = "other",
-        [SCHED_BATCH] = "batch",
-        [SCHED_IDLE] = "idle",
-        [SCHED_FIFO] = "fifo",
-        [SCHED_RR] = "rr"
-};
-
-DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(sched_policy, int, INT_MAX);
-
 bool kexec_loaded(void) {
        bool loaded = false;
        char *s;
@@ -849,78 +808,6 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
         return reset_uid_gid();
 }
 
-unsigned long personality_from_string(const char *p) {
-
-        /* Parse a personality specifier. We introduce our own
-         * identifiers that indicate specific ABIs, rather than just
-         * hints regarding the register size, since we want to keep
-         * things open for multiple locally supported ABIs for the
-         * same register size. We try to reuse the ABI identifiers
-         * used by libseccomp. */
-
-#if defined(__x86_64__)
-
-        if (streq(p, "x86"))
-                return PER_LINUX32;
-
-        if (streq(p, "x86-64"))
-                return PER_LINUX;
-
-#elif defined(__i386__)
-
-        if (streq(p, "x86"))
-                return PER_LINUX;
-
-#elif defined(__s390x__)
-
-        if (streq(p, "s390"))
-                return PER_LINUX32;
-
-        if (streq(p, "s390x"))
-                return PER_LINUX;
-
-#elif defined(__s390__)
-
-        if (streq(p, "s390"))
-                return PER_LINUX;
-#endif
-
-        return PERSONALITY_INVALID;
-}
-
-const char* personality_to_string(unsigned long p) {
-
-#if defined(__x86_64__)
-
-        if (p == PER_LINUX32)
-                return "x86";
-
-        if (p == PER_LINUX)
-                return "x86-64";
-
-#elif defined(__i386__)
-
-        if (p == PER_LINUX)
-                return "x86";
-
-#elif defined(__s390x__)
-
-        if (p == PER_LINUX)
-                return "s390x";
-
-        if (p == PER_LINUX32)
-                return "s390";
-
-#elif defined(__s390__)
-
-        if (p == PER_LINUX)
-                return "s390";
-
-#endif
-
-        return NULL;
-}
-
 uint64_t physical_memory(void) {
         long mem;
 
@@ -978,7 +865,3 @@ bool fdname_is_valid(const char *s) {
 
         return p - s < 256;
 }
-
-bool oom_score_adjust_is_valid(int oa) {
-        return oa >= OOM_SCORE_ADJ_MIN && oa <= OOM_SCORE_ADJ_MAX;
-}
index fc329a869bf720787574ea360176181282b2cc3b..57dc5e8d46b4bd8177a813515846ae76dfbaadc4 100644 (file)
@@ -66,8 +66,6 @@ static inline const char* one_zero(bool b) {
         return b ? "1" : "0";
 }
 
-noreturn void freeze(void);
-
 void execute_directories(const char* const* directories, usec_t timeout, char *argv[]);
 
 bool plymouth_running(void);
@@ -83,15 +81,6 @@ int block_get_whole_disk(dev_t d, dev_t *ret);
 #define NULSTR_FOREACH_PAIR(i, j, l)                             \
         for ((i) = (l), (j) = strchr((i), 0)+1; (i) && *(i); (i) = strchr((j), 0)+1, (j) = *(i) ? strchr((i), 0)+1 : (i))
 
-int ioprio_class_to_string_alloc(int i, char **s);
-int ioprio_class_from_string(const char *s);
-
-const char *sigchld_code_to_string(int i) _const_;
-int sigchld_code_from_string(const char *s) _pure_;
-
-int sched_policy_to_string_alloc(int i, char **s);
-int sched_policy_from_string(const char *s);
-
 extern int saved_argc;
 extern char **saved_argv;
 
@@ -188,16 +177,6 @@ int container_get_leader(const char *machine, pid_t *pid);
 int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *userns_fd, int *root_fd);
 int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd);
 
-#ifndef PERSONALITY_INVALID
-/* personality(7) documents that 0xffffffffUL is used for querying the
- * current personality, hence let's use that here as error
- * indicator. */
-#define PERSONALITY_INVALID 0xffffffffLU
-#endif
-
-unsigned long personality_from_string(const char *p);
-const char *personality_to_string(unsigned long);
-
 uint64_t physical_memory(void);
 
 int update_reboot_param_file(const char *param);
@@ -217,5 +196,3 @@ union inotify_event_buffer {
 int version(void);
 
 bool fdname_is_valid(const char *s);
-
-bool oom_score_adjust_is_valid(int oa);
index 9fed54ffc8d582a027696a5a8cc95c00afe23b33..3592f72fe5f46b3041ea6710856dd45638bd99b7 100644 (file)
@@ -32,6 +32,7 @@
 #include "formats-util.h"
 #include "kdbus.h"
 #include "parse-util.h"
+#include "process-util.h"
 #include "service.h"
 #include "signal-util.h"
 #include "special.h"
index 882a76e9889d5ed2ec1309c0878631be607a2b42..04a5a22b72ae042aeb05213e9018b7b037914d09 100644 (file)
@@ -39,6 +39,7 @@
 #include "namespace.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "process-util.h"
 #include "rlimit-util.h"
 #ifdef HAVE_SECCOMP
 #include "seccomp-util.h"
index c1d09e8e5a2bef4a740024b2779a7e871d428199..ecfdb80debc94e55e0438f251f1053bc5454b47a 100644 (file)
@@ -52,6 +52,7 @@
 #include "missing.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "process-util.h"
 #ifdef HAVE_SECCOMP
 #include "seccomp-util.h"
 #endif
index 77b5ec27eb45e7e92de1c07711c9af51bb374db3..2761f632bdec3b962a9dddca6398f0ca5378b20b 100644 (file)
@@ -40,6 +40,7 @@
 #include "mount.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "process-util.h"
 #include "smack-util.h"
 #include "special.h"
 #include "string-table.h"
index d8b8cf576aa9ad825e9cf9fd3071e0cd62a9bf7f..f62466c6a0a5a221b9395afeabfe89a9ff66881b 100644 (file)
@@ -46,6 +46,7 @@
 #include "mkdir.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "process-util.h"
 #include "selinux-util.h"
 #include "signal-util.h"
 #include "smack-util.h"
index 5be3c709bf0545f663409d81bfcb2027d3dda807..6eff6ffb4c0ecdbad3fd18800108ee67ae605430 100644 (file)
@@ -35,6 +35,7 @@
 #include "fstab-util.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "process-util.h"
 #include "special.h"
 #include "string-table.h"
 #include "string-util.h"
index ee9e70acec81d5de795f15423fb1277738e29d43..6885d0641eba153b573e1a330048cefaf0358856 100644 (file)
 ***/
 
 #include "alloc-util.h"
-#include "util.h"
-#include "conf-parser.h"
-#include "strv.h"
 #include "cap-list.h"
-
+#include "conf-parser.h"
 #include "nspawn-settings.h"
+#include "process-util.h"
+#include "strv.h"
+#include "util.h"
 
 int settings_load(FILE *f, const char *path, Settings **ret) {
         _cleanup_(settings_freep) Settings *s = NULL;
index f4a918063d2e69199cda758c28af1b30a4dfa865..940e393318d118fc5e6d64a1d6b8e0003c7ad318 100644 (file)
@@ -41,6 +41,7 @@
 #include "parse-util.h"
 #include "path-util.h"
 #include "proc-cmdline.h"
+#include "process-util.h"
 #include "rlimit-util.h"
 #include "set.h"
 #include "signal-util.h"
index 163a83518ba0b1c4236aa0800047726f1daddc1d..3f8eaf7d9a208e2d5e59490ea705720fe0e04d07 100644 (file)
 #include "macro.h"
 #include "parse-util.h"
 #include "path-util.h"
+#include "process-util.h"
 #include "signal-util.h"
 #include "string-util.h"
 #include "strv.h"
+#include "syslog-util.h"
 #include "utf8.h"
 #include "util.h"
-#include "syslog-util.h"
 
 int config_item_table_lookup(
                 const void *table,