]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/core/execute.h
Add __attribute__((const, pure, format)) in various places
[thirdparty/systemd.git] / src / core / execute.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #pragma once
4
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
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
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
18 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with systemd; If not, see <http://www.gnu.org/licenses/>.
22 ***/
23
24 typedef struct ExecStatus ExecStatus;
25 typedef struct ExecCommand ExecCommand;
26 typedef struct ExecContext ExecContext;
27
28 #include <linux/types.h>
29 #include <sys/time.h>
30 #include <sys/resource.h>
31 #include <sys/capability.h>
32 #include <stdbool.h>
33 #include <stdio.h>
34 #include <sched.h>
35
36 struct CGroupBonding;
37 struct CGroupAttribute;
38
39 typedef struct Unit Unit;
40
41 #include "list.h"
42 #include "util.h"
43
44 typedef enum ExecInput {
45 EXEC_INPUT_NULL,
46 EXEC_INPUT_TTY,
47 EXEC_INPUT_TTY_FORCE,
48 EXEC_INPUT_TTY_FAIL,
49 EXEC_INPUT_SOCKET,
50 _EXEC_INPUT_MAX,
51 _EXEC_INPUT_INVALID = -1
52 } ExecInput;
53
54 typedef enum ExecOutput {
55 EXEC_OUTPUT_INHERIT,
56 EXEC_OUTPUT_NULL,
57 EXEC_OUTPUT_TTY,
58 EXEC_OUTPUT_SYSLOG,
59 EXEC_OUTPUT_SYSLOG_AND_CONSOLE,
60 EXEC_OUTPUT_KMSG,
61 EXEC_OUTPUT_KMSG_AND_CONSOLE,
62 EXEC_OUTPUT_JOURNAL,
63 EXEC_OUTPUT_JOURNAL_AND_CONSOLE,
64 EXEC_OUTPUT_SOCKET,
65 _EXEC_OUTPUT_MAX,
66 _EXEC_OUTPUT_INVALID = -1
67 } ExecOutput;
68
69 struct ExecStatus {
70 dual_timestamp start_timestamp;
71 dual_timestamp exit_timestamp;
72 pid_t pid;
73 int code; /* as in siginfo_t::si_code */
74 int status; /* as in sigingo_t::si_status */
75 };
76
77 struct ExecCommand {
78 char *path;
79 char **argv;
80 ExecStatus exec_status;
81 LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */
82 bool ignore;
83 };
84
85 struct ExecContext {
86 char **environment;
87 char **environment_files;
88
89 struct rlimit *rlimit[RLIMIT_NLIMITS];
90 char *working_directory, *root_directory;
91
92 mode_t umask;
93 int oom_score_adjust;
94 int nice;
95 int ioprio;
96 int cpu_sched_policy;
97 int cpu_sched_priority;
98
99 cpu_set_t *cpuset;
100 unsigned cpuset_ncpus;
101
102 ExecInput std_input;
103 ExecOutput std_output;
104 ExecOutput std_error;
105
106 nsec_t timer_slack_nsec;
107
108 char *tcpwrap_name;
109
110 char *tty_path;
111
112 bool tty_reset;
113 bool tty_vhangup;
114 bool tty_vt_disallocate;
115
116 bool ignore_sigpipe;
117
118 /* Since resolving these names might might involve socket
119 * connections and we don't want to deadlock ourselves these
120 * names are resolved on execution only and in the child
121 * process. */
122 char *user;
123 char *group;
124 char **supplementary_groups;
125
126 char *pam_name;
127
128 char *utmp_id;
129
130 char **read_write_dirs, **read_only_dirs, **inaccessible_dirs;
131 unsigned long mount_flags;
132
133 uint64_t capability_bounding_set_drop;
134
135 cap_t capabilities;
136 int secure_bits;
137
138 int syslog_priority;
139 char *syslog_identifier;
140 bool syslog_level_prefix;
141
142 bool cpu_sched_reset_on_fork;
143 bool non_blocking;
144 bool private_tmp;
145 bool private_network;
146 char *tmp_dir;
147 char *var_tmp_dir;
148
149 bool no_new_privileges;
150
151 bool control_group_modify;
152 int control_group_persistent;
153
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. */
159 bool same_pgrp;
160
161 uint32_t *syscall_filter;
162
163 bool oom_score_adjust_set:1;
164 bool nice_set:1;
165 bool ioprio_set:1;
166 bool cpu_sched_set:1;
167 };
168
169 int exec_spawn(ExecCommand *command,
170 char **argv,
171 ExecContext *context,
172 int fds[], unsigned n_fds,
173 char **environment,
174 bool apply_permissions,
175 bool apply_chroot,
176 bool apply_tty_stdin,
177 bool confirm_spawn,
178 struct CGroupBonding *cgroup_bondings,
179 struct CGroupAttribute *cgroup_attributes,
180 const char *cgroup_suffix,
181 const char *unit_id,
182 int pipe_fd[2],
183 pid_t *ret);
184
185 void exec_command_done(ExecCommand *c);
186 void exec_command_done_array(ExecCommand *c, unsigned n);
187
188 void exec_command_free_list(ExecCommand *c);
189 void exec_command_free_array(ExecCommand **c, unsigned n);
190
191 char *exec_command_line(char **argv);
192
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);
195 void exec_command_append_list(ExecCommand **l, ExecCommand *e);
196 int exec_command_set(ExecCommand *c, const char *path, ...);
197
198 void exec_context_init(ExecContext *c);
199 void exec_context_done(ExecContext *c, bool reloading_or_reexecuting);
200 void exec_context_tmp_dirs_done(ExecContext *c);
201 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
202 void exec_context_tty_reset(const ExecContext *context);
203
204 int exec_context_load_environment(const ExecContext *c, char ***l);
205
206 bool exec_context_may_touch_console(ExecContext *c);
207 void exec_context_serialize(const ExecContext *c, Unit *u, FILE *f);
208
209 void exec_status_start(ExecStatus *s, pid_t pid);
210 void exec_status_exit(ExecStatus *s, ExecContext *context, pid_t pid, int code, int status);
211 void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix);
212
213 const char* exec_output_to_string(ExecOutput i) _const_;
214 ExecOutput exec_output_from_string(const char *s) _pure_;
215
216 const char* exec_input_to_string(ExecInput i) _const_;
217 ExecInput exec_input_from_string(const char *s) _pure_;