summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRonnie Sahlberg <ronniesahlberg@gmail.com>2011-08-26 09:39:25 +1000
committerRonnie Sahlberg <ronniesahlberg@gmail.com>2011-08-26 09:39:25 +1000
commit2902203900943fa81d42276149471670fa3d6504 (patch)
tree8e87b8aeb4c4b5b70f8b1365e86d16982b83934c
parent66925122991f22eff28c1b0c71c2506722fe33ec (diff)
downloadsamba-2902203900943fa81d42276149471670fa3d6504.tar.gz
samba-2902203900943fa81d42276149471670fa3d6504.tar.xz
samba-2902203900943fa81d42276149471670fa3d6504.zip
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 (This used to be ctdb commit 392363c04185f47a826fc6ed95038342be2150bf)
-rw-r--r--ctdb/include/ctdb_private.h1
-rw-r--r--ctdb/server/ctdb_logging.c11
-rw-r--r--ctdb/server/eventscript.c2
3 files changed, 11 insertions, 3 deletions
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 37f8a7344a..6d3e91e37b 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/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/ctdb/server/ctdb_logging.c b/ctdb/server/ctdb_logging.c
index 27b990ef67..2ef2a0b1fb 100644
--- a/ctdb/server/ctdb_logging.c
+++ b/ctdb/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/ctdb/server/eventscript.c b/ctdb/server/eventscript.c
index eb5c2da2fe..c01fbad69e 100644
--- a/ctdb/server/eventscript.c
+++ b/ctdb/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]);