[SCM] CTDB repository - branch master updated - ctdb-1.0.102-12-g9ffd54b

Ronnie Sahlberg sahlberg at samba.org
Fri Oct 30 02:30:33 MDT 2009


The branch, master has been updated
       via  9ffd54b73c0d64b67e8e736d7cb54490e77ffa78 (commit)
      from  1446f4c247310e2ff2d522055bd8927d1a78d017 (commit)

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


- Log -----------------------------------------------------------------
commit 9ffd54b73c0d64b67e8e736d7cb54490e77ffa78
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Fri Oct 30 19:39:11 2009 +1100

    start the syslog child a little later, after we have forked and detached from the local shell

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

Summary of changes:
 include/ctdb.h        |    2 +-
 server/ctdb_daemon.c  |   12 +++++++++++-
 server/ctdb_logging.c |   35 ++++++++++++++++++++++-------------
 server/ctdbd.c        |    9 +--------
 4 files changed, 35 insertions(+), 23 deletions(-)


Changeset truncated at 500 lines:

diff --git a/include/ctdb.h b/include/ctdb.h
index 1ede662..db4c5cc 100644
--- a/include/ctdb.h
+++ b/include/ctdb.h
@@ -209,7 +209,7 @@ int ctdb_ip_to_nodeid(struct ctdb_context *ctdb, const char *nodeip);
   start the ctdb protocol
 */
 int ctdb_start(struct ctdb_context *ctdb);
-int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork);
+int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog);
 
 /*
   attach to a ctdb database
diff --git a/server/ctdb_daemon.c b/server/ctdb_daemon.c
index 54a47c1..ab04371 100644
--- a/server/ctdb_daemon.c
+++ b/server/ctdb_daemon.c
@@ -656,7 +656,7 @@ static void sig_child_handler(struct event_context *ev,
 /*
   start the protocol going as a daemon
 */
-int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
+int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork, bool use_syslog)
 {
 	int res, ret = -1;
 	struct fd_event *fde;
@@ -690,6 +690,8 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
 	block_signal(SIGPIPE);
 
 	ctdbd_pid = getpid();
+
+
 	DEBUG(DEBUG_ERR, ("Starting CTDBD as pid : %u\n", ctdbd_pid));
 
 	if (ctdb->do_setsched) {
@@ -772,6 +774,14 @@ int ctdb_start_daemon(struct ctdb_context *ctdb, bool do_fork)
 		DEBUG(DEBUG_CRIT,("Failed to set up signal handler for SIGCHLD\n"));
 		exit(1);
 	}
+
+	if (use_syslog) {
+		if (start_syslog_daemon(ctdb)) {
+			DEBUG(DEBUG_CRIT, ("Failed to start syslog daemon\n"));
+			exit(10);
+		}
+	}
+
 	  
 	/* go into a wait loop to allow other nodes to complete */
 	event_loop_wait(ctdb->ev);
diff --git a/server/ctdb_logging.c b/server/ctdb_logging.c
index 556a248..a404cdf 100644
--- a/server/ctdb_logging.c
+++ b/server/ctdb_logging.c
@@ -25,6 +25,7 @@
 #include "system/time.h"
 #include "system/filesys.h"
 
+static bool syslogd_is_started;
 
 struct syslog_message {
 	uint32_t level;
@@ -49,6 +50,8 @@ int start_syslog_daemon(struct ctdb_context *ctdb)
 		return -1;
 	}
 
+	syslogd_is_started = 1;
+
 	if (child != 0) {
 		return 0;
 	}
@@ -153,22 +156,28 @@ static void ctdb_syslog_log(const char *format, va_list ap)
 	msg->len   = strlen(s);
 	strcpy(msg->message, s);
 
-	syslog_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
-	if (syslog_fd == -1) {
-		printf("Failed to create syslog socket\n");
-		free(s);
-		free(msg);
-		return;
-	}
+	if (syslogd_is_started == 0) {
+		syslog(msg->level, "%s", msg->message);
+	} else {
+		syslog_fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
+		if (syslog_fd == -1) {
+			printf("Failed to create syslog socket\n");
+			free(s);
+			free(msg);
+			return;
+		}
 
-	syslog_sin.sin_family = AF_INET;
-	syslog_sin.sin_port   = htons(CTDB_PORT);
-	syslog_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);	
+		syslog_sin.sin_family = AF_INET;
+		syslog_sin.sin_port   = htons(CTDB_PORT);
+		syslog_sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK);	
+
+       
+		ret = sendto(syslog_fd, msg, len, 0, &syslog_sin, sizeof(syslog_sin));
+		/* no point in checking here since we cant log an error */
 
-	ret = sendto(syslog_fd, msg, len, 0, &syslog_sin, sizeof(syslog_sin));
-	/* no point in checking here since we cant log an error */
+		close(syslog_fd);
+	}
 
-	close(syslog_fd);
 	free(s);
 	free(msg);
 }
diff --git a/server/ctdbd.c b/server/ctdbd.c
index d33a409..8647aad 100644
--- a/server/ctdbd.c
+++ b/server/ctdbd.c
@@ -170,13 +170,6 @@ int main(int argc, const char *argv[])
 
 	ctdb = ctdb_cmdline_init(ev);
 
-	if (options.use_syslog) {
-		if (start_syslog_daemon(ctdb)) {
-			printf("Failed to start syslog daemon\n");
-			exit(10);
-		}
-	}
-
 	ctdb->start_as_disabled = options.start_as_disabled;
 	ctdb->start_as_stopped  = options.start_as_stopped;
 
@@ -329,5 +322,5 @@ int main(int argc, const char *argv[])
 	}
 
 	/* start the protocol running (as a child) */
-	return ctdb_start_daemon(ctdb, interactive?False:True);
+	return ctdb_start_daemon(ctdb, interactive?False:True, options.use_syslog);
 }


-- 
CTDB repository


More information about the samba-cvs mailing list