diff --git a/src/runsv.c b/src/runsv.c index ecf4677..991e211 100644 --- a/src/runsv.c +++ b/src/runsv.c @@ -57,7 +57,7 @@ struct svdir svd[2]; int sigterm =0; int haslog =0; int pidchanged =1; -int logpipe[2]; +int logpipe[2] = {0,0}; char *dir; void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); } @@ -89,6 +89,15 @@ void s_term() { write(selfpipe[1], "", 1); /* XXX */ } +void setup_logpipe(void) { + if(logpipe[0]) + return; + if (pipe(logpipe) == -1) + fatal("unable to create log pipe"); + coe(logpipe[0]); + coe(logpipe[1]); +} + void update_status(struct svdir *s) { unsigned long l; int fd; @@ -280,6 +289,7 @@ void startservice(struct svdir *s) { } if (s->pid != 0) stopservice(s); /* should never happen */ + if (haslog) setup_logpipe(); while ((p =fork()) == -1) { warn("unable to fork, sleeping"); sleep(5); @@ -428,10 +438,7 @@ int main(int argc, char **argv) { taia_now(&svd[1].start); if (stat("log/down", &s) != -1) svd[1].want =W_DOWN; - if (pipe(logpipe) == -1) - fatal("unable to create log pipe"); - coe(logpipe[0]); - coe(logpipe[1]); + setup_logpipe(); } } @@ -599,7 +606,9 @@ int main(int argc, char **argv) { /* stopservice(&svd[1]); */ update_status(&svd[1]); if (close(logpipe[1]) == -1) warn("unable to close logpipe[1]"); + logpipe[1] = 0; if (close(logpipe[0]) == -1) warn("unable to close logpipe[0]"); + logpipe[0] = 0; } } }