Skip to content

Commit 9810be2

Browse files
Allow PID file to be disabled at compile-time
Stubby unconditionally attempts to write a PID file under the run state directory when it starts, but this directory is not always writeable by non-root or non-system account users (e.g. on Slackware). To aid with running Stubby in environments where the PID file would otherwise be unwriteable or unnecessary, allow it to be disabled at compile-time with the `ENABLE_PID_FILE` option (which remains on by default).
1 parent 9292e28 commit 9810be2

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ find_package(Libsystemd)
4747
if (Libsystemd_FOUND)
4848
option(ENABLE_SYSTEMD "Enable systemd support." ON)
4949
endif()
50+
option(ENABLE_PID_FILE "Enable PID file support." ON)
51+
if (ENABLE_PID_FILE)
52+
add_compile_definitions(-DENABLE_PID_FILE)
53+
endif ()
5054
option(ENABLE_GETDNS_STATIC_LINK "Link GetDNS statically." ON)
5155
if (ENABLE_GETDNS_STATIC_LINK)
5256
set(GETDNS_STATIC ON)

cmake/include/cmakeconfig.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#cmakedefine SERVER_DEBUG 1
2626

27+
#cmakedefine ENABLE_PID_FILE 1
2728
#cmakedefine ENABLE_SYSTEMD 1
2829

2930
#cmakedefine STUBBYCONFDIR "@STUBBYCONFDIR@"

src/stubby.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
#if defined(ENABLE_WINDOWS_SERVICE)
5252
#include "windowsservice.h"
53-
#else
53+
#elif defined(ENABLE_PID_FILE)
5454
#define STUBBYPIDFILE RUNSTATEDIR"/stubby.pid"
5555
#endif
5656

@@ -204,6 +204,7 @@ main(int argc, char **argv)
204204
#if !defined(STUBBY_ON_WINDOWS)
205205
if (!run_in_foreground) {
206206
pid_t pid;
207+
#if defined(ENABLE_PID_FILE)
207208
char pid_str[1024], *endptr;
208209
FILE *fh = fopen(STUBBYPIDFILE, "r");
209210
do {
@@ -225,13 +226,15 @@ main(int argc, char **argv)
225226
} while(0);
226227
if (fh)
227228
(void) fclose(fh);
229+
#endif
228230

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

234236
} else if (pid) {
237+
#if defined(ENABLE_PID_FILE)
235238
fh = fopen(STUBBYPIDFILE, "w");
236239
if (fh) {
237240
fprintf(fh, "%d", (int)pid);
@@ -242,6 +245,7 @@ main(int argc, char **argv)
242245
strerror(errno));
243246
exit(EXIT_FAILURE);
244247
}
248+
#endif
245249
} else {
246250
#ifdef SIGPIPE
247251
(void)signal(SIGPIPE, SIG_IGN);

0 commit comments

Comments
 (0)