process-util: move a couple of process-related calls over

This commit is contained in:
Lennart Poettering
2015-10-27 14:24:58 +01:00
parent 5fd9b2c546
commit 7b3e062cb6
13 changed files with 158 additions and 145 deletions
+121
View File
@@ -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);