Skip to content

Allow PID file to be disabled at compile-time #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ find_package(Libsystemd)
if (Libsystemd_FOUND)
option(ENABLE_SYSTEMD "Enable systemd support." ON)
endif()
option(ENABLE_PID_FILE "Enable PID file support." ON)
if (ENABLE_PID_FILE)
add_compile_definitions(-DENABLE_PID_FILE)
endif ()
option(ENABLE_GETDNS_STATIC_LINK "Link GetDNS statically." ON)
if (ENABLE_GETDNS_STATIC_LINK)
set(GETDNS_STATIC ON)
Expand Down
1 change: 1 addition & 0 deletions cmake/include/cmakeconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

#cmakedefine SERVER_DEBUG 1

#cmakedefine ENABLE_PID_FILE 1
#cmakedefine ENABLE_SYSTEMD 1

#cmakedefine STUBBYCONFDIR "@STUBBYCONFDIR@"
Expand Down
6 changes: 5 additions & 1 deletion src/stubby.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

#if defined(ENABLE_WINDOWS_SERVICE)
#include "windowsservice.h"
#else
#elif defined(ENABLE_PID_FILE)
#define STUBBYPIDFILE RUNSTATEDIR"/stubby.pid"
#endif

Expand Down Expand Up @@ -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 {
Expand All @@ -225,13 +226,15 @@ main(int argc, char **argv)
} while(0);
if (fh)
(void) fclose(fh);
#endif

pid = fork();
if (pid == -1) {
perror("Could not fork of stubby daemon\n");
r = GETDNS_RETURN_GENERIC_ERROR;

} else if (pid) {
#if defined(ENABLE_PID_FILE)
fh = fopen(STUBBYPIDFILE, "w");
if (fh) {
fprintf(fh, "%d", (int)pid);
Expand All @@ -242,6 +245,7 @@ main(int argc, char **argv)
strerror(errno));
exit(EXIT_FAILURE);
}
#endif
} else {
#ifdef SIGPIPE
(void)signal(SIGPIPE, SIG_IGN);
Expand Down