]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/start.h
Merge pull request #2109 from duguhaotian/new
[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 /* The clone flags that were requested. */
41 int clone_flags;
42
43 /* The clone flags to actually use when calling lxc_clone(). They may
44 * differ from clone_flags because of ordering requirements (e.g.
45 * CLONE_NEWNET and CLONE_NEWUSER).
46 */
47 int on_clone_flags;
48
49 /* File descriptor to pin the rootfs for privileged containers. */
50 int pinfd;
51
52 /* Signal file descriptor. */
53 int sigfd;
54
55 /* List of file descriptors referring to the namespaces of the
56 * container. Note that these are not necessarily identical to
57 * the "clone_flags" handler field in case namespace inheritance is
58 * requested.
59 */
60 int nsfd[LXC_NS_MAX];
61
62 /* Abstract unix domain SOCK_DGRAM socketpair to pass arbitrary data
63 * between child and parent.
64 */
65 int data_sock[2];
66
67 /* The socketpair() fds used to wait on successful daemonized startup. */
68 int state_socket_pair[2];
69
70 /* Socketpair to synchronize processes during container creation. */
71 int sync_sock[2];
72
73 /* Pointer to the name of the container. Do not free! */
74 const char *name;
75
76 /* Pointer to the path the container. Do not free! */
77 const char *lxcpath;
78
79 /* Whether the container's startup process euid is 0. */
80 bool am_root;
81
82 /* Indicates whether should we close std{in,out,err} on start. */
83 bool backgrounded;
84
85 /* The child's pid. */
86 pid_t pid;
87
88 /* Whether the child has already exited. */
89 bool init_died;
90
91 /* The signal mask prior to setting up the signal file descriptor. */
92 sigset_t oldmask;
93
94 /* The container's in-memory configuration. */
95 struct lxc_conf *conf;
96
97 /* A set of operations to be performed at various stages of the
98 * container's life.
99 */
100 struct lxc_operations *ops;
101
102 /* This holds the cgroup information. Note that the data here is
103 * specific to the cgroup driver used.
104 */
105 void *cgroup_data;
106
107 /* Data to be passed to handler ops. */
108 void *data;
109
110 /* Current state of the container. */
111 lxc_state_t state;
112
113 /* The exit status of the container; not defined unless ->init_died ==
114 * true.
115 */
116 int exit_status;
117 };
118
119 struct lxc_operations {
120 int (*start)(struct lxc_handler *, void *);
121 int (*post_start)(struct lxc_handler *, void *);
122 };
123
124 extern int lxc_poll(const char *name, struct lxc_handler *handler);
125 extern int lxc_set_state(const char *name, struct lxc_handler *handler,
126 lxc_state_t state);
127 extern int lxc_serve_state_clients(const char *name,
128 struct lxc_handler *handler,
129 lxc_state_t state);
130 extern void lxc_abort(const char *name, struct lxc_handler *handler);
131 extern struct lxc_handler *lxc_init_handler(const char *name,
132 struct lxc_conf *conf,
133 const char *lxcpath,
134 bool daemonize);
135 extern void lxc_zero_handler(struct lxc_handler *handler);
136 extern void lxc_free_handler(struct lxc_handler *handler);
137 extern int lxc_init(const char *name, struct lxc_handler *handler);
138 extern void lxc_fini(const char *name, struct lxc_handler *handler);
139
140 /* lxc_check_inherited: Check for any open file descriptors and close them if
141 * requested.
142 * @param[in] conf The container's configuration.
143 * @param[in] closeall Whether we should close all open file descriptors.
144 * @param[in] fds_to_ignore Array of file descriptors to ignore.
145 * @param[in] len_fds Length of fds_to_ignore array.
146 */
147 extern int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
148 int *fds_to_ignore, size_t len_fds);
149 extern int __lxc_start(const char *, struct lxc_handler *,
150 struct lxc_operations *, void *, const char *, bool);
151
152 extern int resolve_clone_flags(struct lxc_handler *handler);
153
154 #endif