Use one generic routine to access /proc/cmdline
[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 "../utils/utils.h"
21
22 #define RESPAWN_ERROR   (5 * 60)
23
24 struct service_instance {
25         struct vlist_node node;
26         struct service *srv;
27         const char *name;
28
29         int8_t nice;
30         bool valid;
31
32         uid_t uid;
33         gid_t gid;
34
35         bool halt;
36         bool restart;
37         bool respawn;
38         int respawn_count;
39         struct timespec start;
40
41         uint32_t respawn_timeout;
42         uint32_t respawn_threshold;
43         uint32_t respawn_retry;
44
45         struct blob_attr *config;
46         struct uloop_process proc;
47         struct uloop_timeout timeout;
48
49         struct blob_attr *command;
50         struct blob_attr *trigger;
51         struct blobmsg_list env;
52         struct blobmsg_list data;
53         struct blobmsg_list netdev;
54         struct blobmsg_list file;
55         struct blobmsg_list limits;
56         struct blobmsg_list errors;
57 };
58
59 void instance_start(struct service_instance *in);
60 void instance_stop(struct service_instance *in);
61 bool instance_update(struct service_instance *in, struct service_instance *in_new);
62 void instance_init(struct service_instance *in, struct service *s, struct blob_attr *config);
63 void instance_free(struct service_instance *in);
64 void instance_dump(struct blob_buf *b, struct service_instance *in, int debug);
65
66 #endif