]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/start.h
Merge pull request #2175 from brauner/2018-02-17/coding_style_fixes
[mirror_lxc.git] / src / lxc / start.h
1 /*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
7 * Daniel Lezcano <daniel.lezcano at free.fr>
8 * Serge Hallyn <serge@hallyn.com>
9 * Christian Brauner <christian.brauner@ubuntu.com>
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
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25 #ifndef __LXC_START_H
26 #define __LXC_START_H
27
28 #include <signal.h>
29 #include <stdbool.h>
30 #include <sys/param.h>
31 #include <sys/socket.h>
32 #include <sys/un.h>
33
34 #include "conf.h"
35 #include "config.h"
36 #include "namespace.h"
37 #include "state.h"
38
39 struct lxc_handler {
40 /* Record the clone for namespaces flags that the container requested.
41 *
42 * @ns_clone_flags
43 * - All clone flags that were requested.
44 *
45 * @ns_on_clone_flags
46 * - The clone flags for namespaces to actually use when calling
47 * lxc_clone(): After the container has started ns_on_clone_flags will
48 * list the clone flags that were unshare()ed rather then clone()ed
49 * because of ordering requirements (e.g. e.g. CLONE_NEWNET and
50 * CLONE_NEWUSER) or implementation details.
51 *
52 * @ns_keep_flags;
53 * - The clone flags for the namespaces that the container will inherit
54 * from the parent. They are not recorded in the handler itself but
55 * are present in the container's config.
56 *
57 * @ns_share_flags;
58 * - The clone flags for the namespaces that the container will share
59 * with another process. They are not recorded in the handler itself
60 * but are present in the container's config.
61 */
62 struct /* lxc_ns */ {
63 int ns_clone_flags;
64 int ns_on_clone_flags;
65 };
66
67 /* File descriptor to pin the rootfs for privileged containers. */
68 int pinfd;
69
70 /* Signal file descriptor. */
71 int sigfd;
72
73 /* List of file descriptors referring to the namespaces of the
74 * container. Note that these are not necessarily identical to
75 * the "clone_flags" handler field in case namespace inheritance is
76 * requested.
77 */
78 int nsfd[LXC_NS_MAX];
79
80 /* Abstract unix domain SOCK_DGRAM socketpair to pass arbitrary data
81 * between child and parent.
82 */
83 int data_sock[2];
84
85 /* The socketpair() fds used to wait on successful daemonized startup. */
86 int state_socket_pair[2];
87
88 /* Socketpair to synchronize processes during container creation. */
89 int sync_sock[2];
90
91 /* Pointer to the name of the container. Do not free! */
92 const char *name;
93
94 /* Pointer to the path the container. Do not free! */
95 const char *lxcpath;
96
97 /* Whether the container's startup process euid is 0. */
98 bool am_root;
99
100 /* Indicates whether should we close std{in,out,err} on start. */
101 bool backgrounded;
102
103 /* The child's pid. */
104 pid_t pid;
105
106 /* Whether the child has already exited. */
107 bool init_died;
108
109 /* The signal mask prior to setting up the signal file descriptor. */
110 sigset_t oldmask;
111
112 /* The container's in-memory configuration. */
113 struct lxc_conf *conf;
114
115 /* A set of operations to be performed at various stages of the
116 * container's life.
117 */
118 struct lxc_operations *ops;
119
120 /* This holds the cgroup information. Note that the data here is
121 * specific to the cgroup driver used.
122 */
123 void *cgroup_data;
124
125 /* Data to be passed to handler ops. */
126 void *data;
127
128 /* Current state of the container. */
129 lxc_state_t state;
130
131 /* The exit status of the container; not defined unless ->init_died ==
132 * true.
133 */
134 int exit_status;
135 };
136
137 struct lxc_operations {
138 int (*start)(struct lxc_handler *, void *);
139 int (*post_start)(struct lxc_handler *, void *);
140 };
141
142 extern int lxc_poll(const char *name, struct lxc_handler *handler);
143 extern int lxc_set_state(const char *name, struct lxc_handler *handler,
144 lxc_state_t state);
145 extern int lxc_serve_state_clients(const char *name,
146 struct lxc_handler *handler,
147 lxc_state_t state);
148 extern void lxc_abort(const char *name, struct lxc_handler *handler);
149 extern struct lxc_handler *lxc_init_handler(const char *name,
150 struct lxc_conf *conf,
151 const char *lxcpath,
152 bool daemonize);
153 extern void lxc_zero_handler(struct lxc_handler *handler);
154 extern void lxc_free_handler(struct lxc_handler *handler);
155 extern int lxc_init(const char *name, struct lxc_handler *handler);
156 extern void lxc_fini(const char *name, struct lxc_handler *handler);
157
158 /* lxc_check_inherited: Check for any open file descriptors and close them if
159 * requested.
160 * @param[in] conf The container's configuration.
161 * @param[in] closeall Whether we should close all open file descriptors.
162 * @param[in] fds_to_ignore Array of file descriptors to ignore.
163 * @param[in] len_fds Length of fds_to_ignore array.
164 */
165 extern int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
166 int *fds_to_ignore, size_t len_fds);
167 extern int __lxc_start(const char *, struct lxc_handler *,
168 struct lxc_operations *, void *, const char *, bool);
169
170 extern int resolve_clone_flags(struct lxc_handler *handler);
171
172 #endif