TODO: server: collect the panic action outout for logging master-backtrace
authorStefan Metzmacher <metze@samba.org>
Tue, 12 Jan 2010 11:18:23 +0000 (12:18 +0100)
committerStefan Metzmacher <metze@samba.org>
Wed, 22 Dec 2010 14:59:04 +0000 (15:59 +0100)
metze

server/ctdb_logging.c

index 7e5367eab537993df257c3cdda30c6fee0086eef..ab7cf597543989b9403d24cb80b2791c6c3cb98d 100644 (file)
@@ -173,6 +173,44 @@ struct ctdb_log_state {
 
 /* we need this global to keep the DEBUG() syntax */
 static struct ctdb_log_state *log_state;
+static int log_pid;
+
+/*
+  called when log data comes in from a child process
+ */
+static void ctdb_log_handler(struct event_context *ev, struct fd_event *fde,
+                            uint16_t flags, void *private);
+
+static void ctdb_post_panic_logging(void)
+{
+       if (log_pid != getpid()) {
+               return;
+       }
+
+       if (log_state == NULL) {
+               return;
+       }
+
+       while (true) {
+               int ret;
+               int value = 0;
+
+               ret = ioctl(log_state->pfd, FIONREAD, &value);
+               if (ret == -1) {
+                       break;
+               }
+
+               if (ret != 0) {
+                       break;
+               }
+
+               if (value <= 0) {
+                       break;
+               }
+
+               ctdb_log_handler(NULL, NULL, EVENT_FD_READ, log_state);
+       }
+}
 
 /*
   syslog logging function
@@ -332,6 +370,7 @@ int ctdb_set_logfile(struct ctdb_context *ctdb, const char *logfile, bool use_sy
 
        ctdb->log->ctdb = ctdb;
        log_state = ctdb->log;
+       log_pid = getpid();
 
        if (use_syslog) {
                do_debug_v = ctdb_syslog_log;
@@ -543,6 +582,8 @@ int ctdb_set_child_logging(struct ctdb_context *ctdb)
 
        DEBUG(DEBUG_DEBUG, (__location__ " Created PIPE FD:%d for logging\n", p[0]));
 
+       post_panic_action_hook = ctdb_post_panic_logging;
+
        return 0;
 }