]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/core/execute.h
service: introduce a proper service result if the start limit is hit
[thirdparty/systemd.git] / src / core / execute.h
CommitLineData
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
24typedef struct ExecStatus ExecStatus;
25typedef struct ExecCommand ExecCommand;
26typedef 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 36struct CGroupBonding;
ab1f0633 37struct CGroupAttribute;
8e274523 38
5cb5a6ff 39#include "list.h"
034c6ed7 40#include "util.h"
5cb5a6ff 41
80876c20
LP
42typedef enum ExecInput {
43 EXEC_INPUT_NULL,
44 EXEC_INPUT_TTY,
45 EXEC_INPUT_TTY_FORCE,
46 EXEC_INPUT_TTY_FAIL,
4f2d528d 47 EXEC_INPUT_SOCKET,
80876c20
LP
48 _EXEC_INPUT_MAX,
49 _EXEC_INPUT_INVALID = -1
50} ExecInput;
51
071830ff 52typedef enum ExecOutput {
80876c20 53 EXEC_OUTPUT_INHERIT,
94f04347 54 EXEC_OUTPUT_NULL,
80876c20 55 EXEC_OUTPUT_TTY,
94f04347 56 EXEC_OUTPUT_SYSLOG,
28dbc1e8 57 EXEC_OUTPUT_SYSLOG_AND_CONSOLE,
9a6bca7a 58 EXEC_OUTPUT_KMSG,
28dbc1e8 59 EXEC_OUTPUT_KMSG_AND_CONSOLE,
706343f4
LP
60 EXEC_OUTPUT_JOURNAL,
61 EXEC_OUTPUT_JOURNAL_AND_CONSOLE,
4f2d528d 62 EXEC_OUTPUT_SOCKET,
94f04347
LP
63 _EXEC_OUTPUT_MAX,
64 _EXEC_OUTPUT_INVALID = -1
071830ff
LP
65} ExecOutput;
66
5cb5a6ff 67struct ExecStatus {
63983207
LP
68 dual_timestamp start_timestamp;
69 dual_timestamp exit_timestamp;
9d58f1db 70 pid_t pid;
9152c765
LP
71 int code; /* as in siginfo_t::si_code */
72 int status; /* as in sigingo_t::si_status */
5cb5a6ff
LP
73};
74
75struct ExecCommand {
76 char *path;
77 char **argv;
034c6ed7
LP
78 ExecStatus exec_status;
79 LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */
7fab9d01 80 bool ignore;
5cb5a6ff
LP
81};
82
83struct ExecContext {
84 char **environment;
8c7be95e
LP
85 char **environment_files;
86
94f04347 87 struct rlimit *rlimit[RLIMIT_NLIMITS];
9eba9da4 88 char *working_directory, *root_directory;
9d58f1db
LP
89
90 mode_t umask;
dd6c17b1 91 int oom_score_adjust;
5cb5a6ff 92 int nice;
9eba9da4 93 int ioprio;
94f04347
LP
94 int cpu_sched_policy;
95 int cpu_sched_priority;
9d58f1db 96
82c121a4
LP
97 cpu_set_t *cpuset;
98 unsigned cpuset_ncpus;
fb33a393 99
80876c20
LP
100 ExecInput std_input;
101 ExecOutput std_output;
102 ExecOutput std_error;
103
d88a251b 104 nsec_t timer_slack_nsec;
071830ff 105
df1f0afe
LP
106 char *tcpwrap_name;
107
9d58f1db 108 char *tty_path;
5cb5a6ff 109
6ea832a2
LP
110 bool tty_reset;
111 bool tty_vhangup;
112 bool tty_vt_disallocate;
113
353e12c2
LP
114 bool ignore_sigpipe;
115
94f04347 116 /* Since resolving these names might might involve socket
5cb5a6ff 117 * connections and we don't want to deadlock ourselves these
94f04347
LP
118 * names are resolved on execution only and in the child
119 * process. */
5cb5a6ff
LP
120 char *user;
121 char *group;
122 char **supplementary_groups;
9d58f1db 123
5b6319dc
LP
124 char *pam_name;
125
169c1bda
LP
126 char *utmp_id;
127
15ae422b
LP
128 char **read_write_dirs, **read_only_dirs, **inaccessible_dirs;
129 unsigned long mount_flags;
130
9d58f1db
LP
131 uint64_t capability_bounding_set_drop;
132
133 cap_t capabilities;
134 int secure_bits;
135
7fab9d01
LP
136 int syslog_priority;
137 char *syslog_identifier;
138 bool syslog_level_prefix;
139
9d58f1db
LP
140 bool cpu_sched_reset_on_fork;
141 bool non_blocking;
15ae422b 142 bool private_tmp;
ff01d048 143 bool private_network;
9d58f1db 144
8351ceae
LP
145 bool no_new_privileges;
146
64747e2d 147 bool control_group_modify;
891703e1 148 int control_group_persistent;
64747e2d 149
9d58f1db
LP
150 /* This is not exposed to the user but available
151 * internally. We need it to make sure that whenever we spawn
152 * /bin/mount it is run in the same process group as us so
153 * that the autofs logic detects that it belongs to us and we
154 * don't enter a trigger loop. */
74922904 155 bool same_pgrp;
2e22afe9 156
8351ceae
LP
157 uint32_t *syscall_filter;
158
dd6c17b1 159 bool oom_score_adjust_set:1;
7fab9d01
LP
160 bool nice_set:1;
161 bool ioprio_set:1;
162 bool cpu_sched_set:1;
5cb5a6ff
LP
163};
164
9fb86720 165int exec_spawn(ExecCommand *command,
9e2f7c11 166 char **argv,
81a2b7ce 167 const ExecContext *context,
c2748801 168 int fds[], unsigned n_fds,
1137a57c 169 char **environment,
81a2b7ce
LP
170 bool apply_permissions,
171 bool apply_chroot,
1e3ad081 172 bool apply_tty_stdin,
80876c20 173 bool confirm_spawn,
8e274523 174 struct CGroupBonding *cgroup_bondings,
ab1f0633 175 struct CGroupAttribute *cgroup_attributes,
ecedd90f 176 const char *cgroup_suffix,
62bca2c6 177 const char *unit_id,
f2b68789 178 int pipe_fd[2],
81a2b7ce 179 pid_t *ret);
5cb5a6ff 180
43d0fcbd
LP
181void exec_command_done(ExecCommand *c);
182void exec_command_done_array(ExecCommand *c, unsigned n);
183
5cb5a6ff 184void exec_command_free_list(ExecCommand *c);
034c6ed7 185void exec_command_free_array(ExecCommand **c, unsigned n);
5cb5a6ff 186
9e2f7c11
LP
187char *exec_command_line(char **argv);
188
44d8db9e
LP
189void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix);
190void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix);
a6a80b4f 191void exec_command_append_list(ExecCommand **l, ExecCommand *e);
26fd040d 192int exec_command_set(ExecCommand *c, const char *path, ...);
44d8db9e 193
034c6ed7
LP
194void exec_context_init(ExecContext *c);
195void exec_context_done(ExecContext *c);
5cb5a6ff 196void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
6ea832a2 197void exec_context_tty_reset(const ExecContext *context);
5cb5a6ff 198
8c7be95e
LP
199int exec_context_load_environment(const ExecContext *c, char ***l);
200
b58b4116 201void exec_status_start(ExecStatus *s, pid_t pid);
6ea832a2 202void exec_status_exit(ExecStatus *s, ExecContext *context, pid_t pid, int code, int status);
9fb86720 203void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix);
5cb5a6ff 204
94f04347 205const char* exec_output_to_string(ExecOutput i);
1365b53f 206ExecOutput exec_output_from_string(const char *s);
94f04347
LP
207
208const char* exec_input_to_string(ExecInput i);
1365b53f 209ExecInput exec_input_from_string(const char *s);