]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/attach_options.h
use same ifndef/define format for all headers
[mirror_lxc.git] / src / lxc / attach_options.h
1 /*! \file
2 *
3 * lxc: linux Container library
4 *
5 * (C) Copyright IBM Corp. 2007, 2008
6 *
7 * Authors:
8 * Daniel Lezcano <daniel.lezcano at free.fr>
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25 #ifndef __LXC_ATTACH_OPTIONS_H
26 #define __LXC_ATTACH_OPTIONS_H
27
28 #include <sys/types.h>
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /*!
35 * LXC environment policy.
36 */
37 typedef enum lxc_attach_env_policy_t {
38 LXC_ATTACH_KEEP_ENV, //!< Retain the environment
39 LXC_ATTACH_CLEAR_ENV //!< Clear the environment
40 } lxc_attach_env_policy_t;
41
42 enum {
43 /* the following are on by default: */
44 LXC_ATTACH_MOVE_TO_CGROUP = 0x00000001, //!< Move to cgroup
45 LXC_ATTACH_DROP_CAPABILITIES = 0x00000002, //!< Drop capabilities
46 LXC_ATTACH_SET_PERSONALITY = 0x00000004, //!< Set personality
47 LXC_ATTACH_LSM_EXEC = 0x00000008, //!< Execute under a Linux Security Module
48
49 /* the following are off by default */
50 LXC_ATTACH_REMOUNT_PROC_SYS = 0x00010000, //!< Remount /proc filesystem
51 LXC_ATTACH_LSM_NOW = 0x00020000, //!< FIXME: unknown
52
53 /* we have 16 bits for things that are on by default
54 * and 16 bits that are off by default, that should
55 * be sufficient to keep binary compatibility for
56 * a while
57 */
58 LXC_ATTACH_DEFAULT = 0x0000FFFF //!< Mask of flags to apply by default
59 };
60
61 /*! All Linux Security Module flags */
62 #define LXC_ATTACH_LSM (LXC_ATTACH_LSM_EXEC | LXC_ATTACH_LSM_NOW)
63
64 /*! LXC attach function type.
65 *
66 * Function to run in container.
67 *
68 * \param payload \ref lxc_attach_command_t to run.
69 *
70 * \return Function should return \c 0 on success, and any other value to denote failure.
71 */
72 typedef int (*lxc_attach_exec_t)(void* payload);
73
74 /*!
75 * LXC attach options for \ref lxc_container \c attach().
76 */
77 typedef struct lxc_attach_options_t {
78 /*! Any combination of LXC_ATTACH_* flags */
79 int attach_flags;
80
81 /*! The namespaces to attach to (CLONE_NEW... flags) */
82 int namespaces;
83
84 /*! Initial personality (\c -1 to autodetect).
85 * \warning This may be ignored if lxc is compiled without personality support)
86 */
87 long personality;
88
89 /*! Inital current directory, use \c NULL to use cwd.
90 * If the current directory does not exist in the container, the
91 * root directory will be used instead because of kernel defaults.
92 */
93 char* initial_cwd;
94
95 /*! The user-id to run as.
96 *
97 * \note Set to \c -1 for default behaviour (init uid for userns
98 * containers or \c 0 (super-user) if detection fails).
99 */
100 uid_t uid;
101
102 /*! The group-id to run as.
103 *
104 * \note Set to \c -1 for default behaviour (init gid for userns
105 * containers or \c 0 (super-user) if detection fails).
106 */
107 gid_t gid;
108
109 /*! Environment policy */
110 lxc_attach_env_policy_t env_policy;
111
112 /*! Extra environment variables to set in the container environment */
113 char** extra_env_vars;
114
115 /*! Names of environment variables in existing environment to retain
116 * in container environment.
117 */
118 char** extra_keep_env;
119
120 /**@{*/
121 /*! File descriptors for stdin, stdout and stderr,
122 * \c dup2() will be used before calling exec_function,
123 * (assuming not \c 0, \c 1 and \c 2 are specified) and the
124 * original fds are closed before passing control
125 * over. Any \c O_CLOEXEC flag will be removed after
126 * that.
127 */
128 int stdin_fd; /*!< stdin file descriptor */
129 int stdout_fd; /*!< stdout file descriptor */
130 int stderr_fd; /*!< stderr file descriptor */
131 /**@}*/
132 } lxc_attach_options_t;
133
134 /*! Default attach options to use */
135 #define LXC_ATTACH_OPTIONS_DEFAULT \
136 { \
137 /* .attach_flags = */ LXC_ATTACH_DEFAULT, \
138 /* .namespaces = */ -1, \
139 /* .personality = */ -1, \
140 /* .initial_cwd = */ NULL, \
141 /* .uid = */ (uid_t)-1, \
142 /* .gid = */ (gid_t)-1, \
143 /* .env_policy = */ LXC_ATTACH_KEEP_ENV, \
144 /* .extra_env_vars = */ NULL, \
145 /* .extra_keep_env = */ NULL, \
146 /* .stdin_fd = */ 0, 1, 2 \
147 }
148
149 /*!
150 * Representation of a command to run in a container.
151 */
152 typedef struct lxc_attach_command_t {
153 char* program; /*!< The program to run (passed to execvp) */
154 char** argv; /*!< The argv pointer of that program, including the program itself in argv[0] */
155 } lxc_attach_command_t;
156
157 /*!
158 * \brief Run a command in the container.
159 *
160 * \param payload \ref lxc_attach_command_t to run.
161 *
162 * \return \c -1 on error, exit code of lxc_attach_command_t program on success.
163 */
164 extern int lxc_attach_run_command(void* payload);
165
166 /*!
167 * \brief Run a shell command in the container.
168 *
169 * \param payload Not used.
170 *
171 * \return Exit code of shell.
172 */
173 extern int lxc_attach_run_shell(void* payload);
174
175 #ifdef __cplusplus
176 }
177 #endif
178
179 #endif