]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/namespace.h
lxccontainer: properly cleanup on mount injection failure
[mirror_lxc.git] / src / lxc / namespace.h
CommitLineData
0ad19a3f 1/*
2 * lxc: linux Container library
3 *
5bb3ba8a 4 * (C) Copyright IBM Corp. 2007, 2009
0ad19a3f 5 *
6 * Authors:
9afe19d6 7 * Daniel Lezcano <daniel.lezcano at free.fr>
0ad19a3f 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
250b1eec 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0ad19a3f 22 */
f1a4a029
ÇO
23#ifndef __LXC_NAMESPACE_H
24#define __LXC_NAMESPACE_H
0ad19a3f 25
5bb3ba8a 26#include <sched.h>
bb196a1a
CB
27#include <unistd.h>
28#include <sys/syscall.h>
5bb3ba8a 29
8ab93249
CB
30#ifndef CLONE_PARENT_SETTID
31#define CLONE_PARENT_SETTID 0x00100000
32#endif
33
34#ifndef CLONE_CHILD_CLEARTID
35#define CLONE_CHILD_CLEARTID 0x00200000
36#endif
37
38#ifndef CLONE_CHILD_SETTID
39#define CLONE_CHILD_SETTID 0x01000000
40#endif
41
42#ifndef CLONE_VFORK
43#define CLONE_VFORK 0x00004000
44#endif
45
46#ifndef CLONE_THREAD
47#define CLONE_THREAD 0x00010000
48#endif
49
50#ifndef CLONE_SETTLS
51#define CLONE_SETTLS 0x00080000
52#endif
53
54#ifndef CLONE_VM
55#define CLONE_VM 0x00000100
56#endif
57
58#ifndef CLONE_FILES
59#define CLONE_FILES 0x00000400
60#endif
61
0ad19a3f 62#ifndef CLONE_FS
63# define CLONE_FS 0x00000200
64#endif
65#ifndef CLONE_NEWNS
66# define CLONE_NEWNS 0x00020000
67#endif
12983ba4
SH
68#ifndef CLONE_NEWCGROUP
69# define CLONE_NEWCGROUP 0x02000000
70#endif
0ad19a3f 71#ifndef CLONE_NEWUTS
72# define CLONE_NEWUTS 0x04000000
73#endif
74#ifndef CLONE_NEWIPC
75# define CLONE_NEWIPC 0x08000000
76#endif
77#ifndef CLONE_NEWUSER
78# define CLONE_NEWUSER 0x10000000
79#endif
80#ifndef CLONE_NEWPID
81# define CLONE_NEWPID 0x20000000
82#endif
83#ifndef CLONE_NEWNET
84# define CLONE_NEWNET 0x40000000
85#endif
675693a5 86
9662e444 87enum {
29ed9c13 88 LXC_NS_USER,
9662e444
CB
89 LXC_NS_MNT,
90 LXC_NS_PID,
91 LXC_NS_UTS,
92 LXC_NS_IPC,
9662e444
CB
93 LXC_NS_NET,
94 LXC_NS_CGROUP,
95 LXC_NS_MAX
96};
97
98extern const struct ns_info {
99 const char *proc_name;
100 int clone_flag;
101 const char *flag_name;
18b3b9c1 102 const char *env_name;
9662e444
CB
103} ns_info[LXC_NS_MAX];
104
675693a5
DS
105#if defined(__ia64__)
106int __clone2(int (*__fn) (void *__arg), void *__child_stack_base,
107 size_t __child_stack_size, int __flags, void *__arg, ...);
1f1665e6 108#else
fbef4590
SH
109int clone(int (*fn)(void *), void *child_stack,
110 int flags, void *arg, ...
111 /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ );
1f1665e6 112#endif
fbef4590 113
718dbb8c
CB
114/**
115 * lxc_clone() - create a new process
116 *
117 * - allocate stack:
118 * This function allocates a new stack the size of page and passes it to the
119 * kernel.
120 *
121 * - support all CLONE_*flags:
122 * This function supports all CLONE_* flags. If in doubt or not sufficiently
123 * familiar with process creation in the kernel and interactions with libcs
124 * this function should be used.
125 *
126 * - pthread_atfork() handlers depending on libc:
127 * Whether this function runs pthread_atfork() handlers depends on the
128 * corresponding libc wrapper. glibc currently does not run pthread_atfork()
129 * handlers but does not guarantee that they are not. Other libcs might or
130 * might not run pthread_atfork() handlers. If you require guarantees please
38e5c2db 131 * refer to the lxc_raw_clone*() functions in raw_syscalls.{c,h}.
718dbb8c
CB
132 *
133 * - should call lxc_raw_getpid():
134 * The child should use lxc_raw_getpid() to retrieve its pid.
135 */
33258b95 136extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags, int *pidfd);
718dbb8c 137
28d9e29e
CB
138extern int lxc_namespace_2_cloneflag(const char *namespace);
139extern int lxc_namespace_2_ns_idx(const char *namespace);
42067d18 140extern int lxc_namespace_2_std_identifiers(char *namespaces);
39a5d5fe
CS
141extern int lxc_fill_namespace_flags(char *flaglist, int *flags);
142
0ad19a3f 143#endif