chiark / gitweb /
Merge remote branch 'kay/master'
[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 "/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         bool cpu_sched_reset_on_fork;
74
75         ExecInput input;
76         ExecOutput output;
77         int syslog_priority;
78         char *syslog_identifier;
79
80         /* FIXME: all privs related settings need to be enforced */
81         cap_t capabilities;
82         int secure_bits;
83         uint64_t capability_bounding_set_drop;
84
85         /* Since resolving these names might might involve socket
86          * connections and we don't want to deadlock ourselves these
87          * names are resolved on execution only and in the child
88          * process. */
89         char *user;
90         char *group;
91         char **supplementary_groups;
92 };
93
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,
116         EXIT_OOM_ADJUST,
117         EXIT_SIGNAL_MASK,
118         EXIT_INPUT,
119         EXIT_OUTPUT,
120         EXIT_CHROOT,
121         EXIT_PGID,
122         EXIT_IOPRIO,
123         EXIT_TIMERSLACK,
124         EXIT_SECUREBITS,
125         EXIT_SETSCHEDULER,
126         EXIT_CPUAFFINITY
127 } ExitStatus;
128
129 int exec_spawn(const ExecCommand *command, const ExecContext *context, int *fds, unsigned n_fds, pid_t *ret);
130
131 void exec_command_free_list(ExecCommand *c);
132 void exec_command_free_array(ExecCommand **c, unsigned n);
133
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
138 void exec_context_init(ExecContext *c);
139 void exec_context_done(ExecContext *c);
140 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
141
142 void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status);
143
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
150 #endif