1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-06-26 21:10:13 +02:00

Minor cleanup

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-04-07 15:35:19 +02:00
parent 43274e3910
commit b81668e045
3 changed files with 20 additions and 52 deletions

View file

@ -38,17 +38,14 @@ static void handle_exited(service_t *svc)
{
switch (svc->type) {
case SVC_RESPAWN:
if (target == TGT_REBOOT || target == TGT_SHUTDOWN) {
delsvc(svc);
if (target == TGT_REBOOT || target == TGT_SHUTDOWN)
break;
}
if (svc->rspwn_limit > 0) {
svc->rspwn_limit -= 1;
if (svc->rspwn_limit == 0) {
print_status(svc->desc, STATUS_FAIL, false);
delsvc(svc);
break;
}
}
@ -56,20 +53,18 @@ static void handle_exited(service_t *svc)
svc->pid = runlst(svc->exec, svc->ctty);
if (svc->pid == -1) {
print_status(svc->desc, STATUS_FAIL, false);
delsvc(svc);
break;
}
svclist_add(svc);
break;
return;
case SVC_ONCE:
print_status(svc->desc,
svc->status == EXIT_SUCCESS ?
STATUS_OK : STATUS_FAIL, false);
/* fall-through */
default:
delsvc(svc);
break;
}
delsvc(svc);
}
static void handle_signal(int sigfd)
@ -86,11 +81,7 @@ static void handle_signal(int sigfd)
switch (info.ssi_signo) {
case SIGCHLD:
for (;;) {
pid = waitpid(-1, &status, WNOHANG);
if (pid <= 0)
break;
while ((pid = waitpid(-1, &status, WNOHANG)) > 0) {
status = WIFEXITED(status) ? WEXITSTATUS(status) :
EXIT_FAILURE;
@ -132,9 +123,6 @@ static void start_runlevel(int level)
true);
delsvc(svc);
} else {
if (svc->type == SVC_RESPAWN)
print_status(svc->desc, STATUS_STARTED, false);
svc->pid = runlst(svc->exec, svc->ctty);
if (svc->pid == -1) {
print_status(svc->desc, STATUS_FAIL, false);
@ -142,6 +130,9 @@ static void start_runlevel(int level)
continue;
}
if (svc->type == SVC_RESPAWN)
print_status(svc->desc, STATUS_STARTED, false);
svclist_add(svc);
}
}

View file

@ -30,25 +30,14 @@
int mksock(void)
{
struct sockaddr_un un;
int fd, flags;
int fd;
fd = socket(AF_UNIX, SOCK_STREAM, 0);
fd = socket(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
if (fd < 0) {
perror("socket");
return -1;
}
flags = fcntl(fd, F_GETFD);
if (flags == -1) {
perror("socket F_GETFD");
goto fail;
}
if (fcntl(fd, F_SETFD, flags | O_CLOEXEC)) {
perror("socket F_SETFD");
goto fail;
}
memset(&un, 0, sizeof(un));
un.sun_family = AF_UNIX;

View file

@ -16,26 +16,15 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <sys/wait.h>
#include <signal.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <fcntl.h>
#include "init.h"
extern char **environ;
static NORETURN void split_and_exec(exec_t *cmd)
{
execve(cmd->argv[0], cmd->argv, environ);
perror(cmd->argv[0]);
exit(EXIT_FAILURE);
}
static int child_setup(const char *ctty)
{
sigset_t mask;
@ -77,7 +66,9 @@ int runlst_wait(exec_t *list, const char *ctty)
if (pid == 0) {
if (child_setup(ctty))
exit(EXIT_FAILURE);
split_and_exec(list);
execve(list->argv[0], list->argv, environ);
perror(list->argv[0]);
exit(EXIT_FAILURE);
}
if (pid == -1) {
@ -101,21 +92,18 @@ int runlst_wait(exec_t *list, const char *ctty)
pid_t runlst(exec_t *list, const char *ctty)
{
int status;
pid_t pid;
pid = fork();
pid_t pid = fork();
if (pid == 0) {
if (child_setup(ctty))
exit(EXIT_FAILURE);
if (list->next != NULL) {
status = runlst_wait(list, NULL);
exit(status);
} else {
split_and_exec(list);
}
if (list->next != NULL)
exit(runlst_wait(list, NULL));
execve(list->argv[0], list->argv, environ);
perror(list->argv[0]);
exit(EXIT_FAILURE);
}
if (pid == -1)