eventscript: make sure we die when we timeout.
authorRusty Russell <rusty@rustcorp.com.au>
Thu, 2 Sep 2010 03:14:21 +0000 (12:44 +0930)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 3 Sep 2010 01:42:56 +0000 (11:42 +1000)
Volker noticed that system() can hang on a futex: we do this inside a
signal handler simply to dump extra diagnostics when we timeout, which is
very questionable but usually works.

Add a timeout of 90 seconds: after that, commit suicide.
(This is a workaround for this branch: master does this correctly).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
server/eventscript.c

index c403772454cb50ef53839d16ffcd8ac1a8279a34..37306dbfd55d6d8ba6def9b36891832e5187fb1f 100644 (file)
@@ -34,6 +34,13 @@ static struct {
 
 static void ctdb_event_script_timeout(struct event_context *ev, struct timed_event *te, struct timeval t, void *p);
 
+static void sigalarm(int sig)
+{
+       /* all the child processes will be running in the same process group */
+       kill(-getpgrp(), SIGKILL);
+       _exit(1);
+}
+
 /*
   ctdbd sends us a SIGTERM when we should time out the current script
  */
@@ -42,6 +49,12 @@ static void sigterm(int sig)
        char tbuf[100], buf[200];
        time_t t;
 
+       /* Calling system() inside a signal handler can do strange things:
+        * it usually works, and that's enough for us: it's only for debugging.
+        * But make sure we terminate. */
+       signal(SIGTERM, sigalarm);
+       alarm(90);
+
        DEBUG(DEBUG_ERR,("Timed out running script '%s' after %.1f seconds pid :%d\n", 
                 child_state.script_running, timeval_elapsed(&child_state.start), getpid()));