#include "runmodes.h"
#include "util-daemon.h"
#include "util-debug.h"
+#include "conf.h"
#ifndef OS_WIN32
exit(EXIT_FAILURE);
} else if (pid == 0) {
/* Child continues here */
+ char *daemondir;
umask(027);
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();
# 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.