summaryrefslogtreecommitdiff
path: root/lib/include/service.h
blob: eb92d8556a00b2fb93b260432f013ec28be39ce2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#ifndef SERVICE_H
#define SERVICE_H

#include <sys/types.h>

enum {
	SVC_ONCE = 0,
	SVC_WAIT,
	SVC_RESPAWN,
};

enum {
	TGT_BOOT = 0,
	TGT_SHUTDOWN,
	TGT_REBOOT,
	TGT_CAD,

	TGT_MAX
};

typedef struct service_t {
	int type;		/* SVC_* service type */
	int target;		/* TGT_* service target */
	char *name;		/* canonical service name */
	char *desc;		/* description string */
	char **exec;		/* command lines to execute */
	size_t num_exec;	/* number of command lines */
	char *ctty;		/* controlling tty or log file */

	char **before;
	size_t num_before;
	char **after;
	size_t num_after;

	pid_t pid;
	int status;		/* process exit status */

	struct service_t *next;
} service_t;

typedef struct {
	service_t *targets[TGT_MAX];
} service_list_t;

/*
	Read a service from a file.
*/
service_t *rdsrv(int dirfd, const char *filename);

void delsrv(service_t *srv);

int srvscan(const char *directory, service_list_t *list);

void del_srv_list(service_list_t *list);

/*
	Sort a list of services by dependencies.
*/
service_t *srv_tsort(service_t *list);

#endif /* SERVICE_H */