jail: add support for userns and cgroupsns
[project/procd.git] / service / instance.h
1 /*
2 * Copyright (C) 2013 Felix Fietkau <nbd@openwrt.org>
3 * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License version 2.1
7 * as published by the Free Software Foundation
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15 #ifndef __PROCD_INSTANCE_H
16 #define __PROCD_INSTANCE_H
17
18 #include <libubox/vlist.h>
19 #include <libubox/uloop.h>
20 #include <libubox/ustream.h>
21 #include "../utils/utils.h"
22
23 #define RESPAWN_ERROR (5 * 60)
24 #define SIGNALLED_OFFSET 128
25
26 struct jail {
27 bool procfs;
28 bool sysfs;
29 bool ubus;
30 bool log;
31 bool ronly;
32 bool netns;
33 bool userns;
34 bool cgroupsns;
35 char *name;
36 char *hostname;
37 struct blobmsg_list mount;
38 int argc;
39 };
40
41 struct service_instance {
42 struct vlist_node node;
43 struct service *srv;
44 const char *name;
45
46 int8_t nice;
47 bool valid;
48
49 char *user;
50 uid_t uid;
51 gid_t pw_gid;
52 char *group;
53 gid_t gr_gid;
54
55 bool halt;
56 bool restart;
57 bool respawn;
58 int respawn_count;
59 int reload_signal;
60 struct timespec start;
61
62 bool trace;
63 bool has_jail;
64 bool require_jail;
65 bool no_new_privs;
66 struct jail jail;
67 char *seccomp;
68 char *pidfile;
69 char *extroot;
70 int syslog_facility;
71 int exit_code;
72
73 uint32_t term_timeout;
74 uint32_t respawn_timeout;
75 uint32_t respawn_threshold;
76 uint32_t respawn_retry;
77
78 struct blob_attr *config;
79 struct uloop_process proc;
80 struct uloop_timeout timeout;
81 struct ustream_fd _stdout;
82 struct ustream_fd _stderr;
83
84 struct blob_attr *command;
85 struct blob_attr *trigger;
86 struct blobmsg_list env;
87 struct blobmsg_list data;
88 struct blobmsg_list netdev;
89 struct blobmsg_list file;
90 struct blobmsg_list limits;
91 struct blobmsg_list errors;
92 };
93
94 void instance_start(struct service_instance *in);
95 void instance_stop(struct service_instance *in, bool halt);
96 void instance_update(struct service_instance *in, struct service_instance *in_new);
97 void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
98 void instance_free(struct service_instance *in);
99 void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
100
101 #endif