1
0
Fork 0
mirror of https://github.com/pygos/init.git synced 2024-11-22 11:19:45 +01:00

Remove pid fron cron serives, reap children in signal handler

Signed-off-by: David Oberhollenzer <david.oberhollenzer@tele2.at>
This commit is contained in:
David Oberhollenzer 2018-09-21 18:08:48 +02:00
parent a191a7cc18
commit e171f88865
4 changed files with 9 additions and 16 deletions

View file

@ -79,6 +79,8 @@ static void runjobs(void)
static void sighandler(int signo) static void sighandler(int signo)
{ {
pid_t pid;
switch (signo) { switch (signo) {
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
@ -87,6 +89,10 @@ static void sighandler(int signo)
case SIGHUP: case SIGHUP:
rescan = 1; rescan = 1;
break; break;
case SIGCHLD:
while ((pid = waitpid(-1, NULL, WNOHANG)) != -1)
;
break;
} }
} }
@ -94,15 +100,14 @@ int main(void)
{ {
struct timespec stime; struct timespec stime;
struct sigaction act; struct sigaction act;
crontab_t *t;
int timeout; int timeout;
pid_t pid;
memset(&act, 0, sizeof(act)); memset(&act, 0, sizeof(act));
act.sa_handler = sighandler; act.sa_handler = sighandler;
sigaction(SIGINT, &act, NULL); sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL); sigaction(SIGTERM, &act, NULL);
sigaction(SIGHUP, &act, NULL); sigaction(SIGHUP, &act, NULL);
sigaction(SIGCHLD, &act, NULL);
while (run) { while (run) {
if (rescan == 1) { if (rescan == 1) {
@ -124,15 +129,6 @@ int main(void)
break; break;
} }
} }
while ((pid = waitpid(-1, NULL, WNOHANG)) != -1) {
for (t = jobs; t != NULL; t = t->next) {
if (t->pid == pid) {
t->pid = -1;
break;
}
}
}
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;

View file

@ -33,10 +33,8 @@ int runjob(crontab_t *tab)
return -1; return -1;
} }
if (pid != 0) { if (pid != 0)
tab->pid = pid;
return 0; return 0;
}
/* XXX: inside the child process */ /* XXX: inside the child process */
memset(&act, 0, sizeof(act)); memset(&act, 0, sizeof(act));
@ -44,6 +42,7 @@ int runjob(crontab_t *tab)
sigaction(SIGINT, &act, NULL); sigaction(SIGINT, &act, NULL);
sigaction(SIGTERM, &act, NULL); sigaction(SIGTERM, &act, NULL);
sigaction(SIGHUP, &act, NULL); sigaction(SIGHUP, &act, NULL);
sigaction(SIGCHLD, &act, NULL);
if (setup_tty(tab->ctty, tab->tty_truncate)) if (setup_tty(tab->ctty, tab->tty_truncate))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View file

@ -489,7 +489,6 @@ crontab_t *rdcron(int dirfd, const char *filename)
goto out; goto out;
} }
cron->pid = -1;
cron->minute = 0xFFFFFFFFFFFFFFFFUL; cron->minute = 0xFFFFFFFFFFFFFFFFUL;
cron->hour = 0xFFFFFFFF; cron->hour = 0xFFFFFFFF;
cron->dayofmonth = 0xFFFFFFFF; cron->dayofmonth = 0xFFFFFFFF;

View file

@ -32,7 +32,6 @@ typedef struct crontab_t {
uid_t uid; uid_t uid;
gid_t gid; gid_t gid;
pid_t pid;
uint64_t minute; uint64_t minute;
uint32_t hour; uint32_t hour;