chiark / gitweb /
fsck: drop -C from fsck cmdline to avoid EPIPE
[elogind.git] / src / execute.h
1 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
2
3 #ifndef fooexecutehfoo
4 #define fooexecutehfoo
5
6 /***
7   This file is part of systemd.
8
9   Copyright 2010 Lennart Poettering
10
11   systemd is free software; you can redistribute it and/or modify it
12   under the terms of the GNU General Public License as published by
13   the Free Software Foundation; either version 2 of the License, or
14   (at your option) any later version.
15
16   systemd is distributed in the hope that it will be useful, but
17   WITHOUT ANY WARRANTY; without even the implied warranty of
18   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19   General Public License for more details.
20
21   You should have received a copy of the GNU General Public License
22   along with systemd; If not, see <http://www.gnu.org/licenses/>.
23 ***/
24
25 typedef struct ExecStatus ExecStatus;
26 typedef struct ExecCommand ExecCommand;
27 typedef struct ExecContext ExecContext;
28
29 #include <linux/types.h>
30 #include <sys/time.h>
31 #include <sys/resource.h>
32 #include <sys/capability.h>
33 #include <stdbool.h>
34 #include <stdio.h>
35 #include <sched.h>
36
37 struct CGroupBonding;
38
39 #include "list.h"
40 #include "util.h"
41
42 /* Abstract namespace! */
43 #define LOGGER_SOCKET "/org/freedesktop/systemd1/logger"
44
45 /* This doesn't really belong here, but I couldn't find a better place to put this. */
46 #define SIGNALS_CRASH_HANDLER SIGSEGV,SIGILL,SIGFPE,SIGBUS,SIGQUIT,SIGABRT
47 #define SIGNALS_IGNORE SIGKILL,SIGPIPE
48
49 typedef enum KillMode {
50         KILL_CONTROL_GROUP = 0,
51         KILL_PROCESS_GROUP,
52         KILL_PROCESS,
53         KILL_NONE,
54         _KILL_MODE_MAX,
55         _KILL_MODE_INVALID = -1
56 } KillMode;
57
58 typedef enum ExecInput {
59         EXEC_INPUT_NULL,
60         EXEC_INPUT_TTY,
61         EXEC_INPUT_TTY_FORCE,
62         EXEC_INPUT_TTY_FAIL,
63         EXEC_INPUT_SOCKET,
64         _EXEC_INPUT_MAX,
65         _EXEC_INPUT_INVALID = -1
66 } ExecInput;
67
68 typedef enum ExecOutput {
69         EXEC_OUTPUT_INHERIT,
70         EXEC_OUTPUT_NULL,
71         EXEC_OUTPUT_TTY,
72         EXEC_OUTPUT_SYSLOG,
73         EXEC_OUTPUT_KMSG,
74         EXEC_OUTPUT_SOCKET,
75         _EXEC_OUTPUT_MAX,
76         _EXEC_OUTPUT_INVALID = -1
77 } ExecOutput;
78
79 struct ExecStatus {
80         dual_timestamp start_timestamp;
81         dual_timestamp exit_timestamp;
82         pid_t pid;
83         int code;     /* as in siginfo_t::si_code */
84         int status;   /* as in sigingo_t::si_status */
85 };
86
87 struct ExecCommand {
88         char *path;
89         char **argv;
90         ExecStatus exec_status;
91         LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */
92         bool ignore;
93 };
94
95 struct ExecContext {
96         char **environment;
97         struct rlimit *rlimit[RLIMIT_NLIMITS];
98         char *working_directory, *root_directory;
99
100         mode_t umask;
101         int oom_score_adjust;
102         int nice;
103         int ioprio;
104         int cpu_sched_policy;
105         int cpu_sched_priority;
106
107         cpu_set_t *cpuset;
108         unsigned cpuset_ncpus;
109
110         ExecInput std_input;
111         ExecOutput std_output;
112         ExecOutput std_error;
113
114         unsigned long timer_slack_nsec;
115
116         char *tcpwrap_name;
117
118         char *tty_path;
119
120         /* Since resolving these names might might involve socket
121          * connections and we don't want to deadlock ourselves these
122          * names are resolved on execution only and in the child
123          * process. */
124         char *user;
125         char *group;
126         char **supplementary_groups;
127
128         char *pam_name;
129
130         char *utmp_id;
131
132         char **read_write_dirs, **read_only_dirs, **inaccessible_dirs;
133         unsigned long mount_flags;
134
135         uint64_t capability_bounding_set_drop;
136
137         /* Not relevant for spawning processes, just for killing */
138         KillMode kill_mode;
139         int kill_signal;
140
141         cap_t capabilities;
142         int secure_bits;
143
144         int syslog_priority;
145         char *syslog_identifier;
146         bool syslog_level_prefix;
147
148         bool cpu_sched_reset_on_fork;
149         bool non_blocking;
150         bool private_tmp;
151
152         /* This is not exposed to the user but available
153          * internally. We need it to make sure that whenever we spawn
154          * /bin/mount it is run in the same process group as us so
155          * that the autofs logic detects that it belongs to us and we
156          * don't enter a trigger loop. */
157         bool same_pgrp;
158
159         bool oom_score_adjust_set:1;
160         bool nice_set:1;
161         bool ioprio_set:1;
162         bool cpu_sched_set:1;
163         bool timer_slack_nsec_set:1;
164 };
165
166 int exec_spawn(ExecCommand *command,
167                char **argv,
168                const ExecContext *context,
169                int fds[], unsigned n_fds,
170                char **environment,
171                bool apply_permissions,
172                bool apply_chroot,
173                bool apply_tty_stdin,
174                bool confirm_spawn,
175                struct CGroupBonding *cgroup_bondings,
176                pid_t *ret);
177
178 void exec_command_done(ExecCommand *c);
179 void exec_command_done_array(ExecCommand *c, unsigned n);
180
181 void exec_command_free_list(ExecCommand *c);
182 void exec_command_free_array(ExecCommand **c, unsigned n);
183
184 char *exec_command_line(char **argv);
185
186 void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix);
187 void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix);
188 void exec_command_append_list(ExecCommand **l, ExecCommand *e);
189 int exec_command_set(ExecCommand *c, const char *path, ...);
190
191 void exec_context_init(ExecContext *c);
192 void exec_context_done(ExecContext *c);
193 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
194
195 void exec_status_start(ExecStatus *s, pid_t pid);
196 void exec_status_exit(ExecStatus *s, pid_t pid, int code, int status, const char *utmp_id);
197 void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix);
198
199 const char* exec_output_to_string(ExecOutput i);
200 int exec_output_from_string(const char *s);
201
202 const char* exec_input_to_string(ExecInput i);
203 int exec_input_from_string(const char *s);
204
205 #endif