diff --git a/CMakeLists.txt b/CMakeLists.txt index 3202377..e08cc9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ find_package(Libsystemd) if (Libsystemd_FOUND) option(ENABLE_SYSTEMD "Enable systemd support." ON) endif() +option(ENABLE_PID_FILE "Enable PID file support." ON) option(ENABLE_GETDNS_STATIC_LINK "Link GetDNS statically." ON) if (ENABLE_GETDNS_STATIC_LINK) set(GETDNS_STATIC ON) diff --git a/cmake/include/cmakeconfig.h.in b/cmake/include/cmakeconfig.h.in index 923098e..7b1a757 100644 --- a/cmake/include/cmakeconfig.h.in +++ b/cmake/include/cmakeconfig.h.in @@ -24,6 +24,7 @@ #cmakedefine SERVER_DEBUG 1 +#cmakedefine ENABLE_PID_FILE 1 #cmakedefine ENABLE_SYSTEMD 1 #cmakedefine STUBBYCONFDIR "@STUBBYCONFDIR@" diff --git a/src/stubby.c b/src/stubby.c index 3dd7b54..0a0baf4 100644 --- a/src/stubby.c +++ b/src/stubby.c @@ -50,7 +50,7 @@ #if defined(ENABLE_WINDOWS_SERVICE) #include "windowsservice.h" -#else +#elif defined(ENABLE_PID_FILE) #define STUBBYPIDFILE RUNSTATEDIR"/stubby.pid" #endif @@ -204,6 +204,7 @@ main(int argc, char **argv) #if !defined(STUBBY_ON_WINDOWS) if (!run_in_foreground) { pid_t pid; +#if defined(ENABLE_PID_FILE) char pid_str[1024], *endptr; FILE *fh = fopen(STUBBYPIDFILE, "r"); do { @@ -225,6 +226,7 @@ main(int argc, char **argv) } while(0); if (fh) (void) fclose(fh); +#endif pid = fork(); if (pid == -1) { @@ -232,6 +234,7 @@ main(int argc, char **argv) r = GETDNS_RETURN_GENERIC_ERROR; } else if (pid) { +#if defined(ENABLE_PID_FILE) fh = fopen(STUBBYPIDFILE, "w"); if (fh) { fprintf(fh, "%d", (int)pid); @@ -242,6 +245,7 @@ main(int argc, char **argv) strerror(errno)); exit(EXIT_FAILURE); } +#endif } else { #ifdef SIGPIPE (void)signal(SIGPIPE, SIG_IGN);