]>
Commit | Line | Data |
---|---|---|
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 "/org/freedesktop.org/systemd1/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 | * | |
106 | * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html */ | |
107 | ||
108 | EXIT_CHDIR = 200, | |
109 | EXIT_NICE, | |
110 | EXIT_FDS, | |
111 | EXIT_EXEC, | |
112 | EXIT_MEMORY, | |
113 | EXIT_LIMITS, | |
114 | EXIT_OOM_ADJUST, | |
115 | EXIT_SIGNAL_MASK, | |
116 | EXIT_INPUT, | |
117 | EXIT_OUTPUT, | |
118 | EXIT_CHROOT, | |
119 | EXIT_PGID, | |
120 | EXIT_IOPRIO, | |
121 | EXIT_TIMERSLACK, | |
122 | EXIT_SECUREBITS, | |
123 | EXIT_SETSCHEDULER, | |
124 | EXIT_CPUAFFINITY | |
125 | } ExitStatus; | |
126 | ||
127 | int exec_spawn(const ExecCommand *command, const ExecContext *context, int *fds, unsigned n_fds, pid_t *ret); | |
128 | ||
129 | void exec_command_free_list(ExecCommand *c); | |
130 | void exec_command_free_array(ExecCommand **c, unsigned n); | |
131 | ||
132 | char *exec_command_line(ExecCommand *c); | |
133 | void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix); | |
134 | void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix); | |
135 | ||
136 | void exec_context_init(ExecContext *c); | |
137 | void exec_context_done(ExecContext *c); | |
138 | void exec_context_dump(ExecContext *c, FILE* f, const char *prefix); | |
139 | ||
140 | void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status); | |
141 | ||
142 | const char* exec_output_to_string(ExecOutput i); | |
143 | int exec_output_from_string(const char *s); | |
144 | ||
145 | const char* exec_input_to_string(ExecInput i); | |
146 | int exec_input_from_string(const char *s); | |
147 | ||
148 | #endif |