From: Eric Leblond Date: Fri, 5 Oct 2012 07:46:18 +0000 (+0200) Subject: suricata: add daemon-directory config variable X-Git-Tag: suricata-1.4beta3~23 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a1d1abfc0563b3f8efc39d936a62a9478952316b;p=thirdparty%2Fsuricata.git suricata: add daemon-directory config variable 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. --- diff --git a/src/util-daemon.c b/src/util-daemon.c index 9215d3b73d..b922a3fe56 100644 --- a/src/util-daemon.c +++ b/src/util-daemon.c @@ -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(); diff --git a/suricata.yaml.in b/suricata.yaml.in index 34588c08bd..3df6384983 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -41,6 +41,11 @@ # 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.