summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/basic/process-util.c121
-rw-r--r--src/basic/process-util.h24
-rw-r--r--src/basic/util.c117
-rw-r--r--src/basic/util.h23
-rw-r--r--src/core/busname.c1
-rw-r--r--src/core/dbus-execute.c1
-rw-r--r--src/core/load-fragment.c1
-rw-r--r--src/core/mount.c1
-rw-r--r--src/core/socket.c1
-rw-r--r--src/core/swap.c1
-rw-r--r--src/nspawn/nspawn-settings.c8
-rw-r--r--src/shared/bus-util.c1
-rw-r--r--src/shared/conf-parser.c3
13 files changed, 158 insertions, 145 deletions
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index a737686ab0..7631928d5f 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -20,10 +20,12 @@
#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>
@@ -34,9 +36,11 @@
#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);
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index 85fc8d8eb7..72633ebf70 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -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))
diff --git a/src/basic/util.c b/src/basic/util.c
index 2451da3658..7d9dad472b 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -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;
-}
diff --git a/src/basic/util.h b/src/basic/util.h
index fc329a869b..57dc5e8d46 100644
--- a/src/basic/util.h
+++ b/src/basic/util.h
@@ -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);
diff --git a/src/core/busname.c b/src/core/busname.c
index 9fed54ffc8..3592f72fe5 100644
--- a/src/core/busname.c
+++ b/src/core/busname.c
@@ -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"
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index 882a76e988..04a5a22b72 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -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"
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index c1d09e8e5a..ecfdb80deb 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -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
diff --git a/src/core/mount.c b/src/core/mount.c
index 77b5ec27eb..2761f632bd 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -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"
diff --git a/src/core/socket.c b/src/core/socket.c
index d8b8cf576a..f62466c6a0 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -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"
diff --git a/src/core/swap.c b/src/core/swap.c
index 5be3c709bf..6eff6ffb4c 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -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"
diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c
index ee9e70acec..6885d0641e 100644
--- a/src/nspawn/nspawn-settings.c
+++ b/src/nspawn/nspawn-settings.c
@@ -20,12 +20,12 @@
***/
#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;
diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c
index f4a918063d..940e393318 100644
--- a/src/shared/bus-util.c
+++ b/src/shared/bus-util.c
@@ -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"
diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c
index 163a83518b..3f8eaf7d9a 100644
--- a/src/shared/conf-parser.c
+++ b/src/shared/conf-parser.c
@@ -35,12 +35,13 @@
#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,