logpipe error handling patch

From: <ccx_at_webprojekty.cz>
Date: Sat, 26 Jul 2014 10:44:18 +0200 (CEST)

Hello, I wrote a patch for how broken filedescriptors when creating child
are handled. Currently only the child dies, leaving non-working instance of
runsv in place. My patch makes it kill the parent so the runsv process can
be respawned properly when it gets to the state in which it can't produce
working children.

This should fix the behaviour described in
Message-id: CAN_+VLUtc+JBAATN55b2o6G8tmH4Y8OKLCf-yA6maBt+c1=gmA_at_mail.gmail.com
http://blog.gmane.org/gmane.comp.sysutils.supervision.general/month=20130301
and
Message-id: Pine.LNX.4.64.1008161622390.20374_at_e-smith.charlieb.ott.istop.com
http://blog.gmane.org/gmane.comp.sysutils.supervision.general/month=20100801

--- runsv.c.orig 2014-07-24 16:17:43.087191947 +0200
+++ runsv.c 2014-07-24 18:27:29.720588407 +0200
_at_@ -62,6 +62,11 @@
 
 void usage () { strerr_die4x(1, "usage: ", progname, USAGE, "\n"); }
 
+void fatal_child(char *m) {
+ strerr_warn5("runsv ", dir, ": fatal: ", m, ": ", &strerr_sys);
+ kill(getppid(), SIGTERM);
+ _exit(111);
+}
 void fatal(char *m) {
   strerr_die5sys(111, "runsv ", dir, ": fatal: ", m, ": ");
 }
_at_@ -289,14 +294,14 @@
     if (haslog) {
       if (s->islog) {
         if (fd_copy(0, logpipe[0]) == -1)
- fatal("unable to setup filedescriptor for ./log/run");
+ fatal_child("unable to setup filedescriptor for ./log/run");
         close(logpipe[1]);
         if (chdir("./log") == -1)
           fatal("unable to change directory to ./log");
       }
       else {
         if (fd_copy(1, logpipe[1]) == -1)
- fatal("unable to setup filedescriptor for ./run");
+ fatal_child("unable to setup filedescriptor for ./run");
         close(logpipe[0]);
       }
     }
Received on Sat Jul 26 2014 - 08:44:18 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:44:18 UTC