chiark / gitweb /
greatly extend what we enforce as process properties
[elogind.git] / execute.h
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #ifndef fooexecutehfoo
4 #define fooexecutehfoo
5
6 typedef struct ExecStatus ExecStatus;
7 typedef struct ExecCommand ExecCommand;
8 typedef struct ExecContext ExecContext;
9
10 #include <sys/time.h>
11 #include <sys/resource.h>
12 #include <sys/capability.h>
13 #include <stdbool.h>
14 #include <stdio.h>
15 #include <sched.h>
16
17 #include "list.h"
18 #include "util.h"
19
20 /* Abstract namespace! */
21 #define LOGGER_SOCKET "/systemd/logger"
22
23 typedef enum ExecOutput {
24         EXEC_OUTPUT_CONSOLE,
25         EXEC_OUTPUT_NULL,
26         EXEC_OUTPUT_SYSLOG,
27         EXEC_OUTPUT_KERNEL,
28         _EXEC_OUTPUT_MAX,
29         _EXEC_OUTPUT_INVALID = -1
30 } ExecOutput;
31
32 typedef enum ExecInput {
33         EXEC_INPUT_NULL,
34         EXEC_INPUT_CONSOLE,
35         _EXEC_INPUT_MAX,
36         _EXEC_INPUT_INVALID = -1
37 } ExecInput;
38
39 struct ExecStatus {
40         pid_t pid;
41         usec_t timestamp;
42         int code;     /* as in siginfo_t::si_code */
43         int status;   /* as in sigingo_t::si_status */
44 };
45
46 struct ExecCommand {
47         char *path;
48         char **argv;
49         ExecStatus exec_status;
50         LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */
51 };
52
53 struct ExecContext {
54         char **environment;
55         mode_t umask;
56         struct rlimit *rlimit[RLIMIT_NLIMITS];
57         char *working_directory, *root_directory;
58         int oom_adjust;
59         int nice;
60         int ioprio;
61         int cpu_sched_policy;
62         int cpu_sched_priority;
63         cpu_set_t cpu_affinity;
64         unsigned long timer_slack_ns;
65
66         bool oom_adjust_set:1;
67         bool nice_set:1;
68         bool ioprio_set:1;
69         bool cpu_sched_set:1;
70         bool cpu_affinity_set:1;
71         bool timer_slack_ns_set:1;
72
73         ExecInput input;
74         ExecOutput output;
75         int syslog_priority;
76         char *syslog_identifier;
77
78         /* FIXME: all privs related settings need to be enforced */
79         cap_t capabilities;
80         int secure_bits;
81         uint64_t capability_bounding_set_drop;
82
83         /* Since resolving these names might might involve socket
84          * connections and we don't want to deadlock ourselves these
85          * names are resolved on execution only and in the child
86          * process. */
87         char *user;
88         char *group;
89         char **supplementary_groups;
90 };
91
92 typedef enum ExitStatus {
93         /* EXIT_SUCCESS defined by libc */
94         /* EXIT_FAILURE defined by libc */
95         EXIT_INVALIDARGUMENT = 2,
96         EXIT_NOTIMPLEMENTED = 3,
97         EXIT_NOPERMISSION = 4,
98         EXIT_NOTINSTALLED = 5,
99         EXIT_NOTCONFIGURED = 6,
100         EXIT_NOTRUNNING = 7,
101
102         /* The LSB suggests that error codes >= 200 are "reserved". We
103          * use them here under the assumption that they hence are
104          * unused by init scripts.
105          * c->
106          *
107          * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html */
108
109         EXIT_CHDIR = 200,
110         EXIT_NICE,
111         EXIT_FDS,
112         EXIT_EXEC,
113         EXIT_MEMORY,
114         EXIT_LIMITS,
115         EXIT_OOM_ADJUST,
116         EXIT_SIGNAL_MASK,
117         EXIT_INPUT,
118         EXIT_OUTPUT,
119         EXIT_CHROOT,
120         EXIT_PGID,
121         EXIT_IOPRIO,
122         EXIT_TIMERSLACK,
123         EXIT_SECUREBITS,
124         EXIT_SETSCHEDULER,
125         EXIT_CPUAFFINITY
126 } ExitStatus;
127
128 int exec_spawn(const ExecCommand *command, const ExecContext *context, int *fds, unsigned n_fds, pid_t *ret);
129
130 void exec_command_free_list(ExecCommand *c);
131 void exec_command_free_array(ExecCommand **c, unsigned n);
132
133 char *exec_command_line(ExecCommand *c);
134 void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix);
135 void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix);
136
137 void exec_context_init(ExecContext *c);
138 void exec_context_done(ExecContext *c);
139 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
140
141 void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status);
142
143 const char* exec_output_to_string(ExecOutput i);
144 int exec_output_from_string(const char *s);
145
146 const char* exec_input_to_string(ExecInput i);
147 int exec_input_from_string(const char *s);
148
149 #endif