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