Logging: when we log stdout/stderr messages from eventscripts to the system log...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 25 Aug 2011 23:39:25 +0000 (09:39 +1000)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Thu, 25 Aug 2011 23:39:25 +0000 (09:39 +1000)
CQ S1028412

include/ctdb_private.h
server/ctdb_logging.c
server/eventscript.c

index 37f8a7344ad1ede654aeecf58f82964f556b6794..6d3e91e37bfc4a9d133d943fc7205432bdec0785 100644 (file)
@@ -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);
 
index 27b990ef6768b09967b4e8139f0bbf19f9d1f5d8..2ef2a0b1fb8480e9a3bc1e27fd983bc8409f5e3e 100644 (file)
@@ -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;
 
index eb5c2da2fe7f0197f7bec7560c861c25c0f27258..c01fbad69ed8129efd53937f224ca590fd5fb4f5 100644 (file)
@@ -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]);