add a max runtime switch to ctdb tool
authorAndrew Tridgell <tridge@samba.org>
Wed, 9 Jan 2008 21:04:54 +0000 (08:04 +1100)
committerAndrew Tridgell <tridge@samba.org>
Wed, 9 Jan 2008 21:04:54 +0000 (08:04 +1100)
tools/ctdb.c

index bbd2f0ec28b3e9133bb50830a18f01d0d5eb8675..75b9749b61faa8a61ca217b1ac2cc68d9667cdc9 100644 (file)
@@ -33,6 +33,7 @@ static struct {
        int timelimit;
        uint32_t pnn;
        int machinereadable;
+       int maxruntime;
 } options;
 
 #define TIMELIMIT() timeval_current_ofs(options.timelimit, 0)
@@ -1094,6 +1095,12 @@ static void usage(void)
 }
 
 
+static void ctdb_alarm(int sig)
+{
+       printf("Maximum runtime exceeded - exiting\n");
+       _exit(0);
+}
+
 /*
   main program
 */
@@ -1107,6 +1114,7 @@ int main(int argc, const char *argv[])
                { "timelimit", 't', POPT_ARG_INT, &options.timelimit, 0, "timelimit", "integer" },
                { "node",      'n', POPT_ARG_STRING, &nodestring, 0, "node", "integer|all" },
                { "machinereadable", 'Y', POPT_ARG_NONE, &options.machinereadable, 0, "enable machinereadable output", NULL },
+               { "maxruntime", 'T', POPT_ARG_INT, &options.maxruntime, 0, "die if runtime exceeds this limit (in seconds)", "integer" },
                POPT_TABLEEND
        };
        int opt;
@@ -1120,6 +1128,7 @@ int main(int argc, const char *argv[])
        setlinebuf(stdout);
        
        /* set some defaults */
+       options.maxruntime = 0;
        options.timelimit = 3;
        options.pnn = CTDB_CURRENT_NODE;
 
@@ -1145,6 +1154,11 @@ int main(int argc, const char *argv[])
                usage();
        }
 
+       if (options.maxruntime != 0) {
+               signal(SIGALRM, ctdb_alarm);
+               alarm(options.maxruntime);
+       }
+
        /* setup the node number to contact */
        if (nodestring != NULL) {
                if (strcmp(nodestring, "all") == 0) {