]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/basic/process-util.c
util-lib: support various ppc archs in personality logic
[thirdparty/systemd.git] / src / basic / process-util.c
index 4341d0093f93d7e267892dc0a1d3162775ac056a..f45e4ca338d2070f470b1bff7059febc22e46ac3 100644 (file)
@@ -38,6 +38,7 @@
 #endif
 
 #include "alloc-util.h"
+#include "architecture.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -48,6 +49,7 @@
 #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"
@@ -204,7 +206,7 @@ void rename_process(const char name[8]) {
          * "systemd"). If you pass a longer string it will be
          * truncated */
 
-        prctl(PR_SET_NAME, name);
+        (void) prctl(PR_SET_NAME, name);
 
         if (program_invocation_name)
                 strncpy(program_invocation_name, name, strlen(program_invocation_name));
@@ -637,6 +639,17 @@ bool pid_is_alive(pid_t pid) {
         return true;
 }
 
+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");
+}
+
 bool is_main_thread(void) {
         static thread_local int cached = 0;
 
@@ -662,75 +675,138 @@ bool oom_score_adjust_is_valid(int oa) {
 }
 
 unsigned long personality_from_string(const char *p) {
+        int architecture;
+
+        /* 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. */
 
-        /* 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. */
+        architecture = architecture_from_string(p);
+        if (architecture < 0)
+                return PERSONALITY_INVALID;
 
 #if defined(__x86_64__)
 
-        if (streq(p, "x86"))
+        if (architecture == ARCHITECTURE_X86)
                 return PER_LINUX32;
 
-        if (streq(p, "x86-64"))
+        if (architecture == ARCHITECTURE_X86_64)
                 return PER_LINUX;
 
 #elif defined(__i386__)
 
-        if (streq(p, "x86"))
+        if (architecture == ARCHITECTURE_X86)
                 return PER_LINUX;
 
 #elif defined(__s390x__)
 
-        if (streq(p, "s390"))
+        if (architecture == ARCHITECTURE_S390)
                 return PER_LINUX32;
 
-        if (streq(p, "s390x"))
+        if (architecture == ARCHITECTURE_S390X)
                 return PER_LINUX;
 
 #elif defined(__s390__)
 
-        if (streq(p, "s390"))
+        if (architecture == ARCHITECTURE_S390)
+                return PER_LINUX;
+
+#elif defined(__powerpc64__)
+#  if __BYTE_ORDER == __BIG_ENDIAN
+
+        if (architecture == ARCHITECTURE_PPC_LE)
+                return PER_LINUX32;
+
+        if (architecture == ARCHITECTURE_PPC64_LE)
+                return PER_LINUX;
+
+#  else
+
+        if (architecture == ARCHITECTURE_PPC)
+                return PER_LINUX32;
+
+        if (architecture == ARCHITECTURE_PPC64)
+                return PER_LINUX;
+
+#  endif
+#elif defined(__powerpc__)
+#  if __BYTE_ORDER == __BIG_ENDIAN
+
+        if (architecture == ARCHITECTURE_PPC)
                 return PER_LINUX;
+
+#  else
+
+        if (architecture == ARCHITECTURE_PPC_LE)
+                return PER_LINUX;
+
+#  endif
 #endif
 
         return PERSONALITY_INVALID;
 }
 
 const char* personality_to_string(unsigned long p) {
+        int architecture = _ARCHITECTURE_INVALID;
 
 #if defined(__x86_64__)
 
-        if (p == PER_LINUX32)
-                return "x86";
-
         if (p == PER_LINUX)
-                return "x86-64";
+                architecture = ARCHITECTURE_X86_64;
+        else if (p == PER_LINUX32)
+                architecture = ARCHITECTURE_X86;
 
 #elif defined(__i386__)
 
         if (p == PER_LINUX)
-                return "x86";
+                architecture = ARCHITECTURE_X86;
 
 #elif defined(__s390x__)
 
         if (p == PER_LINUX)
-                return "s390x";
-
-        if (p == PER_LINUX32)
-                return "s390";
+                architecture = ARCHITECTURE_S390X;
+        else if (p == PER_LINUX32)
+                architecture = ARCHITECTURE_S390;
 
 #elif defined(__s390__)
 
         if (p == PER_LINUX)
-                return "s390";
+                architecture = ARCHITECTURE_S390;
+
+#elif defined(__powerpc64__)
+#  if __BYTE_ORDER == __BIG_ENDIAN
+
+        if (p == PER_LINUX)
+                architecture = ARCHITECTURE_PPC64;
+        else if (p == PER_LINUX32)
+                 architecture = ARCHITECTURE_PPC;
 
+#  else
+
+        if (p == PER_LINUX)
+                architecture = ARCHITECTURE_PPC64_LE;
+        else if (p == PER_LINUX32)
+                architecture = ARCHITECTURE_PPC_LE;
+
+#  endif
+#elif defined(__powerpc__)
+#  if __BYTE_ORDER == __BIG_ENDIAN
+
+        if (p == PER_LINUX)
+                architecture = ARCHITECTURE_PPC;
+
+#  else
+
+        if (p == PER_LINUX)
+                architecture = ARCHITECTURE_PPC_LE;
+
+#  endif
 #endif
 
-        return NULL;
+        if (architecture < 0)
+                return NULL;
+
+        return architecture_to_string(architecture);
 }
 
 void valgrind_summary_hack(void) {