jail: add support for launching extroot containers
[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 char *name;
34 char *hostname;
35 char *extroot;
36 struct blobmsg_list mount;
37 int argc;
38 };
39
40 struct service_instance {
41 struct vlist_node node;
42 struct service *srv;
43 const char *name;
44
45 int8_t nice;
46 bool valid;
47
48 char *user;
49 uid_t uid;
50 gid_t pw_gid;
51 char *group;
52 gid_t gr_gid;
53
54 bool halt;
55 bool restart;
56 bool respawn;
57 int respawn_count;
58 int reload_signal;
59 struct timespec start;
60
61 bool trace;
62 bool has_jail;
63 bool require_jail;
64 bool no_new_privs;
65 struct jail jail;
66 char *seccomp;
67 char *pidfile;
68 int syslog_facility;
69 int exit_code;
70
71 uint32_t term_timeout;
72 uint32_t respawn_timeout;
73 uint32_t respawn_threshold;
74 uint32_t respawn_retry;
75
76 struct blob_attr *config;
77 struct uloop_process proc;
78 struct uloop_timeout timeout;
79 struct ustream_fd _stdout;
80 struct ustream_fd _stderr;
81
82 struct blob_attr *command;
83 struct blob_attr *trigger;
84 struct blobmsg_list env;
85 struct blobmsg_list data;
86 struct blobmsg_list netdev;
87 struct blobmsg_list file;
88 struct blobmsg_list limits;
89 struct blobmsg_list errors;
90 };
91
92 void instance_start(struct service_instance *in);
93 void instance_stop(struct service_instance *in, bool halt);
94 void instance_update(struct service_instance *in, struct service_instance *in_new);
95 void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
96 void instance_free(struct service_instance *in);
97 void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
98
99 #endif