1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-12-22 15:20:49 +01:00

cleanup: initd: simplify and merge linux specific code into main.c

Targetting anything else than Linux isn't really relevant. All
other systems ($BSD and other Unices) are a closed ecosystem
where kernel & userspace are developed together. They don't need
something like a third party init system, so compatibillity can
be largely ignored.

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2020-03-31 13:09:04 +02:00
parent 0d985a7430
commit 9f9807d4d3
5 changed files with 28 additions and 67 deletions

View file

@ -1,4 +1,4 @@
init_SOURCES = initd/main.c initd/init.h initd/signal_linux.c initd/runsvc.c
init_SOURCES = initd/main.c initd/init.h initd/runsvc.c
init_SOURCES += initd/status.c initd/supervisor.c initd/initsock.c
init_CPPFLAGS = $(AM_CPPFLAGS)
init_CFLAGS = $(AM_CFLAGS)

View file

@ -77,29 +77,6 @@ void supervisor_start(int id);
void supervisor_stop(int id);
/********** 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);
/********** initsock.c **********/
int init_socket_create(void);

View file

@ -96,6 +96,29 @@ void target_completed(int target)
}
}
static int sigsetup(void)
{
sigset_t mask;
int sfd;
sigfillset(&mask);
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
perror("sigprocmask");
return -1;
}
sfd = signalfd(-1, &mask, SFD_CLOEXEC);
if (sfd == -1) {
perror("signalfd");
return -1;
}
if (reboot(LINUX_REBOOT_CMD_CAD_OFF))
perror("cannot disable CTRL+ALT+DEL");
return sfd;
}
int main(void)
{
int i, ret, count;

View file

@ -10,6 +10,7 @@
pid_t runsvc(service_t *svc)
{
char *argv[4], *envp[1];
sigset_t mask;
pid_t pid;
argv[0] = (char *)RUNSVCBIN;
@ -25,7 +26,9 @@ pid_t runsvc(service_t *svc)
perror("fork");
if (pid == 0) {
sigreset();
sigemptyset(&mask);
sigprocmask(SIG_SETMASK, &mask, NULL);
execve(argv[0], argv, envp);
perror(argv[0]);
exit(EXIT_FAILURE);

View file

@ -1,42 +0,0 @@
/* SPDX-License-Identifier: ISC */
#include <stdio.h>
#include "init.h"
int sigsetup(void)
{
sigset_t mask;
int sfd;
sigfillset(&mask);
if (sigprocmask(SIG_SETMASK, &mask, NULL) == -1) {
perror("sigprocmask");
return -1;
}
sigemptyset(&mask);
sigaddset(&mask, SIGCHLD);
sigaddset(&mask, SIGINT);
sigaddset(&mask, SIGTERM);
sigaddset(&mask, SIGUSR1);
sigaddset(&mask, SIGHUP);
sfd = signalfd(-1, &mask, SFD_CLOEXEC);
if (sfd == -1) {
perror("signalfd");
return -1;
}
if (reboot(LINUX_REBOOT_CMD_CAD_OFF))
perror("cannot disable CTRL+ALT+DEL");
return sfd;
}
void sigreset(void)
{
sigset_t mask;
sigemptyset(&mask);
sigprocmask(SIG_SETMASK, &mask, NULL);
}