]> git.ipfire.org Git - thirdparty/systemd.git/blob - execute.h
make sure the log functions don't modify errno
[thirdparty/systemd.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
16 #include "list.h"
17 #include "util.h"
18
19 struct ExecStatus {
20 pid_t pid;
21 usec_t timestamp;
22 int code; /* as in siginfo_t::si_code */
23 int status; /* as in sigingo_t::si_status */
24 };
25
26 struct ExecCommand {
27 char *path;
28 char **argv;
29 ExecStatus exec_status;
30 LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */
31 };
32
33 struct ExecContext {
34 char **environment;
35 mode_t umask;
36 struct rlimit *rlimit[RLIMIT_NLIMITS];
37 int oom_adjust;
38 int nice;
39 char *directory;
40
41 cap_t capabilities;
42 bool capabilities_set:1;
43
44 /* since resolving these names might might involve socket
45 * connections and we don't want to deadlock ourselves these
46 * names are resolved on execution only. */
47 char *user;
48 char *group;
49 char **supplementary_groups;
50 };
51
52 typedef enum ExitStatus {
53 /* EXIT_SUCCESS defined by libc */
54 /* EXIT_FAILURE defined by libc */
55 EXIT_INVALIDARGUMENT = 2,
56 EXIT_NOTIMPLEMENTED = 3,
57 EXIT_NOPERMISSION = 4,
58 EXIT_NOTINSTALLED = 5,
59 EXIT_NOTCONFIGURED = 6,
60 EXIT_NOTRUNNING = 7,
61
62 /* The LSB suggests that error codes >= 200 are "reserved". We
63 * use them here under the assumption that they hence are
64 * unused by init scripts.
65 *
66 * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html */
67
68 EXIT_CHDIR = 200,
69 EXIT_NICE,
70 EXIT_FDS,
71 EXIT_EXEC,
72 EXIT_MEMORY,
73 EXIT_LIMITS,
74 EXIT_OOM_ADJUST,
75 EXIT_SIGNAL_MASK
76 } ExitStatus;
77
78 int exec_spawn(const ExecCommand *command, const ExecContext *context, int *fds, unsigned n_fds, pid_t *ret);
79
80 void exec_command_free_list(ExecCommand *c);
81 void exec_command_free_array(ExecCommand **c, unsigned n);
82
83 char *exec_command_line(ExecCommand *c);
84 void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix);
85 void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix);
86
87 void exec_context_init(ExecContext *c);
88 void exec_context_done(ExecContext *c);
89 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
90
91 void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status);
92
93 #endif