]>
Commit | Line | Data |
---|---|---|
03467c88 | 1 | /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ |
5cb5a6ff | 2 | |
c2f1db8f | 3 | #pragma once |
5cb5a6ff | 4 | |
a7334b09 LP |
5 | /*** |
6 | This file is part of systemd. | |
7 | ||
8 | Copyright 2010 Lennart Poettering | |
9 | ||
10 | systemd is free software; you can redistribute it and/or modify it | |
5430f7f2 LP |
11 | under the terms of the GNU Lesser General Public License as published by |
12 | the Free Software Foundation; either version 2.1 of the License, or | |
a7334b09 LP |
13 | (at your option) any later version. |
14 | ||
15 | systemd is distributed in the hope that it will be useful, but | |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
5430f7f2 | 18 | Lesser General Public License for more details. |
a7334b09 | 19 | |
5430f7f2 | 20 | You should have received a copy of the GNU Lesser General Public License |
a7334b09 LP |
21 | along with systemd; If not, see <http://www.gnu.org/licenses/>. |
22 | ***/ | |
23 | ||
5cb5a6ff LP |
24 | typedef struct ExecStatus ExecStatus; |
25 | typedef struct ExecCommand ExecCommand; | |
26 | typedef struct ExecContext ExecContext; | |
27 | ||
dacdf153 | 28 | #include <linux/types.h> |
5cb5a6ff LP |
29 | #include <sys/time.h> |
30 | #include <sys/resource.h> | |
31 | #include <sys/capability.h> | |
32 | #include <stdbool.h> | |
33 | #include <stdio.h> | |
94f04347 | 34 | #include <sched.h> |
5cb5a6ff | 35 | |
8e274523 | 36 | struct CGroupBonding; |
ab1f0633 | 37 | struct CGroupAttribute; |
8e274523 | 38 | |
c17ec25e MS |
39 | typedef struct Unit Unit; |
40 | ||
5cb5a6ff | 41 | #include "list.h" |
034c6ed7 | 42 | #include "util.h" |
5cb5a6ff | 43 | |
80876c20 LP |
44 | typedef enum ExecInput { |
45 | EXEC_INPUT_NULL, | |
46 | EXEC_INPUT_TTY, | |
47 | EXEC_INPUT_TTY_FORCE, | |
48 | EXEC_INPUT_TTY_FAIL, | |
4f2d528d | 49 | EXEC_INPUT_SOCKET, |
80876c20 LP |
50 | _EXEC_INPUT_MAX, |
51 | _EXEC_INPUT_INVALID = -1 | |
52 | } ExecInput; | |
53 | ||
071830ff | 54 | typedef enum ExecOutput { |
80876c20 | 55 | EXEC_OUTPUT_INHERIT, |
94f04347 | 56 | EXEC_OUTPUT_NULL, |
80876c20 | 57 | EXEC_OUTPUT_TTY, |
94f04347 | 58 | EXEC_OUTPUT_SYSLOG, |
28dbc1e8 | 59 | EXEC_OUTPUT_SYSLOG_AND_CONSOLE, |
9a6bca7a | 60 | EXEC_OUTPUT_KMSG, |
28dbc1e8 | 61 | EXEC_OUTPUT_KMSG_AND_CONSOLE, |
706343f4 LP |
62 | EXEC_OUTPUT_JOURNAL, |
63 | EXEC_OUTPUT_JOURNAL_AND_CONSOLE, | |
4f2d528d | 64 | EXEC_OUTPUT_SOCKET, |
94f04347 LP |
65 | _EXEC_OUTPUT_MAX, |
66 | _EXEC_OUTPUT_INVALID = -1 | |
071830ff LP |
67 | } ExecOutput; |
68 | ||
5cb5a6ff | 69 | struct ExecStatus { |
63983207 LP |
70 | dual_timestamp start_timestamp; |
71 | dual_timestamp exit_timestamp; | |
9d58f1db | 72 | pid_t pid; |
9152c765 LP |
73 | int code; /* as in siginfo_t::si_code */ |
74 | int status; /* as in sigingo_t::si_status */ | |
5cb5a6ff LP |
75 | }; |
76 | ||
77 | struct ExecCommand { | |
78 | char *path; | |
79 | char **argv; | |
034c6ed7 LP |
80 | ExecStatus exec_status; |
81 | LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */ | |
7fab9d01 | 82 | bool ignore; |
5cb5a6ff LP |
83 | }; |
84 | ||
85 | struct ExecContext { | |
86 | char **environment; | |
8c7be95e LP |
87 | char **environment_files; |
88 | ||
94f04347 | 89 | struct rlimit *rlimit[RLIMIT_NLIMITS]; |
9eba9da4 | 90 | char *working_directory, *root_directory; |
9d58f1db LP |
91 | |
92 | mode_t umask; | |
dd6c17b1 | 93 | int oom_score_adjust; |
5cb5a6ff | 94 | int nice; |
9eba9da4 | 95 | int ioprio; |
94f04347 LP |
96 | int cpu_sched_policy; |
97 | int cpu_sched_priority; | |
9d58f1db | 98 | |
82c121a4 LP |
99 | cpu_set_t *cpuset; |
100 | unsigned cpuset_ncpus; | |
fb33a393 | 101 | |
80876c20 LP |
102 | ExecInput std_input; |
103 | ExecOutput std_output; | |
104 | ExecOutput std_error; | |
105 | ||
d88a251b | 106 | nsec_t timer_slack_nsec; |
071830ff | 107 | |
df1f0afe LP |
108 | char *tcpwrap_name; |
109 | ||
9d58f1db | 110 | char *tty_path; |
5cb5a6ff | 111 | |
6ea832a2 LP |
112 | bool tty_reset; |
113 | bool tty_vhangup; | |
114 | bool tty_vt_disallocate; | |
115 | ||
353e12c2 LP |
116 | bool ignore_sigpipe; |
117 | ||
94f04347 | 118 | /* Since resolving these names might might involve socket |
5cb5a6ff | 119 | * connections and we don't want to deadlock ourselves these |
94f04347 LP |
120 | * names are resolved on execution only and in the child |
121 | * process. */ | |
5cb5a6ff LP |
122 | char *user; |
123 | char *group; | |
124 | char **supplementary_groups; | |
9d58f1db | 125 | |
5b6319dc LP |
126 | char *pam_name; |
127 | ||
169c1bda LP |
128 | char *utmp_id; |
129 | ||
15ae422b LP |
130 | char **read_write_dirs, **read_only_dirs, **inaccessible_dirs; |
131 | unsigned long mount_flags; | |
132 | ||
9d58f1db LP |
133 | uint64_t capability_bounding_set_drop; |
134 | ||
135 | cap_t capabilities; | |
136 | int secure_bits; | |
137 | ||
7fab9d01 LP |
138 | int syslog_priority; |
139 | char *syslog_identifier; | |
140 | bool syslog_level_prefix; | |
141 | ||
9d58f1db LP |
142 | bool cpu_sched_reset_on_fork; |
143 | bool non_blocking; | |
15ae422b | 144 | bool private_tmp; |
ff01d048 | 145 | bool private_network; |
c17ec25e MS |
146 | char *tmp_dir; |
147 | char *var_tmp_dir; | |
9d58f1db | 148 | |
8351ceae LP |
149 | bool no_new_privileges; |
150 | ||
64747e2d | 151 | bool control_group_modify; |
891703e1 | 152 | int control_group_persistent; |
64747e2d | 153 | |
9d58f1db LP |
154 | /* This is not exposed to the user but available |
155 | * internally. We need it to make sure that whenever we spawn | |
156 | * /bin/mount it is run in the same process group as us so | |
157 | * that the autofs logic detects that it belongs to us and we | |
158 | * don't enter a trigger loop. */ | |
74922904 | 159 | bool same_pgrp; |
2e22afe9 | 160 | |
8351ceae LP |
161 | uint32_t *syscall_filter; |
162 | ||
dd6c17b1 | 163 | bool oom_score_adjust_set:1; |
7fab9d01 LP |
164 | bool nice_set:1; |
165 | bool ioprio_set:1; | |
166 | bool cpu_sched_set:1; | |
5cb5a6ff LP |
167 | }; |
168 | ||
9fb86720 | 169 | int exec_spawn(ExecCommand *command, |
9e2f7c11 | 170 | char **argv, |
c17ec25e | 171 | ExecContext *context, |
c2748801 | 172 | int fds[], unsigned n_fds, |
1137a57c | 173 | char **environment, |
81a2b7ce LP |
174 | bool apply_permissions, |
175 | bool apply_chroot, | |
1e3ad081 | 176 | bool apply_tty_stdin, |
80876c20 | 177 | bool confirm_spawn, |
8e274523 | 178 | struct CGroupBonding *cgroup_bondings, |
ab1f0633 | 179 | struct CGroupAttribute *cgroup_attributes, |
ecedd90f | 180 | const char *cgroup_suffix, |
62bca2c6 | 181 | const char *unit_id, |
f2b68789 | 182 | int pipe_fd[2], |
81a2b7ce | 183 | pid_t *ret); |
5cb5a6ff | 184 | |
43d0fcbd LP |
185 | void exec_command_done(ExecCommand *c); |
186 | void exec_command_done_array(ExecCommand *c, unsigned n); | |
187 | ||
5cb5a6ff | 188 | void exec_command_free_list(ExecCommand *c); |
034c6ed7 | 189 | void exec_command_free_array(ExecCommand **c, unsigned n); |
5cb5a6ff | 190 | |
9e2f7c11 LP |
191 | char *exec_command_line(char **argv); |
192 | ||
44d8db9e LP |
193 | void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix); |
194 | void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix); | |
a6a80b4f | 195 | void exec_command_append_list(ExecCommand **l, ExecCommand *e); |
26fd040d | 196 | int exec_command_set(ExecCommand *c, const char *path, ...); |
44d8db9e | 197 | |
034c6ed7 | 198 | void exec_context_init(ExecContext *c); |
c17ec25e MS |
199 | void exec_context_done(ExecContext *c, bool reloading_or_reexecuting); |
200 | void exec_context_tmp_dirs_done(ExecContext *c); | |
5cb5a6ff | 201 | void exec_context_dump(ExecContext *c, FILE* f, const char *prefix); |
6ea832a2 | 202 | void exec_context_tty_reset(const ExecContext *context); |
5cb5a6ff | 203 | |
8c7be95e LP |
204 | int exec_context_load_environment(const ExecContext *c, char ***l); |
205 | ||
6ac8fdc9 | 206 | bool exec_context_may_touch_console(ExecContext *c); |
c17ec25e | 207 | void exec_context_serialize(const ExecContext *c, Unit *u, FILE *f); |
6ac8fdc9 | 208 | |
b58b4116 | 209 | void exec_status_start(ExecStatus *s, pid_t pid); |
6ea832a2 | 210 | void exec_status_exit(ExecStatus *s, ExecContext *context, pid_t pid, int code, int status); |
9fb86720 | 211 | void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix); |
5cb5a6ff | 212 | |
94f04347 | 213 | const char* exec_output_to_string(ExecOutput i); |
1365b53f | 214 | ExecOutput exec_output_from_string(const char *s); |
94f04347 LP |
215 | |
216 | const char* exec_input_to_string(ExecInput i); | |
1365b53f | 217 | ExecInput exec_input_from_string(const char *s); |