mirror of
https://github.com/systemd/systemd.git
synced 2024-10-28 11:55:44 +03:00
process-util: move a couple of process-related calls over
This commit is contained in:
parent
5fd9b2c546
commit
7b3e062cb6
@ -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);
|
||||
|
@ -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))
|
||||
|
117
src/basic/util.c
117
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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
|
@ -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"
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user