ctdb-mutex: Avoid corner case where helper is already reparented to init
authorMartin Schwenke <martin@meltin.net>
Fri, 5 Aug 2016 04:17:01 +0000 (14:17 +1000)
committerMartin Schwenke <martins@samba.org>
Mon, 8 Aug 2016 06:17:34 +0000 (08:17 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12113

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
ctdb/doc/cluster_mutex_helper.txt
ctdb/server/ctdb_mutex_fcntl_helper.c

index 0fc3a50dc7cf218551e8b2773289e759d23d73fd..20c8eb2b51dcc2e4dfbc5fa23f2e4fddea5294a5 100644 (file)
@@ -64,7 +64,8 @@ Valid status codes are:
 If a 0 status code is sent then it the helper should periodically
 check if the (original) parent processes still exists while awaiting
 termination.  If the parent process disappears then the helper should
-release the mutex and exit.  This avoids stale mutexes.
+release the mutex and exit.  This avoids stale mutexes.  Note that a
+helper should never wait for parent process ID 1!
 
 If a non-0 status code is sent then the helper can exit immediately.
 However, if the helper does not exit then it must terminate if it
index 06c2205d4969526365cc47885b1c14b9dcdb157f..87358beb234d12db997bb44e421b673c98ced808 100644 (file)
@@ -82,6 +82,19 @@ int main(int argc, char *argv[])
        }
 
        ppid = getppid();
+
+       if (ppid == 1) {
+               /* The original parent is gone and the process has
+                * been reparented to init.  This can happen if the
+                * helper is started just as the parent is killed
+                * during shutdown.  The error message doesn't need to
+                * be stellar, since there won't be anything around to
+                * capture and log it...
+                */
+               fprintf(stderr, "%s: PPID == 1\n", progname);
+               exit(1);
+       }
+
        file = argv[1];
 
        result = fcntl_lock(file, &fd);