[SCM] CTDB repository - branch master updated - ctdb-1.10-425-g392363c

Ronnie Sahlberg sahlberg at samba.org
Thu Aug 25 18:00:41 MDT 2011


The branch, master has been updated
       via  392363c04185f47a826fc6ed95038342be2150bf (commit)
      from  750a31cf95c356a0ee071967537eb615dce35845 (commit)

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


- Log -----------------------------------------------------------------
commit 392363c04185f47a826fc6ed95038342be2150bf
Author: Ronnie Sahlberg <ronniesahlberg at gmail.com>
Date:   Fri Aug 26 09:39:25 2011 +1000

    Logging:  when we log stdout/stderr messages from eventscripts to the system log, prefix every line of output with the name of the eventscript.
    
    CQ S1028412

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

Summary of changes:
 include/ctdb_private.h |    1 +
 server/ctdb_logging.c  |   11 +++++++++--
 server/eventscript.c   |    2 +-
 3 files changed, 11 insertions(+), 3 deletions(-)


Changeset truncated at 500 lines:

diff --git a/include/ctdb_private.h b/include/ctdb_private.h
index 37f8a73..6d3e91e 100644
--- a/include/ctdb_private.h
+++ b/include/ctdb_private.h
@@ -1352,6 +1352,7 @@ int32_t ctdb_control_clear_log(struct ctdb_context *ctdb);
 
 struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
 					      struct ctdb_context *ctdb,
+					      const char *log_prefix,
 					      void (*logfn)(const char *, uint16_t, void *),
 					      void *logfn_private, pid_t *pid);
 
diff --git a/server/ctdb_logging.c b/server/ctdb_logging.c
index 27b990e..2ef2a0b 100644
--- a/server/ctdb_logging.c
+++ b/server/ctdb_logging.c
@@ -163,6 +163,7 @@ int start_syslog_daemon(struct ctdb_context *ctdb)
 
 struct ctdb_log_state {
 	struct ctdb_context *ctdb;
+	const char *prefix;
 	int fd, pfd;
 	char buf[1024];
 	uint16_t buf_used;
@@ -366,7 +367,11 @@ static void write_to_log(struct ctdb_log_state *log,
 			 const char *buf, unsigned int len)
 {
 	if (script_log_level <= LogLevel) {
-		do_debug("%*.*s\n", len, len, buf);
+		if (log != NULL && log->prefix != NULL) {
+			do_debug("%s: %*.*s\n", log->prefix, len, len, buf);
+		} else {
+			do_debug("%*.*s\n", len, len, buf);
+		}
 		/* log it in the eventsystem as well */
 		if (log->logfn)
 			log->logfn(log->buf, len, log->logfn_private);
@@ -386,7 +391,7 @@ static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
 	if (!(flags & EVENT_FD_READ)) {
 		return;
 	}
-	
+
 	n = read(log->pfd, &log->buf[log->buf_used],
 		 sizeof(log->buf) - log->buf_used);
 	if (n > 0) {
@@ -436,6 +441,7 @@ static int log_context_destructor(struct ctdb_log_state *log)
 */
 struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
 					      struct ctdb_context *ctdb,
+					      const char *log_prefix,
 					      void (*logfn)(const char *, uint16_t, void *),
 					      void *logfn_private, pid_t *pid)
 {
@@ -446,6 +452,7 @@ struct ctdb_log_state *ctdb_fork_with_logging(TALLOC_CTX *mem_ctx,
 	log = talloc_zero(mem_ctx, struct ctdb_log_state);
 	CTDB_NO_MEMORY_NULL(ctdb, log);
 	log->ctdb = ctdb;
+	log->prefix = log_prefix;
 	log->logfn = logfn;
 	log->logfn_private = (void *)logfn_private;
 
diff --git a/server/eventscript.c b/server/eventscript.c
index eb5c2da..c01fbad 100644
--- a/server/eventscript.c
+++ b/server/eventscript.c
@@ -382,7 +382,7 @@ static int fork_child_for_script(struct ctdb_context *ctdb,
 		return -errno;
 	}
 
- 	if (!ctdb_fork_with_logging(state, ctdb, log_event_script_output,
+ 	if (!ctdb_fork_with_logging(state, ctdb, current->name, log_event_script_output,
 				    state, &state->child)) {
 		r = -errno;
 		close(state->fd[0]);


-- 
CTDB repository


More information about the samba-cvs mailing list