]>
Commit | Line | Data |
---|---|---|
1bc5cc8c DL |
1 | /* |
2 | * lxc: linux Container library | |
3 | * | |
4 | * (C) Copyright IBM Corp. 2007, 2008 | |
5 | * | |
6 | * Authors: | |
9afe19d6 | 7 | * Daniel Lezcano <daniel.lezcano at free.fr> |
35a02107 CB |
8 | * Serge Hallyn <serge@hallyn.com> |
9 | * Christian Brauner <christian.brauner@ubuntu.com> | |
1bc5cc8c DL |
10 | * |
11 | * This library is free software; you can redistribute it and/or | |
12 | * modify it under the terms of the GNU Lesser General Public | |
13 | * License as published by the Free Software Foundation; either | |
14 | * version 2.1 of the License, or (at your option) any later version. | |
15 | * | |
16 | * This library is distributed in the hope that it will be useful, | |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
19 | * Lesser General Public License for more details. | |
20 | * | |
21 | * You should have received a copy of the GNU Lesser General Public | |
22 | * License along with this library; if not, write to the Free Software | |
250b1eec | 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
1bc5cc8c | 24 | */ |
f1a4a029 ÇO |
25 | #ifndef __LXC_START_H |
26 | #define __LXC_START_H | |
00b3c2e2 | 27 | |
9dc56d32 | 28 | #include <signal.h> |
35a02107 | 29 | #include <stdbool.h> |
872e1899 | 30 | #include <sys/param.h> |
5e5576a4 CB |
31 | #include <sys/socket.h> |
32 | #include <sys/un.h> | |
f2363e38 | 33 | |
aa460476 | 34 | #include "conf.h" |
9f30a190 | 35 | #include "namespace.h" |
35a02107 | 36 | #include "state.h" |
1bc5cc8c | 37 | |
872e1899 | 38 | struct lxc_handler { |
becad0ec CB |
39 | /* Record the clone for namespaces flags that the container requested. |
40 | * | |
41 | * @ns_clone_flags | |
42 | * - All clone flags that were requested. | |
43 | * | |
44 | * @ns_on_clone_flags | |
45 | * - The clone flags for namespaces to actually use when calling | |
46 | * lxc_clone(): After the container has started ns_on_clone_flags will | |
47 | * list the clone flags that were unshare()ed rather then clone()ed | |
48 | * because of ordering requirements (e.g. e.g. CLONE_NEWNET and | |
49 | * CLONE_NEWUSER) or implementation details. | |
50 | * | |
51 | * @ns_keep_flags; | |
52 | * - The clone flags for the namespaces that the container will inherit | |
53 | * from the parent. They are not recorded in the handler itself but | |
54 | * are present in the container's config. | |
55 | * | |
56 | * @ns_share_flags; | |
57 | * - The clone flags for the namespaces that the container will share | |
58 | * with another process. They are not recorded in the handler itself | |
59 | * but are present in the container's config. | |
8deca6c9 | 60 | */ |
becad0ec CB |
61 | struct /* lxc_ns */ { |
62 | int ns_clone_flags; | |
63 | int ns_on_clone_flags; | |
64 | }; | |
8deca6c9 | 65 | |
35a02107 | 66 | /* File descriptor to pin the rootfs for privileged containers. */ |
2b0e17e4 | 67 | int pinfd; |
35a02107 CB |
68 | |
69 | /* Signal file descriptor. */ | |
70 | int sigfd; | |
71 | ||
72 | /* List of file descriptors referring to the namespaces of the | |
73 | * container. Note that these are not necessarily identical to | |
74 | * the "clone_flags" handler field in case namespace inheritance is | |
75 | * requested. | |
76 | */ | |
77 | int nsfd[LXC_NS_MAX]; | |
1a0e70ac | 78 | |
c6012571 CB |
79 | /* Abstract unix domain SOCK_DGRAM socketpair to pass arbitrary data |
80 | * between child and parent. | |
81 | */ | |
82 | int data_sock[2]; | |
1a0e70ac | 83 | |
1a0e70ac | 84 | /* The socketpair() fds used to wait on successful daemonized startup. */ |
5e5576a4 | 85 | int state_socket_pair[2]; |
35a02107 CB |
86 | |
87 | /* Socketpair to synchronize processes during container creation. */ | |
88 | int sync_sock[2]; | |
89 | ||
f0ecc19d CB |
90 | /* Pointer to the name of the container. Do not free! */ |
91 | const char *name; | |
35a02107 | 92 | |
f0ecc19d | 93 | /* Pointer to the path the container. Do not free! */ |
35a02107 CB |
94 | const char *lxcpath; |
95 | ||
96 | /* Whether the container's startup process euid is 0. */ | |
97 | bool am_root; | |
98 | ||
99 | /* Indicates whether should we close std{in,out,err} on start. */ | |
bb955810 | 100 | bool daemonize; |
35a02107 CB |
101 | |
102 | /* The child's pid. */ | |
103 | pid_t pid; | |
104 | ||
33942046 CB |
105 | /* The child's pidfd. */ |
106 | int pidfd; | |
107 | ||
d9bb2fba CB |
108 | /* |
109 | * File descriptor for the /proc/<pid> directory of the container's | |
110 | * init process. | |
111 | */ | |
112 | int proc_pidfd; | |
113 | ||
434c8e15 CB |
114 | /* The monitor's pid. */ |
115 | pid_t monitor_pid; | |
116 | ||
3c319edb CB |
117 | /* Whether the child has already exited. */ |
118 | bool init_died; | |
119 | ||
35a02107 CB |
120 | /* The signal mask prior to setting up the signal file descriptor. */ |
121 | sigset_t oldmask; | |
122 | ||
123 | /* The container's in-memory configuration. */ | |
124 | struct lxc_conf *conf; | |
125 | ||
35a02107 CB |
126 | /* A set of operations to be performed at various stages of the |
127 | * container's life. | |
128 | */ | |
129 | struct lxc_operations *ops; | |
130 | ||
131 | /* This holds the cgroup information. Note that the data here is | |
132 | * specific to the cgroup driver used. | |
133 | */ | |
134 | void *cgroup_data; | |
135 | ||
136 | /* Data to be passed to handler ops. */ | |
137 | void *data; | |
138 | ||
139 | /* Current state of the container. */ | |
140 | lxc_state_t state; | |
cd5177e9 TA |
141 | |
142 | /* The exit status of the container; not defined unless ->init_died == | |
143 | * true. | |
144 | */ | |
145 | int exit_status; | |
2202afc9 CB |
146 | |
147 | struct cgroup_ops *cgroup_ops; | |
fc25b815 MN |
148 | }; |
149 | ||
794248d0 CB |
150 | struct execute_args { |
151 | char *init_path; | |
4b5b3a2a | 152 | int init_fd; |
794248d0 CB |
153 | char *const *argv; |
154 | int quiet; | |
155 | }; | |
156 | ||
dbc9832d CB |
157 | struct lxc_operations { |
158 | int (*start)(struct lxc_handler *, void *); | |
159 | int (*post_start)(struct lxc_handler *, void *); | |
160 | }; | |
161 | ||
735f2c6e | 162 | extern int lxc_poll(const char *name, struct lxc_handler *handler); |
974a8aba CB |
163 | extern int lxc_set_state(const char *name, struct lxc_handler *handler, |
164 | lxc_state_t state); | |
165 | extern int lxc_serve_state_clients(const char *name, | |
166 | struct lxc_handler *handler, | |
167 | lxc_state_t state); | |
735f2c6e | 168 | extern void lxc_abort(const char *name, struct lxc_handler *handler); |
aa460476 CB |
169 | extern struct lxc_handler *lxc_init_handler(const char *name, |
170 | struct lxc_conf *conf, | |
5e5576a4 CB |
171 | const char *lxcpath, |
172 | bool daemonize); | |
41784e4e | 173 | extern void lxc_zero_handler(struct lxc_handler *handler); |
f2e07cb6 | 174 | extern void lxc_free_handler(struct lxc_handler *handler); |
aa460476 | 175 | extern int lxc_init(const char *name, struct lxc_handler *handler); |
3b72c4a0 | 176 | extern void lxc_fini(const char *name, struct lxc_handler *handler); |
1bc5cc8c | 177 | |
47a46cf1 CB |
178 | /* lxc_check_inherited: Check for any open file descriptors and close them if |
179 | * requested. | |
180 | * @param[in] conf The container's configuration. | |
181 | * @param[in] closeall Whether we should close all open file descriptors. | |
182 | * @param[in] fds_to_ignore Array of file descriptors to ignore. | |
183 | * @param[in] len_fds Length of fds_to_ignore array. | |
184 | */ | |
185 | extern int lxc_check_inherited(struct lxc_conf *conf, bool closeall, | |
186 | int *fds_to_ignore, size_t len_fds); | |
35a02107 | 187 | extern int __lxc_start(const char *, struct lxc_handler *, |
a3b4f3d6 TA |
188 | struct lxc_operations *, void *, const char *, bool, |
189 | int *); | |
1bc5cc8c | 190 | |
5af9369b | 191 | extern int resolve_clone_flags(struct lxc_handler *handler); |
1bc5cc8c | 192 | |
a529bc25 | 193 | #endif |