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