]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/start.h
Merge pull request #1659 from brauner/2017-06-28/do_not_use_cmd_socket_on_daemonized_...
[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 *
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
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23 #ifndef __LXC_START_H
24 #define __LXC_START_H
25
26 #include <signal.h>
27 #include <sys/param.h>
28 #include <sys/socket.h>
29 #include <sys/un.h>
30 #include <stdbool.h>
31
32 #include "conf.h"
33 #include "config.h"
34 #include "state.h"
35 #include "namespace.h"
36
37 struct lxc_handler {
38 pid_t pid;
39 char *name;
40 lxc_state_t state;
41 int clone_flags;
42 int sigfd;
43 sigset_t oldmask;
44 struct lxc_conf *conf;
45 struct lxc_operations *ops;
46 void *data;
47 int sv[2];
48 int pinfd;
49 const char *lxcpath;
50 void *cgroup_data;
51 int ttysock[2]; // socketpair for child->parent tty fd passing
52 bool backgrounded; // indicates whether should we close std{in,out,err} on start
53 int nsfd[LXC_NS_MAX];
54 int netnsfd;
55 /* The socketpair() fds used to wait on successful daemonized
56 * startup.
57 */
58 int state_socket_pair[2];
59 struct lxc_list state_clients;
60 };
61
62 struct lxc_operations {
63 int (*start)(struct lxc_handler *, void *);
64 int (*post_start)(struct lxc_handler *, void *);
65 };
66
67 struct state_client {
68 int clientfd;
69 lxc_state_t states[MAX_STATE];
70 };
71
72 extern int lxc_poll(const char *name, struct lxc_handler *handler);
73 extern int lxc_set_state(const char *name, struct lxc_handler *handler, lxc_state_t state);
74 extern void lxc_abort(const char *name, struct lxc_handler *handler);
75 extern struct lxc_handler *lxc_init_handler(const char *name,
76 struct lxc_conf *conf,
77 const char *lxcpath,
78 bool daemonize);
79 extern void lxc_free_handler(struct lxc_handler *handler);
80 extern int lxc_init(const char *name, struct lxc_handler *handler);
81 extern void lxc_fini(const char *name, struct lxc_handler *handler);
82
83 /* lxc_check_inherited: Check for any open file descriptors and close them if
84 * requested.
85 * @param[in] conf The container's configuration.
86 * @param[in] closeall Whether we should close all open file descriptors.
87 * @param[in] fds_to_ignore Array of file descriptors to ignore.
88 * @param[in] len_fds Length of fds_to_ignore array.
89 */
90 extern int lxc_check_inherited(struct lxc_conf *conf, bool closeall,
91 int *fds_to_ignore, size_t len_fds);
92 int __lxc_start(const char *, struct lxc_handler *, struct lxc_operations *,
93 void *, const char *, bool);
94
95 extern void resolve_clone_flags(struct lxc_handler *handler);
96 #endif
97