ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
Jan Synacek 5606d8
From 6ae61e265d8becff0960c0911e8bd37b0df42386 Mon Sep 17 00:00:00 2001
Jan Synacek 5606d8
From: Fedora systemd team <systemd-maint@redhat.com>
Jan Synacek 5606d8
Date: Thu, 18 Dec 2014 15:21:22 +0100
Jan Synacek 5606d8
Subject: [PATCH] nspawn: fix invocation of the raw clone() system call on s390
Jan Synacek 5606d8
 and cris
Jan Synacek 5606d8
Jan Synacek 5606d8
Since the order of the first and second arguments of the raw clone() system
Jan Synacek 5606d8
call is reversed on s390 and cris it needs to be invoked differently.
Jan Synacek 5606d8
Jan Synacek 5606d8
(cherry-picked from 60e1651a31c9c0ed1caef1a63f5e3a87156b0b1e)
Jan Synacek 5606d8
---
Jan Synacek 5606d8
 src/nspawn/nspawn.c  |  6 +++---
Jan Synacek 5606d8
 src/shared/missing.h | 10 ++++++++++
Jan Synacek 5606d8
 2 files changed, 13 insertions(+), 3 deletions(-)
Jan Synacek 5606d8
Jan Synacek 5606d8
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
Jan Synacek 5606d8
index 0466ddb..2f57e65 100644
Jan Synacek 5606d8
--- a/src/nspawn/nspawn.c
Jan Synacek 5606d8
+++ b/src/nspawn/nspawn.c
Jan Synacek 5606d8
@@ -2982,9 +2982,9 @@ int main(int argc, char *argv[]) {
Jan Synacek 5606d8
                         goto finish;
Jan Synacek 5606d8
                 }
Jan Synacek 5606d8
 
Jan Synacek 5606d8
-                pid = syscall(__NR_clone, SIGCHLD|CLONE_NEWNS|
Jan Synacek 5606d8
-                                          (arg_share_system ? 0 : CLONE_NEWIPC|CLONE_NEWPID|CLONE_NEWUTS)|
Jan Synacek 5606d8
-                                          (arg_private_network ? CLONE_NEWNET : 0), NULL);
Jan Synacek 5606d8
+                pid = raw_clone(SIGCHLD|CLONE_NEWNS|
Jan Synacek 5606d8
+                                (arg_share_system ? 0 : CLONE_NEWIPC|CLONE_NEWPID|CLONE_NEWUTS)|
Jan Synacek 5606d8
+                                (arg_private_network ? CLONE_NEWNET : 0), NULL);
Jan Synacek 5606d8
                 if (pid < 0) {
Jan Synacek 5606d8
                         if (errno == EINVAL)
Jan Synacek 5606d8
                                 log_error_errno(errno, "clone() failed, do you have namespace support enabled in your kernel? (You need UTS, IPC, PID and NET namespacing built in): %m");
Jan Synacek 5606d8
diff --git a/src/shared/missing.h b/src/shared/missing.h
Jan Synacek 5606d8
index 478988c..8ea3807 100644
Jan Synacek 5606d8
--- a/src/shared/missing.h
Jan Synacek 5606d8
+++ b/src/shared/missing.h
Jan Synacek 5606d8
@@ -631,3 +631,13 @@ static inline int setns(int fd, int nstype) {
Jan Synacek 5606d8
 #ifndef CAP_AUDIT_READ
Jan Synacek 5606d8
 #define CAP_AUDIT_READ 37
Jan Synacek 5606d8
 #endif
Jan Synacek 5606d8
+
Jan Synacek 5606d8
+static inline long raw_clone(unsigned long flags, void *child_stack) {
Jan Synacek 5606d8
+#if defined(__s390__) || defined(__CRIS__)
Jan Synacek 5606d8
+        /* On s390 and cris the order of the first and second arguments
Jan Synacek 5606d8
+         * of the raw clone() system call is reversed. */
Jan Synacek 5606d8
+        return syscall(__NR_clone, child_stack, flags);
Jan Synacek 5606d8
+#else
Jan Synacek 5606d8
+        return syscall(__NR_clone, flags, child_stack);
Jan Synacek 5606d8
+#endif
Jan Synacek 5606d8
+}
Jan Synacek 5606d8
-- 
Jan Synacek 5606d8
2.2.0
Jan Synacek 5606d8