summaryrefslogtreecommitdiffstats
path: root/ctdb/server/ctdb_daemon.c
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2014-06-30 17:22:14 +1000
committerAmitay Isaacs <amitay@samba.org>2014-07-05 06:51:13 +0200
commite454e5ac9c8ed77409d9fa4463b2b29985e67e10 (patch)
tree731c954d959694768be0a25bfa84c72ca06888d6 /ctdb/server/ctdb_daemon.c
parentc7b3be97d96ee5a17bb88dceec42c57e9bf69c5d (diff)
downloadsamba-e454e5ac9c8ed77409d9fa4463b2b29985e67e10.tar.gz
samba-e454e5ac9c8ed77409d9fa4463b2b29985e67e10.tar.xz
samba-e454e5ac9c8ed77409d9fa4463b2b29985e67e10.zip
ctdb-daemon: Check PID in ctdb_remove_pidfile(), not unreliable flag
If something unexpectedly uses fork() then an exiting child will remove the PID file while the main daemon is still running. The real test is whether the current process has the PID of the main CTDB daemon, which is the process that calls setsid(). This could be done using getpgrp() instead. At the moment the eventscript handler harmlessly calls setpgid() - harmless because the atexit() handlers are cleared upon exec(). However, it is possible that process groups will be used more in future so it is probably better to rely on the session ID. Thanks to Sumit Bose <sbose@redhat.com> for the idea. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb/server/ctdb_daemon.c')
-rw-r--r--ctdb/server/ctdb_daemon.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c
index eb42e18886..448e7dcc98 100644
--- a/ctdb/server/ctdb_daemon.c
+++ b/ctdb/server/ctdb_daemon.c
@@ -1109,7 +1109,8 @@ static void ctdb_tevent_trace(enum tevent_trace_point tp,
static void ctdb_remove_pidfile(void)
{
- if (ctdbd_pidfile != NULL && !ctdb_is_child_process()) {
+ /* Only the main ctdbd's PID matches the SID */
+ if (ctdbd_pidfile != NULL && getsid(0) == getpid()) {
if (unlink(ctdbd_pidfile) == 0) {
DEBUG(DEBUG_NOTICE, ("Removed PID file %s\n",
ctdbd_pidfile));