mirror of
https://github.com/pygos/init.git
synced 2024-11-22 19:19:47 +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:
parent
0d985a7430
commit
9f9807d4d3
5 changed files with 28 additions and 67 deletions
|
@ -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_SOURCES += initd/status.c initd/supervisor.c initd/initsock.c
|
||||||
init_CPPFLAGS = $(AM_CPPFLAGS)
|
init_CPPFLAGS = $(AM_CPPFLAGS)
|
||||||
init_CFLAGS = $(AM_CFLAGS)
|
init_CFLAGS = $(AM_CFLAGS)
|
||||||
|
|
23
initd/init.h
23
initd/init.h
|
@ -77,29 +77,6 @@ void supervisor_start(int id);
|
||||||
|
|
||||||
void supervisor_stop(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 **********/
|
/********** initsock.c **********/
|
||||||
|
|
||||||
int init_socket_create(void);
|
int init_socket_create(void);
|
||||||
|
|
23
initd/main.c
23
initd/main.c
|
@ -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 main(void)
|
||||||
{
|
{
|
||||||
int i, ret, count;
|
int i, ret, count;
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
pid_t runsvc(service_t *svc)
|
pid_t runsvc(service_t *svc)
|
||||||
{
|
{
|
||||||
char *argv[4], *envp[1];
|
char *argv[4], *envp[1];
|
||||||
|
sigset_t mask;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
|
|
||||||
argv[0] = (char *)RUNSVCBIN;
|
argv[0] = (char *)RUNSVCBIN;
|
||||||
|
@ -25,7 +26,9 @@ pid_t runsvc(service_t *svc)
|
||||||
perror("fork");
|
perror("fork");
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
sigreset();
|
sigemptyset(&mask);
|
||||||
|
sigprocmask(SIG_SETMASK, &mask, NULL);
|
||||||
|
|
||||||
execve(argv[0], argv, envp);
|
execve(argv[0], argv, envp);
|
||||||
perror(argv[0]);
|
perror(argv[0]);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
Loading…
Reference in a new issue