2018-11-23 13:13:23 +01:00
|
|
|
/* SPDX-License-Identifier: ISC */
|
2018-02-25 14:33:19 +01:00
|
|
|
#ifndef INIT_H
|
|
|
|
#define INIT_H
|
|
|
|
|
2018-08-24 16:51:15 +02:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#include <sys/socket.h>
|
2019-03-17 18:33:12 +01:00
|
|
|
#include <sys/un.h>
|
2018-08-24 16:51:15 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <poll.h>
|
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
#include <linux/reboot.h>
|
2018-04-15 13:21:34 +02:00
|
|
|
#include <sys/signalfd.h>
|
2018-02-25 14:33:19 +01:00
|
|
|
#include <sys/reboot.h>
|
2018-04-15 13:21:34 +02:00
|
|
|
#include <signal.h>
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2019-03-17 18:33:12 +01:00
|
|
|
#include "initsock.h"
|
2018-02-25 14:33:19 +01:00
|
|
|
#include "service.h"
|
|
|
|
#include "util.h"
|
|
|
|
|
2018-04-22 01:02:27 +02:00
|
|
|
#define RUNSVCBIN SCRIPTDIR "/runsvc"
|
2018-04-12 06:15:02 +02:00
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
enum {
|
|
|
|
STATUS_OK = 0,
|
|
|
|
STATUS_FAIL,
|
|
|
|
STATUS_WAIT,
|
2018-03-25 22:07:33 +02:00
|
|
|
STATUS_STARTED,
|
2018-02-25 14:33:19 +01:00
|
|
|
};
|
|
|
|
|
2018-08-24 16:51:15 +02:00
|
|
|
/********** main.c **********/
|
|
|
|
|
|
|
|
void target_completed(int target);
|
|
|
|
|
2018-04-22 01:02:27 +02:00
|
|
|
/********** runsvc.c **********/
|
2018-03-24 22:31:05 +01:00
|
|
|
|
|
|
|
/*
|
2018-04-22 01:02:27 +02:00
|
|
|
Invoke the runsvc command to execute the comands of a service.
|
2018-03-24 22:31:05 +01:00
|
|
|
|
2018-04-22 01:02:27 +02:00
|
|
|
Returns the pid of the child process containing the runsvc instance.
|
2018-03-24 22:31:05 +01:00
|
|
|
*/
|
2018-04-22 01:02:27 +02:00
|
|
|
pid_t runsvc(service_t *svc);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-03-24 22:31:05 +01:00
|
|
|
/********** status.c **********/
|
|
|
|
|
|
|
|
/*
|
2018-03-25 22:07:33 +02:00
|
|
|
Print a status message. Type is either STATUS_OK, STATUS_FAIL,
|
|
|
|
STATUS_WAIT or STATUS_STARTED.
|
2018-03-24 22:31:05 +01:00
|
|
|
|
|
|
|
A new-line is appended to the mssage, UNLESS type is STATUS_WAIT.
|
|
|
|
|
|
|
|
If update is true, print a carriage return first to overwrite the
|
|
|
|
current line (e.g. after a STATUS_WAIT message).
|
|
|
|
*/
|
2018-02-25 14:33:19 +01:00
|
|
|
void print_status(const char *msg, int type, bool update);
|
|
|
|
|
2018-08-24 16:51:15 +02:00
|
|
|
/********** supervisor.c **********/
|
2018-03-24 22:31:05 +01:00
|
|
|
|
2018-08-24 16:51:15 +02:00
|
|
|
void supervisor_handle_exited(pid_t pid, int status);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-08-24 16:51:15 +02:00
|
|
|
void supervisor_set_target(int next);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2018-08-24 16:51:15 +02:00
|
|
|
void supervisor_init(void);
|
2018-03-24 22:31:05 +01:00
|
|
|
|
2018-08-24 16:51:15 +02:00
|
|
|
bool supervisor_process_queues(void);
|
2018-02-25 14:33:19 +01:00
|
|
|
|
2019-03-18 14:08:17 +01:00
|
|
|
void supervisor_answer_status_request(int fd, const void *dest_addr,
|
2019-03-27 17:48:13 +01:00
|
|
|
size_t addrlen, E_SERVICE_STATE filter);
|
2019-03-18 14:08:17 +01:00
|
|
|
|
2018-04-15 13:21:34 +02:00
|
|
|
/********** signal_<platform>.c **********/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Setup signal handling. Returns -1 on error, a file descriptor on
|
|
|
|
success.
|
|
|
|
|
|
|
|
The returned file descriptor can be polled and becomes readable
|
|
|
|
when a signal arrives. Reading from it returns a signalfd_siginfo
|
|
|
|
structure.
|
|
|
|
|
|
|
|
The returned file descriptor has the close on exec flag set.
|
|
|
|
|
|
|
|
The kernel is also told to send us SIGINT signals if a user presses
|
|
|
|
the local equivalent of CTRL+ALT+DEL.
|
|
|
|
*/
|
|
|
|
int sigsetup(void);
|
|
|
|
|
|
|
|
/*
|
|
|
|
Undo everything that sigsetup() changed about signal handling and
|
|
|
|
restore the default.
|
|
|
|
*/
|
|
|
|
void sigreset(void);
|
|
|
|
|
2018-02-25 14:33:19 +01:00
|
|
|
#endif /* INIT_H */
|