The branch, master has been updated via 331fb7f ctdb-recoverd: No need to set ctdbd_pid again via 1677dd4 ctdb-daemon: Remove ctdbd_pid global variable via e454e5a ctdb-daemon: Check PID in ctdb_remove_pidfile(), not unreliable flag via c7b3be9 ctdb-daemon: Exit if setting the session ID fails from 085c7a7 smbd: do_lock_cancel does not need "blr" anymore
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 331fb7fc64c0a4f64c28001a1644a2a6a923be75 Author: Amitay Isaacs <ami...@gmail.com> Date: Thu Jul 3 13:47:07 2014 +1000 ctdb-recoverd: No need to set ctdbd_pid again This is unnecessary since ctdbd_pid is set very early in the code before creating any other processes including recovery daemon. Signed-off-by: Amitay Isaacs <ami...@gmail.com> Reviewed-by: Martin Schwenke <mar...@meltin.net> Autobuild-User(master): Amitay Isaacs <ami...@samba.org> Autobuild-Date(master): Sat Jul 5 09:20:27 CEST 2014 on sn-devel-104 commit 1677dd499c571081a8ddaf560eb3b033156e1c67 Author: Martin Schwenke <mar...@meltin.net> Date: Thu Jul 3 12:29:46 2014 +1000 ctdb-daemon: Remove ctdbd_pid global variable This duplicates ctdb->ctdbd_pid. Thanks to Sumit Bose <sb...@redhat.com> for the suggestion. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit e454e5ac9c8ed77409d9fa4463b2b29985e67e10 Author: Martin Schwenke <mar...@meltin.net> Date: Mon Jun 30 17:22:14 2014 +1000 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 <sb...@redhat.com> for the idea. Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> commit c7b3be97d96ee5a17bb88dceec42c57e9bf69c5d Author: Martin Schwenke <mar...@meltin.net> Date: Thu Jul 3 12:12:20 2014 +1000 ctdb-daemon: Exit if setting the session ID fails Currently ctdbd_wrapper depends on the session ID. Very soon PID file removal will too. :-) Signed-off-by: Martin Schwenke <mar...@meltin.net> Reviewed-by: Amitay Isaacs <ami...@gmail.com> ----------------------------------------------------------------------- Summary of changes: ctdb/client/ctdb_client.c | 2 -- ctdb/common/ctdb_fork.c | 8 -------- ctdb/include/ctdb_private.h | 5 ----- ctdb/server/ctdb_daemon.c | 20 ++++++++++++-------- ctdb/server/ctdb_recoverd.c | 2 -- 5 files changed, 12 insertions(+), 25 deletions(-) Changeset truncated at 500 lines: diff --git a/ctdb/client/ctdb_client.c b/ctdb/client/ctdb_client.c index 73c593f..c8ab1cd 100644 --- a/ctdb/client/ctdb_client.c +++ b/ctdb/client/ctdb_client.c @@ -29,8 +29,6 @@ #include "../include/ctdb_private.h" #include "lib/util/dlinklist.h" -pid_t ctdbd_pid; - /* allocate a packet for use in client<->daemon communication */ diff --git a/ctdb/common/ctdb_fork.c b/ctdb/common/ctdb_fork.c index aa9bcf0..d7eef76 100644 --- a/ctdb/common/ctdb_fork.c +++ b/ctdb/common/ctdb_fork.c @@ -23,11 +23,8 @@ #include "../include/ctdb_private.h" #include "../common/rb_tree.h" -static bool is_child = false; - void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...) { - is_child = true; if (child_name_fmt != NULL) { va_list ap; char *t; @@ -40,11 +37,6 @@ void ctdb_set_child_info(TALLOC_CTX *mem_ctx, const char *child_name_fmt, ...) } } -bool ctdb_is_child_process(void) -{ - return is_child; -} - void ctdb_track_child(struct ctdb_context *ctdb, pid_t pid) { char *process; diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 0481e43..de7880b 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -38,11 +38,6 @@ struct srvid_request_data { }; /* - * pid of the ctdbd daemon - */ -extern pid_t ctdbd_pid; - -/* a tcp connection description also used by tcp_add and tcp_remove controls */ diff --git a/ctdb/server/ctdb_daemon.c b/ctdb/server/ctdb_daemon.c index 391f244..da2f42e 100644 --- a/ctdb/server/ctdb_daemon.c +++ b/ctdb/server/ctdb_daemon.c @@ -60,7 +60,7 @@ static void ctdb_time_tick(struct event_context *ev, struct timed_event *te, { struct ctdb_context *ctdb = talloc_get_type(private_data, struct ctdb_context); - if (getpid() != ctdbd_pid) { + if (getpid() != ctdb->ctdbd_pid) { return; } @@ -1070,8 +1070,10 @@ static void ctdb_tevent_trace(enum tevent_trace_point tp, { struct timeval diff; struct timeval now; + struct ctdb_context *ctdb = + talloc_get_type(private_data, struct ctdb_context); - if (getpid() != ctdbd_pid) { + if (getpid() != ctdb->ctdbd_pid) { return; } @@ -1109,7 +1111,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)); @@ -1162,7 +1165,9 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog) tdb_reopen_all(false); if (do_fork) { - setsid(); + if (setsid() == -1) { + ctdb_die(ctdb, "Failed to setsid()\n"); + } close(0); if (open("/dev/null", O_RDONLY) != 0) { DEBUG(DEBUG_ALERT,(__location__ " Failed to setup stdin on /dev/null\n")); @@ -1171,10 +1176,9 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog) } ignore_signal(SIGPIPE); - ctdbd_pid = getpid(); - ctdb->ctdbd_pid = ctdbd_pid; + ctdb->ctdbd_pid = getpid(); DEBUG(DEBUG_ERR, ("Starting CTDBD (Version %s) as PID: %u\n", - CTDB_VERSION_STRING, ctdbd_pid)); + CTDB_VERSION_STRING, ctdb->ctdbd_pid)); ctdb_create_pidfile(ctdb->ctdbd_pid); /* Make sure we log something when the daemon terminates. @@ -1197,7 +1201,7 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog) ctdb->ev = event_context_init(NULL); tevent_loop_allow_nesting(ctdb->ev); - tevent_set_trace_callback(ctdb->ev, ctdb_tevent_trace, NULL); + tevent_set_trace_callback(ctdb->ev, ctdb_tevent_trace, ctdb); ret = ctdb_init_tevent_logging(ctdb); if (ret != 0) { DEBUG(DEBUG_ALERT,("Failed to initialize TEVENT logging\n")); diff --git a/ctdb/server/ctdb_recoverd.c b/ctdb/server/ctdb_recoverd.c index 7758635..cfba29d 100644 --- a/ctdb/server/ctdb_recoverd.c +++ b/ctdb/server/ctdb_recoverd.c @@ -4283,8 +4283,6 @@ int ctdb_start_recoverd(struct ctdb_context *ctdb) return -1; } - ctdb->ctdbd_pid = getpid(); - ctdb->recoverd_pid = ctdb_fork_no_free_ringbuffer(ctdb); if (ctdb->recoverd_pid == -1) { return -1; -- Samba Shared Repository