]> git.proxmox.com Git - mirror_lxc.git/blob - src/lxc/attach_options.h
licensing: Add missing headers and FSF address
[mirror_lxc.git] / src / lxc / attach_options.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
24 #ifndef _LXC_ATTACH_OPTIONS_H
25 #define _LXC_ATTACH_OPTIONS_H
26
27 #include <sys/types.h>
28
29 typedef enum lxc_attach_env_policy_t {
30 LXC_ATTACH_KEEP_ENV,
31 LXC_ATTACH_CLEAR_ENV
32 } lxc_attach_env_policy_t;
33
34 enum {
35 /* the following are on by default: */
36 LXC_ATTACH_MOVE_TO_CGROUP = 0x00000001,
37 LXC_ATTACH_DROP_CAPABILITIES = 0x00000002,
38 LXC_ATTACH_SET_PERSONALITY = 0x00000004,
39 LXC_ATTACH_APPARMOR = 0x00000008,
40
41 /* the following are off by default */
42 LXC_ATTACH_REMOUNT_PROC_SYS = 0x00010000,
43
44 /* we have 16 bits for things that are on by default
45 * and 16 bits that are off by default, that should
46 * be sufficient to keep binary compatibility for
47 * a while
48 */
49 LXC_ATTACH_DEFAULT = 0x0000FFFF
50 };
51
52 typedef struct lxc_attach_options_t lxc_attach_options_t;
53 typedef int (*lxc_attach_exec_t)(void* payload);
54
55 struct lxc_attach_options_t {
56 /* any combination of the above enum */
57 int attach_flags;
58 /* the namespaces to attach to (CLONE_NEW... flags) */
59 int namespaces;
60 /* initial personality, -1 to autodetect
61 * (may be ignored if lxc is compiled w/o personality support) */
62 long personality;
63
64 /* inital current directory, use NULL to use cwd
65 * (might not exist in container, then / will be
66 * used because of kernel defaults)
67 */
68 char* initial_cwd;
69
70 /* the uid and gid to attach to,
71 * -1 for default (init uid/gid for userns containers,
72 * otherwise or if detection fails 0/0)
73 */
74 uid_t uid;
75 gid_t gid;
76
77 /* environment handling */
78 lxc_attach_env_policy_t env_policy;
79 char** extra_env_vars;
80 char** extra_keep_env;
81
82 /* file descriptors for stdin, stdout and stderr,
83 * dup2() will be used before calling exec_function,
84 * (assuming not 0, 1 and 2 are specified) and the
85 * original fds are closed before passing control
86 * over. Any O_CLOEXEC flag will be removed after
87 * that
88 */
89 int stdin_fd;
90 int stdout_fd;
91 int stderr_fd;
92 };
93
94 #define LXC_ATTACH_OPTIONS_DEFAULT \
95 { \
96 /* .attach_flags = */ LXC_ATTACH_DEFAULT, \
97 /* .namespaces = */ -1, \
98 /* .personality = */ -1, \
99 /* .initial_cwd = */ NULL, \
100 /* .uid = */ (uid_t)-1, \
101 /* .gid = */ (gid_t)-1, \
102 /* .env_policy = */ LXC_ATTACH_KEEP_ENV, \
103 /* .extra_env_vars = */ NULL, \
104 /* .extra_keep_env = */ NULL, \
105 /* .stdin_fd = */ 0, 1, 2 \
106 }
107
108 typedef struct lxc_attach_command_t {
109 char* program; /* the program to run (passed to execvp) */
110 char** argv; /* the argv pointer of that program, including the program itself in argv[0] */
111 } lxc_attach_command_t;
112
113 /* default execution functions:
114 * run_command: pointer to lxc_attach_command_t
115 * run_shell: no payload, will be ignored
116 */
117 extern int lxc_attach_run_command(void* payload);
118 extern int lxc_attach_run_shell(void* payload);
119
120 #endif