]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
suricata: add daemon-directory config variable
authorEric Leblond <eric@regit.org>
Fri, 5 Oct 2012 07:46:18 +0000 (09:46 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 9 Nov 2012 15:06:47 +0000 (16:06 +0100)
It is now possible to use the 'daemon-directory' configuration
variable to specify the working directory of suricata in daemon
mode. This will permit to specify the place for core and other
related files.

src/util-daemon.c
suricata.yaml.in

index 9215d3b73db9551e84c48a6a53ba322a05fc6c6c..b922a3fe563691d8e4ead73fd90c409f91191778 100644 (file)
@@ -28,6 +28,7 @@
 #include "runmodes.h"
 #include "util-daemon.h"
 #include "util-debug.h"
+#include "conf.h"
 
 #ifndef OS_WIN32
 
@@ -116,6 +117,7 @@ void Daemonize (void) {
         exit(EXIT_FAILURE);
     } else if (pid == 0) {
         /* Child continues here */
+        char *daemondir;
 
         umask(027);
 
@@ -125,15 +127,19 @@ void Daemonize (void) {
             exit(EXIT_FAILURE);
         }
 
-        /** \todo The daemon runs on the current directory, but later we'll want
-                  to allow through the configuration file (or other means) to
-                  change the running directory  */
-        /* if ((chdir(DAEMON_WORKING_DIRECTORY)) < 0) {
-            SCLogError(SC_ERR_DAEMON, "Error changing to working directory");
-            exit(EXIT_FAILURE);
-        } */
-
-        chdir("/");
+        if (ConfGet("daemon-directory", &daemondir) == 1) {
+            if ((chdir(daemondir)) < 0) {
+                SCLogError(SC_ERR_DAEMON, "Error changing to working directory");
+                exit(EXIT_FAILURE);
+            }
+        }
+#ifndef OS_WIN32
+        else {
+            if (chdir("/") < 0) {
+                SCLogError(SC_ERR_DAEMON, "Error changing to working directory '/'");
+            }
+        }
+#endif
 
         SetupLogging();
 
index 34588c08bdb2e41d24905667f6c01d40457bcd09..3df638498321ad645d47977eaa23a571ebaf4c4a 100644 (file)
 # Will use this file if no --pidfile in command options.
 #pid-file: /var/run/suricata.pid
 
+# Daemon working directory
+# Suricata will change directory to this one if provided
+# Default: "/"
+#daemon-directory: "/"
+
 # Preallocated size for packet. Default is 1514 which is the classical
 # size for pcap on ethernet. You should adjust this value to the highest
 # packet size (MTU + hardware header) on your system.