ctdbd: Debug locks by default with override from enviroment variable
authorMartin Schwenke <martin@meltin.net>
Tue, 1 Oct 2013 05:13:29 +0000 (15:13 +1000)
committerMartin Schwenke <martin@meltin.net>
Tue, 22 Oct 2013 04:37:54 +0000 (15:37 +1100)
Default is debug_locks.sh, relative to CTDB_BASE.

Signed-off-by: Martin Schwenke <martin@meltin.net>
server/ctdb_lock.c

index 1d27a444b6613d71c0ea5d5e94dcf15406eb7e9e..fc437b0fa7f8b950a32ee2f7a37499baa32e134f 100644 (file)
@@ -495,7 +495,7 @@ static void ctdb_lock_timeout_handler(struct tevent_context *ev,
                                    struct timeval current_time,
                                    void *private_data)
 {
-       const char *cmd = getenv("CTDB_DEBUG_LOCKS");
+       static const char * debug_locks = NULL;
        struct lock_context *lock_ctx;
        struct ctdb_context *ctdb;
        pid_t pid;
@@ -515,12 +515,24 @@ static void ctdb_lock_timeout_handler(struct tevent_context *ev,
                       timeval_elapsed(&lock_ctx->start_time)));
        }
 
-       /* fire a child process to find the blocking process */
-       if (cmd != NULL) {
+       /* Fire a child process to find the blocking process. */
+       if (debug_locks == NULL) {
+               debug_locks = getenv("CTDB_DEBUG_LOCKS");
+               if (debug_locks == NULL) {
+                       debug_locks = talloc_asprintf(ctdb,
+                                                     "%s/debug_locks.sh",
+                                                     getenv("CTDB_BASE"));
+               }
+       }
+       if (debug_locks != NULL) {
                pid = fork();
                if (pid == 0) {
-                       execl(cmd, cmd, NULL);
+                       execl(debug_locks, debug_locks, NULL);
                }
+       } else {
+               DEBUG(DEBUG_WARNING,
+                     (__location__
+                      " Unable to setup lock debugging - no memory?\n"));
        }
 
        /* reset the timeout timer */