From dee80360fd287a2a4dbe484023600eca47710898 Mon Sep 17 00:00:00 2001 From: Martin Schwenke Date: Fri, 5 Aug 2016 14:17:01 +1000 Subject: [PATCH] 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 Reviewed-by: Amitay Isaacs (cherry picked from commit 1f942ec36c98127e25d7aa9b8370a4f621b9d362) --- ctdb/doc/cluster_mutex_helper.txt | 3 ++- ctdb/server/ctdb_mutex_fcntl_helper.c | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ctdb/doc/cluster_mutex_helper.txt b/ctdb/doc/cluster_mutex_helper.txt index 0fc3a50..20c8eb2 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 06c2205..87358be 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); -- 2.8.1