start the syslog child a little later, after we have forked and detached from the...
authorRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 30 Oct 2009 08:39:11 +0000 (19:39 +1100)
committerRonnie Sahlberg <ronniesahlberg@gmail.com>
Fri, 30 Oct 2009 08:39:11 +0000 (19:39 +1100)
include/ctdb.h
server/ctdb_daemon.c
server/ctdb_logging.c
server/ctdbd.c

index 1ede66205a249b518a2675107aa382d2e7f43177..db4c5ccc4bfd2bf8cea225a4c44f334a011f1bd6 100644 (file)
@@ -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
index 54a47c1d88229ff2965bdd0aaaaa200e8cc91440..ab0437164e521292220eb1ff71b89bab21d0ead3 100644 (file)
@@ -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);
index 556a2489adce32371b331a5aed4d4936b25e06a2..a404cdf02e1792cff3f8dbb3c72d7c0077939f05 100644 (file)
@@ -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);
 }
index d33a4092dd543cf8ac3e1ab20771f838ed508b84..8647aad189284c956e5c474f3e146217b1a7c50d 100644 (file)
@@ -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);
 }