]>
git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/namespace.c
2 * lxc: linux Container library
4 * (C) Copyright IBM Corp. 2007, 2009
7 * Daniel Lezcano <daniel.lezcano at free.fr>
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.
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.
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
28 #include <sys/param.h>
29 #include <sys/types.h>
33 #include "namespace.h"
36 lxc_log_define(lxc_namespace
, lxc
);
43 static int do_clone(void *arg
)
45 struct clone_arg
*clone_arg
= arg
;
46 return clone_arg
->fn(clone_arg
->arg
);
49 pid_t
lxc_clone(int (*fn
)(void *), void *arg
, int flags
)
51 struct clone_arg clone_arg
= {
56 size_t stack_size
= sysconf(_SC_PAGESIZE
);
57 void *stack
= alloca(stack_size
);
61 ret
= __clone2(do_clone
, stack
,
62 stack_size
, flags
| SIGCHLD
, &clone_arg
);
64 ret
= clone(do_clone
, stack
+ stack_size
, flags
| SIGCHLD
, &clone_arg
);
67 ERROR("failed to clone(0x%x): %s", flags
, strerror(errno
));
72 static const char * const namespaces_list
[] = {
73 "MOUNT", "PID", "UTSNAME", "IPC",
76 static const int cloneflags_list
[] = {
77 CLONE_NEWNS
, CLONE_NEWPID
, CLONE_NEWUTS
, CLONE_NEWIPC
,
78 CLONE_NEWUSER
, CLONE_NEWNET
81 int lxc_namespace_2_cloneflag(char *namespace)
84 len
= sizeof(namespaces_list
)/sizeof(namespaces_list
[0]);
85 for (i
= 0; i
< len
; i
++)
86 if (!strcmp(namespaces_list
[i
], namespace))
87 return cloneflags_list
[i
];
89 ERROR("invalid namespace name %s", namespace);
93 int lxc_fill_namespace_flags(char *flaglist
, int *flags
)
95 char *token
, *saveptr
= NULL
;
99 ERROR("need at least one namespace to unshare");
103 token
= strtok_r(flaglist
, "|", &saveptr
);
106 aflag
= lxc_namespace_2_cloneflag(token
);
112 token
= strtok_r(NULL
, "|", &saveptr
);