[SCM] CTDB repository - branch 2.5 updated - ctdb-2.5.3-71-g9455d80

Amitay Isaacs amitay at samba.org
Mon Jul 7 19:14:48 MDT 2014


The branch, 2.5 has been updated
       via  9455d80a14588cce58ca494725a4eb031ae34e14 (commit)
       via  093e219716b2a3027a06176dd2385051657fc101 (commit)
       via  27fd360aa3575afa24f27901e5be6d2f9cbbfb99 (commit)
       via  3460c619ed998bcdba2df630a8daaada65fb2b0b (commit)
      from  00534e6ca28d8a2e47118338ca1cda4d3bd79486 (commit)

http://gitweb.samba.org/?p=ctdb.git;a=shortlog;h=2.5


- Log -----------------------------------------------------------------
commit 9455d80a14588cce58ca494725a4eb031ae34e14
Author: Amitay Isaacs <amitay at gmail.com>
Date:   Thu Jul 3 13:47:07 2014 +1000

    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 <amitay at gmail.com>
    Reviewed-by: Martin Schwenke <martin at meltin.net>
    
    Autobuild-User(master): Amitay Isaacs <amitay at samba.org>
    Autobuild-Date(master): Sat Jul  5 09:20:27 CEST 2014 on sn-devel-104
    
    (Imported from commit 331fb7fc64c0a4f64c28001a1644a2a6a923be75)

commit 093e219716b2a3027a06176dd2385051657fc101
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Jul 3 12:29:46 2014 +1000

    daemon: Remove ctdbd_pid global variable
    
    This duplicates ctdb->ctdbd_pid.
    
    Thanks to Sumit Bose <sbose at redhat.com> for the suggestion.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    (Imported from commit 1677dd499c571081a8ddaf560eb3b033156e1c67)

commit 27fd360aa3575afa24f27901e5be6d2f9cbbfb99
Author: Martin Schwenke <martin at meltin.net>
Date:   Mon Jun 30 17:22:14 2014 +1000

    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 at redhat.com> for the idea.
    
    Signed-off-by: Martin Schwenke <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    (Imported from commit e454e5ac9c8ed77409d9fa4463b2b29985e67e10)

commit 3460c619ed998bcdba2df630a8daaada65fb2b0b
Author: Martin Schwenke <martin at meltin.net>
Date:   Thu Jul 3 12:12:20 2014 +1000

    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 <martin at meltin.net>
    Reviewed-by: Amitay Isaacs <amitay at gmail.com>
    
    (Imported from commit c7b3be97d96ee5a17bb88dceec42c57e9bf69c5d)

-----------------------------------------------------------------------

Summary of changes:
 client/ctdb_client.c   |    2 --
 common/ctdb_fork.c     |    8 --------
 include/ctdb_private.h |    5 -----
 server/ctdb_daemon.c   |   20 ++++++++++++--------
 server/ctdb_recoverd.c |    2 --
 5 files changed, 12 insertions(+), 25 deletions(-)


Changeset truncated at 500 lines:

diff --git a/client/ctdb_client.c b/client/ctdb_client.c
index 73c593f..c8ab1cd 100644
--- a/client/ctdb_client.c
+++ b/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/common/ctdb_fork.c b/common/ctdb_fork.c
index aa9bcf0..d7eef76 100644
--- a/common/ctdb_fork.c
+++ b/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/include/ctdb_private.h b/include/ctdb_private.h
index 0481e43..de7880b 100644
--- a/include/ctdb_private.h
+++ b/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/server/ctdb_daemon.c b/server/ctdb_daemon.c
index 391f244..da2f42e 100644
--- a/server/ctdb_daemon.c
+++ b/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/server/ctdb_recoverd.c b/server/ctdb_recoverd.c
index 7758635..cfba29d 100644
--- a/server/ctdb_recoverd.c
+++ b/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;


-- 
CTDB repository


More information about the samba-cvs mailing list