aboutgitcodebugslistschat
diff options
context:
space:
mode:
-rw-r--r--pasta.c10
-rw-r--r--util.c21
-rw-r--r--util.h8
3 files changed, 31 insertions, 8 deletions
diff --git a/pasta.c b/pasta.c
index db86317..528f02a 100644
--- a/pasta.c
+++ b/pasta.c
@@ -226,11 +226,11 @@ void pasta_start_ns(struct ctx *c, uid_t uid, gid_t gid,
arg.argv = sh_argv;
}
- pasta_child_pid = clone(pasta_spawn_cmd,
- ns_fn_stack + sizeof(ns_fn_stack) / 2,
- CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |
- CLONE_NEWUTS,
- (void *)&arg);
+ pasta_child_pid = do_clone(pasta_spawn_cmd, ns_fn_stack,
+ sizeof(ns_fn_stack),
+ CLONE_NEWIPC | CLONE_NEWPID | CLONE_NEWNET |
+ CLONE_NEWUTS,
+ (void *)&arg);
if (pasta_child_pid == -1) {
perror("clone");
diff --git a/util.c b/util.c
index be102e3..2125a67 100644
--- a/util.c
+++ b/util.c
@@ -482,3 +482,24 @@ int write_file(const char *path, const char *buf)
close(fd);
return len == 0 ? 0 : -1;
}
+
+/**
+ * do_clone() - Wrapper of __clone2() for ia64, clone() for other architectures
+ * @fn: Entry point for child
+ * @stack_area: Stack area for child: we'll point callees to the middle of it
+ * @stack_size: Total size of stack area, passed to callee divided by two
+ * @flags: clone() system call flags
+ * @arg: Argument to @fn
+ *
+ * Return: thread ID of child, -1 on failure
+ */
+int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags,
+ void *arg)
+{
+#ifdef __ia64__
+ return __clone2(fn, stack_area + stack_size / 2, stack_size / 2,
+ flags, arg);
+#else
+ return clone(fn, stack_area + stack_size / 2, flags, arg);
+#endif
+}
diff --git a/util.h b/util.h
index 2d4e1ff..02b55a9 100644
--- a/util.h
+++ b/util.h
@@ -81,13 +81,15 @@
(((struct in_addr *)(a))->s_addr == ((struct in_addr *)b)->s_addr)
#define NS_FN_STACK_SIZE (RLIMIT_STACK_VAL * 1024 / 8)
+int do_clone(int (*fn)(void *), char *stack_area, size_t stack_size, int flags,
+ void *arg);
#define NS_CALL(fn, arg) \
do { \
char ns_fn_stack[NS_FN_STACK_SIZE]; \
\
- clone((fn), ns_fn_stack + sizeof(ns_fn_stack) / 2, \
- CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD, \
- (void *)(arg)); \
+ do_clone((fn), ns_fn_stack, sizeof(ns_fn_stack), \
+ CLONE_VM | CLONE_VFORK | CLONE_FILES | SIGCHLD,\
+ (void *)(arg)); \
} while (0)
#if __BYTE_ORDER == __BIG_ENDIAN