chiark / gitweb /
581736d0f5cc5c540cc32d05f6ca1cf75c361242
[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
16 #include "list.h"
17 #include "util.h"
18
19 /* Abstract namespace! */
20 #define LOGGER_SOCKET "/systemd/logger"
21
22 typedef enum ExecOutput {
23         EXEC_CONSOLE,
24         EXEC_NULL,
25         EXEC_SYSLOG,
26         EXEC_KERNEL
27 } ExecOutput;
28
29 struct ExecStatus {
30         pid_t pid;
31         usec_t timestamp;
32         int code;     /* as in siginfo_t::si_code */
33         int status;   /* as in sigingo_t::si_status */
34 };
35
36 struct ExecCommand {
37         char *path;
38         char **argv;
39         ExecStatus exec_status;
40         LIST_FIELDS(ExecCommand, command); /* useful for chaining commands */
41 };
42
43 struct ExecContext {
44         char **environment;
45         mode_t umask;
46         struct rlimit *rlimit[RLIMIT_NLIMITS];  /* FIXME: load-fragment parser missing */
47         char *working_directory, *root_directory;
48         int oom_adjust;
49         int nice;
50         int ioprio;
51
52         bool oom_adjust_set:1;
53         bool nice_set:1;
54         bool ioprio_set:1;
55
56         ExecOutput output;
57         int syslog_priority;
58         char *syslog_identifier;
59
60          /* FIXME: all privs related settings need parser and enforcer */
61         cap_t capabilities;
62         bool capabilities_set:1;
63
64         /* since resolving these names might might involve socket
65          * connections and we don't want to deadlock ourselves these
66          * names are resolved on execution only. */
67         char *user;
68         char *group;
69         char **supplementary_groups;
70 };
71
72 typedef enum ExitStatus {
73         /* EXIT_SUCCESS defined by libc */
74         /* EXIT_FAILURE defined by libc */
75         EXIT_INVALIDARGUMENT = 2,
76         EXIT_NOTIMPLEMENTED = 3,
77         EXIT_NOPERMISSION = 4,
78         EXIT_NOTINSTALLED = 5,
79         EXIT_NOTCONFIGURED = 6,
80         EXIT_NOTRUNNING = 7,
81
82         /* The LSB suggests that error codes >= 200 are "reserved". We
83          * use them here under the assumption that they hence are
84          * unused by init scripts.
85          *
86          * http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/iniscrptact.html */
87
88         EXIT_CHDIR = 200,
89         EXIT_NICE,
90         EXIT_FDS,
91         EXIT_EXEC,
92         EXIT_MEMORY,
93         EXIT_LIMITS,
94         EXIT_OOM_ADJUST,
95         EXIT_SIGNAL_MASK,
96         EXIT_OUTPUT,
97         EXIT_CHROOT,
98         EXIT_PGID,
99         EXIT_IOPRIO
100 } ExitStatus;
101
102 int exec_spawn(const ExecCommand *command, const ExecContext *context, int *fds, unsigned n_fds, pid_t *ret);
103
104 void exec_command_free_list(ExecCommand *c);
105 void exec_command_free_array(ExecCommand **c, unsigned n);
106
107 char *exec_command_line(ExecCommand *c);
108 void exec_command_dump(ExecCommand *c, FILE *f, const char *prefix);
109 void exec_command_dump_list(ExecCommand *c, FILE *f, const char *prefix);
110
111 void exec_context_init(ExecContext *c);
112 void exec_context_done(ExecContext *c);
113 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
114
115 void exec_status_fill(ExecStatus *s, pid_t pid, int code, int status);
116
117 #endif