]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/namespace.c
open the console later
[mirror_lxc.git] / src / lxc / namespace.c
CommitLineData
5bb3ba8a
DL
1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2009
5 *
6 * Authors:
7 * Daniel Lezcano <dlezcano at fr.ibm.com>
8 *
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
13 *
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
18 *
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24#include <unistd.h>
25#include <alloca.h>
26#include <errno.h>
27#include <signal.h>
28#include <namespace.h>
29
00b3c2e2 30#include <lxc/log.h>
5bb3ba8a
DL
31
32lxc_log_define(lxc_namespace, lxc);
33
34struct clone_arg {
35 int (*fn)(void *);
36 void *arg;
37};
38
39static int do_clone(void *arg)
40{
41 struct clone_arg *clone_arg = arg;
42 return clone_arg->fn(clone_arg->arg);
43}
44
45pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
46{
47 struct clone_arg clone_arg = {
48 .fn = fn,
49 .arg = arg,
50 };
51
52 long stack_size = sysconf(_SC_PAGESIZE);
d983b93c 53 void *stack = alloca(stack_size) + stack_size;
5bb3ba8a
DL
54 pid_t ret;
55
246091b9
DL
56#ifdef __ia64__
57 ret = __clone2(do_clone, stack,
58 stack_size, flags | SIGCHLD, &clone_arg);
59#else
5bb3ba8a 60 ret = clone(do_clone, stack, flags | SIGCHLD, &clone_arg);
246091b9 61#endif
5bb3ba8a
DL
62 if (ret < 0)
63 ERROR("failed to clone(0x%x): %s", flags, strerror(errno));
64
65 return ret;
66}