[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r4134 - in trunk/OpenDNSSEC/signer/src: . daemon

Matthijs Mekking matthijs at nlnetlabs.nl
Mon Oct 25 12:09:08 CEST 2010


Author: matthijs
Date: 2010-10-25 12:09:08 +0200 (Mon, 25 Oct 2010)
New Revision: 4134

Modified:
   trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c
   trunk/OpenDNSSEC/signer/src/daemon/engine.c
   trunk/OpenDNSSEC/signer/src/ods-signer.c
Log:
ods-signer running (ticket 187)



Modified: trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c	2010-10-25 10:08:28 UTC (rev 4133)
+++ trunk/OpenDNSSEC/signer/src/daemon/cmdhandler.c	2010-10-25 10:09:08 UTC (rev 4134)
@@ -503,6 +503,21 @@
 
 
 /**
+ * Handle the 'running' command.
+ *
+ */
+static void
+cmdhandler_handle_cmd_running(int sockfd)
+{
+    char buf[ODS_SE_MAXLINE];
+
+    (void)snprintf(buf, ODS_SE_MAXLINE, "Engine running.\n");
+    se_writen(sockfd, buf, strlen(buf));
+    return;
+}
+
+
+/**
  * Handle the 'verbosity' command.
  *
  */
@@ -642,6 +657,9 @@
         } else if (n == 6 && strncmp(buf, "reload", n) == 0) {
             se_log_debug("reload command");
             cmdhandler_handle_cmd_reload(sockfd, cmdc);
+        } else if (n == 7 && strncmp(buf, "running", n) == 0) {
+            se_log_debug("running command");
+            cmdhandler_handle_cmd_running(sockfd);
         } else if (n >= 9 && strncmp(buf, "verbosity", 9) == 0) {
             se_log_debug("verbosity command");
             if (buf[9] == '\0') {

Modified: trunk/OpenDNSSEC/signer/src/daemon/engine.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/daemon/engine.c	2010-10-25 10:08:28 UTC (rev 4133)
+++ trunk/OpenDNSSEC/signer/src/daemon/engine.c	2010-10-25 10:09:08 UTC (rev 4134)
@@ -481,23 +481,7 @@
         }
     }
     engine->pid = getpid();
-    /* make common with enforcer */
-    if (write_pidfile(engine->config->pid_filename, engine->pid) == -1) {
-        se_log_error("setup failed: unable to write pid file");
-        cmdhandler_cleanup(engine->cmdhandler);
-        engine->cmdhandler = NULL;
-        return 1;
-    }
-    se_log_verbose("running as pid %lu", (unsigned long) engine->pid);
 
-    /* start command handler */
-    if (engine_start_cmdhandler(engine) != 0) {
-        se_log_error("setup failed: unable to start command handler");
-        cmdhandler_cleanup(engine->cmdhandler);
-        engine->cmdhandler = NULL;
-        return 1;
-    }
-
     /* catch signals */
     signal_set_engine(engine);
     action.sa_handler = signal_handler;
@@ -511,9 +495,28 @@
     if (result != HSM_OK) {
         se_log_error("setup failed: error initializing libhsm (errno %i)",
             result);
+        cmdhandler_cleanup(engine->cmdhandler);
+        engine->cmdhandler = NULL;
         return 1;
     }
 
+    /* start command handler */
+    if (engine_start_cmdhandler(engine) != 0) {
+        se_log_error("setup failed: unable to start command handler");
+        cmdhandler_cleanup(engine->cmdhandler);
+        engine->cmdhandler = NULL;
+        return 1;
+    }
+
+    /* make common with enforcer */
+    if (write_pidfile(engine->config->pid_filename, engine->pid) == -1) {
+        se_log_error("setup failed: unable to write pid file");
+        cmdhandler_cleanup(engine->cmdhandler);
+        engine->cmdhandler = NULL;
+        return 1;
+    }
+    se_log_verbose("running as pid %lu", (unsigned long) engine->pid);
+
     /* set up the work floor */
     engine->tasklist = tasklist_create(); /* tasks */
     engine->zonelist = zonelist_create(); /* zones */

Modified: trunk/OpenDNSSEC/signer/src/ods-signer.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/ods-signer.c	2010-10-25 10:08:28 UTC (rev 4133)
+++ trunk/OpenDNSSEC/signer/src/ods-signer.c	2010-10-25 10:09:08 UTC (rev 4134)
@@ -142,6 +142,9 @@
                 if (n < 0) {
                     /* error occurred */
                     fprintf(stderr, "error: %s\n", strerror(errno));
+                    if (cmd) {
+                        se_free((void*)cmd);
+                    }
                     exit(1);
                 } else if (stdineof == 1) {
                     /* normal termination */
@@ -150,6 +153,9 @@
                     /* weird termination */
                     fprintf(stderr, "signer engine terminated "
                         "prematurely\n");
+                    if (cmd) {
+                        se_free((void*)cmd);
+                    }
                     exit(1);
                 }
             }
@@ -189,6 +195,9 @@
                 if (ret != 0) {
                     fprintf(stderr, "shutdown failed: %s\n",
                         strerror(errno));
+                    if (cmd) {
+                        se_free((void*)cmd);
+                    }
                     exit(1);
                 }
                 FD_CLR(fileno(fp), &rset);
@@ -207,6 +216,9 @@
                 if (ret != 0) {
                     fprintf(stderr, "shutdown failed: %s\n",
                         strerror(errno));
+                    if (cmd) {
+                        se_free((void*)cmd);
+                    }
                     exit(1);
                 }
                 FD_CLR(fileno(fp), &rset);
@@ -240,6 +252,9 @@
     if (sockfd <= 0) {
         fprintf(stderr, "Unable to connect to engine. "
             "socket() failed: %s\n", strerror(errno));
+        if (cmd) {
+            se_free((void*)cmd);
+        }
         exit(1);
     }
 
@@ -258,9 +273,17 @@
             return;
         }
 
-        fprintf(stderr, "Unable to connect to engine: "
-            "connect() failed: %s\n", strerror(errno));
+        if (cmd && se_strcmp(cmd, "running\n") == 0) {
+            fprintf(stderr, "Engine not running.\n");
+        } else {
+            fprintf(stderr, "Unable to connect to engine: "
+                "connect() failed: %s\n", strerror(errno));
+        }
+
         close(sockfd);
+        if (cmd) {
+            se_free((void*)cmd);
+        }
         exit(1);
     }
 




More information about the Opendnssec-commits mailing list