Skip to content

Instantly share code, notes, and snippets.

@rem7

rem7/wait.patch

Created Nov 6, 2018
Embed
What would you like to do?
runit
diff --git a/src/runsvdir.c b/src/runsvdir.c
index 07c1d8e..5197bec 100644
--- a/src/runsvdir.c
+++ b/src/runsvdir.c
@@ -2,6 +2,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <signal.h>
+#include <sys/wait.h>
#include "direntry.h"
#include "strerr.h"
#include "error.h"
@@ -53,6 +54,7 @@ void warn3x(char *m1, char *m2, char *m3) {
}
void s_term() { exitsoon =1; }
void s_hangup() { exitsoon =2; }
+void s_usr1() { exitsoon =3; }
void runsv(int no, char *name) {
int pid;
@@ -70,6 +72,7 @@ void runsv(int no, char *name) {
prog[2] =0;
sig_uncatch(sig_hangup);
sig_uncatch(sig_term);
+ sig_uncatch(sig_usr1);
if (pgrp) setsid();
pathexec_run(*prog, prog, (const char* const*)environ);
fatal("unable to start runsv ", name);
@@ -183,6 +186,7 @@ int main(int argc, char **argv) {
sig_catch(sig_term, s_term);
sig_catch(sig_hangup, s_hangup);
+ sig_catch(sig_usr1, s_usr1);
svdir =*argv++;
if (argv && *argv) {
rplog =*argv;
@@ -272,13 +276,22 @@ int main(int argc, char **argv) {
rplog[i -1] =rplog[i];
rplog[rploglen -1] =ch;
}
-
+
+ int status =0;
switch(exitsoon) {
case 1:
_exit(0);
case 2:
for (i =0; i < svnum; i++) if (sv[i].pid) kill(sv[i].pid, SIGTERM);
_exit(111);
+ case 3:
+ for (i =0; i < svnum; i++) {
+ if (sv[i].pid) {
+ kill(sv[i].pid, SIGTERM);
+ waitpid(sv[i].pid,&status,0);
+ }
+ };
+ _exit(112);
}
}
/* not reached */
diff --git a/src/sig.c b/src/sig.c
index 423d18e..cc6d155 100644
--- a/src/sig.c
+++ b/src/sig.c
@@ -10,6 +10,7 @@ int sig_hangup = SIGHUP;
int sig_int = SIGINT;
int sig_pipe = SIGPIPE;
int sig_term = SIGTERM;
+int sig_usr1 = SIGUSR1;
void (*sig_defaulthandler)() = SIG_DFL;
void (*sig_ignorehandler)() = SIG_IGN;
diff --git a/src/sig.h b/src/sig.h
index 2a3c780..fd24ffc 100644
--- a/src/sig.h
+++ b/src/sig.h
@@ -10,6 +10,7 @@ extern int sig_hangup;
extern int sig_int;
extern int sig_pipe;
extern int sig_term;
+extern int sig_usr1;
extern void (*sig_defaulthandler)();
extern void (*sig_ignorehandler)();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment