aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@free.fr>2009-07-07 22:51:18 +0200
committerDaniel Lezcano <dlezcano@fr.ibm.com>2009-07-07 22:51:18 +0200
commit5bb3ba8acd29d11c92845b06a1f0852b642f02c7 (patch)
treec759fa428505f59bfba36de7bc2fe56d0e9b5ca4 /src/lxc/namespace.c
parentFix missing capability fowner to manipulate /dev/pts/ptmx (diff)
downloadlxc-5bb3ba8acd29d11c92845b06a1f0852b642f02c7.tar.gz
lxc-5bb3ba8acd29d11c92845b06a1f0852b642f02c7.tar.bz2
lxc-5bb3ba8acd29d11c92845b06a1f0852b642f02c7.zip
use glibc clone instead of clone syscall
This patch replaces the clone syscall by the glibc clone making the code not tied with the syscalls number declaration. The unshare syscall has been removed as it is not interesting. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
Diffstat (limited to 'src/lxc/namespace.c')
-rw-r--r--src/lxc/namespace.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/lxc/namespace.c b/src/lxc/namespace.c
new file mode 100644
index 0000000..72b0fc9
--- /dev/null
+++ b/src/lxc/namespace.c
@@ -0,0 +1,61 @@
+/*
+ * lxc: linux Container library
+ *
+ * (C) Copyright IBM Corp. 2007, 2009
+ *
+ * Authors:
+ * Daniel Lezcano <dlezcano at fr.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include <unistd.h>
+#include <alloca.h>
+#include <errno.h>
+#include <signal.h>
+#include <namespace.h>
+
+#include <lxc/lxc.h>
+
+lxc_log_define(lxc_namespace, lxc);
+
+struct clone_arg {
+ int (*fn)(void *);
+ void *arg;
+};
+
+static int do_clone(void *arg)
+{
+ struct clone_arg *clone_arg = arg;
+ return clone_arg->fn(clone_arg->arg);
+}
+
+pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
+{
+ struct clone_arg clone_arg = {
+ .fn = fn,
+ .arg = arg,
+ };
+
+ long stack_size = sysconf(_SC_PAGESIZE);
+ void *stack = alloca(stack_size) + stack_size;
+ pid_t ret;
+
+ ret = clone(do_clone, stack, flags | SIGCHLD, &clone_arg);
+ if (ret < 0)
+ ERROR("failed to clone(0x%x): %s", flags, strerror(errno));
+
+ return ret;
+}