2018-03-24 22:31:05 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018 - David Oberhollenzer
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
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>
|
|
|
|
#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
|
|
|
|
|
|
|
#include "service.h"
|
|
|
|
#include "telinit.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
|
|
|
|
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 */
|
|
|
|
|