aboutsummaryrefslogtreecommitdiffstats
path: root/svcscan.c
diff options
context:
space:
mode:
Diffstat (limited to 'svcscan.c')
-rw-r--r--svcscan.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/svcscan.c b/svcscan.c
index 1de5b46..5286302 100644
--- a/svcscan.c
+++ b/svcscan.c
@@ -127,13 +127,15 @@ direxists(const char *dir)
return r;
}
-void
+int
start_supervisor(struct svc *service)
{
char *path;
if ((asprintf(&path, "%s/%s", supdir, service->dir)) == -1 ||
- path == NULL)
- err(1, "asprintf()");
+ path == NULL) {
+ perror("asprintf()");
+ return 0;
+ }
pid_t p = fork();
if (p == 0) { /* Child */
@@ -141,21 +143,24 @@ start_supervisor(struct svc *service)
super_path[1] = path;
- if (execv(super_path[0], super_path))
+ if (execv(super_path[0], super_path) == -1)
err(1, "execv()");
} else if (p > 0) { /* Parent */
service->supervisor = p;
} else {
- err(1, "fork()");
+ perror("fork()");
}
free(path);
+
+ return 1;
}
-void
+int
start_dead()
{
struct svc *np, *tmp;
+ int ret = 1;
TAILQ_FOREACH_SAFE(np, &svc_norun, entries, tmp) {
if (!direxists(np->dir)) {
@@ -163,10 +168,13 @@ start_dead()
continue;
}
- start_supervisor(np);
-
- move_run(np);
+ if (start_supervisor(np) == 0)
+ ret = 0;
+ else
+ move_run(np);
}
+
+ return ret;
}
void
@@ -431,7 +439,10 @@ main(int argc, char **argv)
err(1, "kevent()");
scan_svcdir(dir_fd);
- start_dead();
+ if (start_dead() == 0) {
+ if (kevent(kq, &evt[5], 1, NULL, 0, NULL) == -1)
+ perror("kevent()");
+ }
for (;;) {
if ((e = kevent(kq, NULL, 0, revt, 6, NULL)) == -1) {
@@ -452,7 +463,10 @@ main(int argc, char **argv)
goto end;
}
} else if (revt[i].filter == EVFILT_TIMER && revt[i].ident == 1) {
- start_dead();
+ if (start_dead() == 0) {
+ if (kevent(kq, &evt[5], 1, NULL, 0, NULL) == -1)
+ perror("kevent()");
+ }
} else {
fprintf(stderr, "Unknown event\n");
}