X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fbasic%2Fprocess-util.c;h=d146638b8e9188159c5e02a74f8d09e6313922f1;hb=7b6ffe6395e164016636530c2aedaf3f4f9a7830;hp=0c6a494e07931adcd70c7105c22f4d97f6cbd1a2;hpb=68def6bc80ba50ed3b3658d00799a3ec295c4d7a;p=elogind.git
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 0c6a494e0..d146638b8 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -17,29 +17,39 @@
along with systemd; If not, see .
***/
-#include
#include
#include
+#include
+#include
#include
#include
#include
#include
+#include
#include
#include
#include
#include
#include
+#include
#include
+#ifdef HAVE_VALGRIND_VALGRIND_H
+#include
+#endif
#include "alloc-util.h"
+#include "architecture.h"
#include "escape.h"
#include "fd-util.h"
#include "fileio.h"
#include "fs-util.h"
//#include "ioprio.h"
#include "log.h"
+#include "macro.h"
+#include "missing.h"
#include "process-util.h"
#include "signal-util.h"
+//#include "stat-util.h"
#include "string-table.h"
#include "string-util.h"
#include "user-util.h"
@@ -637,6 +647,19 @@ bool pid_is_alive(pid_t pid) {
return true;
}
+#if 0 /// UNNEEDED by elogind
+int pid_from_same_root_fs(pid_t pid) {
+ const char *root;
+
+ if (pid < 0)
+ return 0;
+
+ root = procfs_file_alloca(pid, "root");
+
+ return files_same(root, "/proc/1/root");
+}
+#endif // 0
+
bool is_main_thread(void) {
static thread_local int cached = 0;
@@ -663,75 +686,72 @@ bool oom_score_adjust_is_valid(int oa) {
}
unsigned long personality_from_string(const char *p) {
+ int architecture;
- /* 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 (!p)
+ return PERSONALITY_INVALID;
- if (streq(p, "x86-64"))
- return PER_LINUX;
+ /* Parse a personality specifier. We use 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. */
-#elif defined(__i386__)
+ architecture = architecture_from_string(p);
+ if (architecture < 0)
+ return PERSONALITY_INVALID;
- if (streq(p, "x86"))
+ if (architecture == native_architecture())
return PER_LINUX;
-
-#elif defined(__s390x__)
-
- if (streq(p, "s390"))
+#ifdef SECONDARY_ARCHITECTURE
+ if (architecture == SECONDARY_ARCHITECTURE)
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";
+ int architecture = _ARCHITECTURE_INVALID;
if (p == PER_LINUX)
- return "x86-64";
-
-#elif defined(__i386__)
-
- if (p == PER_LINUX)
- return "x86";
+ architecture = native_architecture();
+#ifdef SECONDARY_ARCHITECTURE
+ else if (p == PER_LINUX32)
+ architecture = SECONDARY_ARCHITECTURE;
+#endif
-#elif defined(__s390x__)
+ if (architecture < 0)
+ return NULL;
- if (p == PER_LINUX)
- return "s390x";
-
- if (p == PER_LINUX32)
- return "s390";
+ return architecture_to_string(architecture);
+}
-#elif defined(__s390__)
+void valgrind_summary_hack(void) {
+#ifdef HAVE_VALGRIND_VALGRIND_H
+ if (getpid() == 1 && RUNNING_ON_VALGRIND) {
+ pid_t pid;
+ pid = raw_clone(SIGCHLD, NULL);
+ if (pid < 0)
+ log_emergency_errno(errno, "Failed to fork off valgrind helper: %m");
+ else if (pid == 0)
+ exit(EXIT_SUCCESS);
+ else {
+ log_info("Spawned valgrind helper as PID "PID_FMT".", pid);
+ (void) wait_for_terminate(pid, NULL);
+ }
+ }
+#endif
+}
- if (p == PER_LINUX)
- return "s390";
+int pid_compare_func(const void *a, const void *b) {
+ const pid_t *p = a, *q = b;
-#endif
+ /* Suitable for usage in qsort() */
- return NULL;
+ if (*p < *q)
+ return -1;
+ if (*p > *q)
+ return 1;
+ return 0;
}
static const char *const ioprio_class_table[] = {