chiark / gitweb /
add simple event loop
[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
18 struct ExecStatus {
19         pid_t pid;
20         time_t timestamp;
21         int code;     /* as in siginfo_t::si_code */
22         int status;   /* as in sigingo_t::si_status */
23 };
24
25 struct ExecCommand {
26         char *path;
27         char **argv;
28         ExecStatus last_exec_status;
29         LIST_FIELDS(ExecCommand);
30 };
31
32 struct ExecContext {
33         char **environment;
34         mode_t umask;
35         struct rlimit *rlimit[RLIMIT_NLIMITS];
36         cap_t capabilities;
37         bool capabilities_set:1;
38         bool dumpable:1;
39         int oom_adjust;
40         int nice;
41         char *chdir;
42
43         /* since resolving these names might might involve socket
44          * connections and we don't want to deadlock ourselves these
45          * names are resolved on execution only. */
46         char *user;
47         char *group;
48         char **supplementary_groups;
49 };
50
51 int exec_spawn(const ExecCommand *command, const ExecContext *context, pid_t *ret);
52
53 void exec_context_free(ExecContext *c);
54 void exec_command_free_list(ExecCommand *c);
55
56 void exec_context_dump(ExecContext *c, FILE* f, const char *prefix);
57
58 void exec_context_defaults(ExecContext *c);
59
60 #endif