jail: cgroups: replace wrongly used assert()
[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 bool console;
36 char *name;
37 char *hostname;
38 char *pidfile;
39 struct blobmsg_list mount;
40 int argc;
41 };
42
43 typedef enum instance_watchdog {
44 INSTANCE_WATCHDOG_MODE_DISABLED,
45 INSTANCE_WATCHDOG_MODE_PASSIVE,
46 INSTANCE_WATCHDOG_MODE_ACTIVE,
47 __INSTANCE_WATCHDOG_MODE_MAX,
48 } instance_watchdog_mode_t;
49
50 struct watchdog {
51 instance_watchdog_mode_t mode;
52 uint32_t freq;
53 struct uloop_timeout timeout;
54 };
55
56 struct service_instance {
57 struct vlist_node node;
58 struct service *srv;
59 const char *name;
60
61 int8_t nice;
62 bool valid;
63
64 char *user;
65 uid_t uid;
66 gid_t pw_gid;
67 char *group;
68 gid_t gr_gid;
69
70 bool halt;
71 bool restart;
72 bool respawn;
73 int respawn_count;
74 int reload_signal;
75 struct timespec start;
76
77 bool trace;
78 bool has_jail;
79 bool require_jail;
80 bool immediately;
81 bool no_new_privs;
82 struct jail jail;
83 char *seccomp;
84 char *capabilities;
85 char *pidfile;
86 char *extroot;
87 char *overlaydir;
88 char *tmpoverlaysize;
89 char *bundle;
90 int syslog_facility;
91 int exit_code;
92
93 uint32_t term_timeout;
94 uint32_t respawn_timeout;
95 uint32_t respawn_threshold;
96 uint32_t respawn_retry;
97
98 struct blob_attr *config;
99 struct uloop_process proc;
100 struct uloop_timeout timeout;
101 struct ustream_fd _stdout;
102 struct ustream_fd _stderr;
103 struct ustream_fd console;
104 struct ustream_fd console_client;
105
106 struct blob_attr *command;
107 struct blob_attr *trigger;
108 struct blobmsg_list env;
109 struct blobmsg_list data;
110 struct blobmsg_list netdev;
111 struct blobmsg_list file;
112 struct blobmsg_list limits;
113 struct blobmsg_list errors;
114
115 struct watchdog watchdog;
116 };
117
118 void instance_start(struct service_instance *in);
119 void instance_stop(struct service_instance *in, bool halt);
120 void instance_update(struct service_instance *in, struct service_instance *in_new);
121 void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
122 void instance_free(struct service_instance *in);
123 void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
124
125 #endif