aboutsummaryrefslogtreecommitdiff
path: root/initd/init.h
blob: deb6da9b616a4f9c1923ae56461f958916ac7b62 (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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* SPDX-License-Identifier: ISC */
#ifndef INIT_H
#define INIT_H

#include <sys/types.h>
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <endian.h>
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <poll.h>

#include <linux/reboot.h>
#include <sys/reboot.h>
#include <sys/prctl.h>
#include <stdbool.h>
#include <signal.h>

#include "service.h"
#include "config.h"
#include "util.h"

#define ENVFILE ETCPATH "/initd.env"
#define PROCFDDIR "/proc/self/fd"

/* service run time data */

enum {
	STATE_OFF,
	STATE_RUNNING,
	STATE_QUEUED,
	STATE_COMPLETED,
	STATE_FAILED,
};

typedef struct {
	service_t *svc;		/* the underlying service description */
	int state;		/* what STATE_* the service is currently in */
	int rspwn_count;	/* services respawn counter */
	int status;		/* if exited, process exit status */
	pid_t pid;		/* if still running, the pid */
} svc_run_data_t;

/********** runsvc.c **********/

/*
	Invoke the runsvc command to execute the comands of a service.

	Returns the pid of the child process containing the runsvc instance.
*/
pid_t runsvc(service_t *svc);

/********** config.c **********/

/* load persistent configuration from disk */
int config_load(void);

svc_run_data_t *config_rt_data_by_pid(pid_t pid);

/*
  Get the next service that is waiting to be launched. Returns NULL if
  the queue is empty.
 */
svc_run_data_t *config_dequeue(void);

/*
  Transition to a different target, if possible in the current state.

  The transition may be ignored, e.g. if we are currently in the reboot
  or shutdown target.
 */
void config_set_target(int tgt);

/* get the current run time target from the configuration manager */
int config_get_current_target(void);

/*
  Find out if the current target is completed, i.e. there are no more services
  left in the queue and no active single shot services.
 */
bool config_is_current_target_complete(void);

/* Ask whether we should respawn services in the current target */
bool config_should_respawn(void);

/* notify the configuration manager that a single shot service started */
void config_singleshot_started(void);

/* notify the configuration manager that a single shot service terminated */
void config_singleshot_terminated(void);

/********** print_status.c **********/

void print_status(const svc_run_data_t *rt);

#endif /* INIT_H */