summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2016-08-05 14:17:01 +1000
committerStefan Metzmacher <metze@samba.org>2016-08-10 11:24:36 +0200
commitfe1ca7a68f10f739e33521f022a8efa3cb987853 (patch)
tree4f19757ec308e10925831068f3b6c827333964af
parent00d2d4b9e45ce0a73680dbaecc223cb66f30a06d (diff)
downloadsamba-fe1ca7a68f10f739e33521f022a8efa3cb987853.tar.gz
ctdb-mutex: Avoid corner case where helper is already reparented to init
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> (cherry picked from commit 1f942ec36c98127e25d7aa9b8370a4f621b9d362)
-rw-r--r--ctdb/doc/cluster_mutex_helper.txt3
-rw-r--r--ctdb/server/ctdb_mutex_fcntl_helper.c13
2 files changed, 15 insertions, 1 deletions
diff --git a/ctdb/doc/cluster_mutex_helper.txt b/ctdb/doc/cluster_mutex_helper.txt
index 0fc3a50dc7c..20c8eb2b51d 100644
--- a/ctdb/doc/cluster_mutex_helper.txt
+++ b/ctdb/doc/cluster_mutex_helper.txt
@@ -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
diff --git a/ctdb/server/ctdb_mutex_fcntl_helper.c b/ctdb/server/ctdb_mutex_fcntl_helper.c
index 06c2205d496..87358beb234 100644
--- a/ctdb/server/ctdb_mutex_fcntl_helper.c
+++ b/ctdb/server/ctdb_mutex_fcntl_helper.c
@@ -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);