1 /* SPDX-License-Identifier: LGPL-2.1+ */
6 #include <linux/sched.h>
10 #include <sys/param.h>
11 #include <sys/socket.h>
17 #include "namespace.h"
21 /* Record the clone for namespaces flags that the container requested.
24 * - All clone flags that were requested.
27 * - The clone flags for namespaces to actually use when calling
28 * lxc_clone(): After the container has started ns_on_clone_flags will
29 * list the clone flags that were unshare()ed rather then clone()ed
30 * because of ordering requirements (e.g. e.g. CLONE_NEWNET and
31 * CLONE_NEWUSER) or implementation details.
34 * - Flags for namespaces that were unshared, not cloned.
37 * - ns_on_clone flags | other flags used to create container.
40 unsigned int ns_clone_flags
;
41 unsigned int ns_on_clone_flags
;
42 unsigned int ns_unshare_flags
;
43 __aligned_u64 clone_flags
;
46 /* Signal file descriptor. */
49 /* List of file descriptors referring to the namespaces of the
50 * container. Note that these are not necessarily identical to
51 * the "clone_flags" handler field in case namespace inheritance is
56 /* Abstract unix domain SOCK_DGRAM socketpair to pass arbitrary data
57 * between child and parent.
61 /* The socketpair() fds used to wait on successful daemonized startup. */
62 int state_socket_pair
[2];
64 /* Socketpair to synchronize processes during container creation. */
67 /* Pointer to the name of the container. Do not free! */
70 /* Pointer to the path the container. Do not free! */
73 /* Whether the container's startup process euid is 0. */
76 /* Indicates whether should we close std{in,out,err} on start. */
79 /* The child's pid. */
82 /* The child's pidfd. */
85 /* The grandfather's pid when double-forking. */
88 /* The monitor's pid. */
91 int monitor_status_fd
;
93 /* Whether the child has already exited. */
96 /* The signal mask prior to setting up the signal file descriptor. */
99 /* The container's in-memory configuration. */
100 struct lxc_conf
*conf
;
102 /* A set of operations to be performed at various stages of the
105 struct lxc_operations
*ops
;
107 /* This holds the cgroup information. Note that the data here is
108 * specific to the cgroup driver used.
112 /* Data to be passed to handler ops. */
115 /* Current state of the container. */
118 /* The exit status of the container; not defined unless ->init_died ==
123 struct cgroup_ops
*cgroup_ops
;
125 /* Internal fds that always need to stay open. */
128 /* Static memory, don't free. */
129 struct lsm_ops
*lsm_ops
;
131 /* The namespace idx is guaranteed to match the stashed namespace path. */
132 char nsfd_paths
[LXC_NS_MAX
+ 1][LXC_EXPOSE_NAMESPACE_LEN
];
133 /* The namesace idx is _not_ guaranteed to match the stashed namespace path. */
134 lxc_namespace_t hook_argc
;
135 char *hook_argv
[LXC_NS_MAX
+ 1];
138 struct execute_args
{
143 struct lxc_operations
{
144 int (*start
)(struct lxc_handler
*, void *);
145 int (*post_start
)(struct lxc_handler
*, void *);
148 __hidden
extern int lxc_poll(const char *name
, struct lxc_handler
*handler
);
149 __hidden
extern int lxc_set_state(const char *name
, struct lxc_handler
*handler
, lxc_state_t state
);
150 __hidden
extern int lxc_serve_state_clients(const char *name
, struct lxc_handler
*handler
,
152 __hidden
extern void lxc_abort(struct lxc_handler
*handler
);
153 __hidden
extern struct lxc_handler
*lxc_init_handler(struct lxc_handler
*old
, const char *name
,
154 struct lxc_conf
*conf
, const char *lxcpath
,
156 __hidden
extern void lxc_put_handler(struct lxc_handler
*handler
);
157 __hidden
extern int lxc_init(const char *name
, struct lxc_handler
*handler
);
158 __hidden
extern void lxc_end(struct lxc_handler
*handler
);
160 /* lxc_check_inherited: Check for any open file descriptors and close them if
162 * @param[in] conf The container's configuration.
163 * @param[in] closeall Whether we should close all open file descriptors.
164 * @param[in] fds_to_ignore Array of file descriptors to ignore.
165 * @param[in] len_fds Length of fds_to_ignore array.
167 __hidden
extern int lxc_check_inherited(struct lxc_conf
*conf
, bool closeall
, int *fds_to_ignore
,
169 static inline int inherit_fds(struct lxc_handler
*handler
, bool closeall
)
171 return lxc_check_inherited(handler
->conf
, closeall
, handler
->keep_fds
,
172 ARRAY_SIZE(handler
->keep_fds
));
175 __hidden
extern int __lxc_start(struct lxc_handler
*, struct lxc_operations
*, void *, const char *,
178 __hidden
extern int resolve_clone_flags(struct lxc_handler
*handler
);
179 __hidden
extern void lxc_expose_namespace_environment(const struct lxc_handler
*handler
);
181 static inline bool container_uses_namespace(const struct lxc_handler
*handler
,
182 unsigned int ns_flag
)
184 return (handler
->ns_clone_flags
& ns_flag
);