39 static volatile sig_atomic_t sigflag = 0;
44 static void SignalHandlerSigusr1 (
int signo)
54 static void TellWaitingParent (pid_t pid)
64 static void WaitForChild (pid_t pid)
67 SCLogDebug(
"Daemon: Parent waiting for child to be ready...");
69 while (sigflag == 0) {
70 if (waitpid(pid, &status, WNOHANG)) {
72 if (WIFEXITED(status) || WIFSIGNALED(status)) {
85 static void SetupLogging (
void)
88 int fd = open(
"/dev/null", O_RDWR);
106 signal(SIGUSR1, SignalHandlerSigusr1);
113 #if defined(OS_DARWIN) && defined(__clang__)
114 #pragma clang diagnostic push
115 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
118 #if defined(OS_DARWIN) && defined(__clang__)
119 #pragma clang diagnostic pop
125 }
else if (pid == 0) {
127 const char *daemondir;
134 if (
ConfGet(
"daemon-directory", &daemondir) == 1) {
135 if ((chdir(daemondir)) < 0) {
136 FatalError(
"Error changing to working directory");
141 if (chdir(
"/") < 0) {
142 SCLogError(
"Error changing to working directory '/'");
150 TellWaitingParent(getppid());
157 SCLogDebug(
"Parent is waiting for child to be ready");
182 SCLogError(
"ERROR: pcap offline mode cannot run as daemon");
185 SCLogError(
"ERROR: unittests cannot run as daemon");