------------------------------------------------------------
revno: 751
revision-id:[EMAIL PROTECTED]
parent: [EMAIL PROTECTED]
committer: Andrew Tridgell <[EMAIL PROTECTED]>
branch nick: tridge.stable
timestamp: Thu 2008-01-10 08:04:54 +1100
message:
  add a max runtime switch to ctdb tool
modified:
  tools/ctdb.c                   
ctdb_control.c-20070426122705-9ehj1l5lu2gn9kuj-1
=== modified file 'tools/ctdb.c'
--- a/tools/ctdb.c      2008-01-08 12:02:43 +0000
+++ b/tools/ctdb.c      2008-01-09 21:04:54 +0000
@@ -33,6 +33,7 @@
        int timelimit;
        uint32_t pnn;
        int machinereadable;
+       int maxruntime;
 } options;
 
 #define TIMELIMIT() timeval_current_ofs(options.timelimit, 0)
@@ -1094,6 +1095,12 @@
 }
 
 
+static void ctdb_alarm(int sig)
+{
+       printf("Maximum runtime exceeded - exiting\n");
+       _exit(0);
+}
+
 /*
   main program
 */
@@ -1107,6 +1114,7 @@
                { "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 @@
        setlinebuf(stdout);
        
        /* set some defaults */
+       options.maxruntime = 0;
        options.timelimit = 3;
        options.pnn = CTDB_CURRENT_NODE;
 
@@ -1145,6 +1154,11 @@
                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) {

Reply via email to