chiark / gitweb /
nspawn: add new --personality= switch to make it easier to run 32bit containers on...
[elogind.git] / src / shared / util.c
index 4f3145b2bc493ec1efff7d00afe29e9355e83cec..99658f097571f847db178d1402623bd27fd3031e 100644 (file)
@@ -58,6 +58,7 @@
 #include <limits.h>
 #include <langinfo.h>
 #include <locale.h>
+#include <sys/personality.h>
 #include <libgen.h>
 #undef basename
 
@@ -6045,7 +6046,9 @@ int namespace_enter(int pidns_fd, int mntns_fd, int root_fd) {
         return 0;
 }
 
-bool pid_valid(pid_t pid) {
+bool pid_is_unwaited(pid_t pid) {
+        /* Checks whether a PID is still valid at all, including a zombie */
+
         if (pid <= 0)
                 return false;
 
@@ -6055,6 +6058,21 @@ bool pid_valid(pid_t pid) {
         return errno != ESRCH;
 }
 
+bool pid_is_alive(pid_t pid) {
+        int r;
+
+        /* Checks whether a PID is still valid and not a zombie */
+
+        if (pid <= 0)
+                return false;
+
+        r = get_process_state(pid);
+        if (r == -ENOENT || r == 'Z')
+                return false;
+
+        return true;
+}
+
 int getpeercred(int fd, struct ucred *ucred) {
         socklen_t n = sizeof(struct ucred);
         struct ucred u;
@@ -6175,3 +6193,32 @@ int fd_warn_permissions(const char *path, int fd) {
 
         return 0;
 }
+
+unsigned long parse_personality(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;
+#endif
+
+        /* personality(7) documents that 0xffffffffUL is used for
+         * querying the current personality, hence let's use that here
+         * as error indicator. */
+        return 0xffffffffUL;
+}