rk_pidfile() should call pidfile() if HAVE_PIDFILE

This is necessary so we can use --detach in tests even on NetBSD and
OpenBSD.
This commit is contained in:
Nicolas Williams
2016-12-04 16:41:26 -06:00
parent bbaae5f43c
commit 12eb54d03f
3 changed files with 15 additions and 6 deletions

View File

@@ -163,6 +163,7 @@ roken_detach_finish(const char *dir, int daemon_child_fd)
ssize_t bytes; ssize_t bytes;
int fd; int fd;
pidfile(NULL);
if (pipefds[1] == -1 && daemon_child_fd != -1) if (pipefds[1] == -1 && daemon_child_fd != -1)
pipefds[1] = daemon_child_fd; pipefds[1] = daemon_child_fd;
if (pipefds[0] != -1) if (pipefds[0] != -1)

View File

@@ -756,14 +756,12 @@ ROKEN_LIB_FUNCTION ssize_t ROKEN_LIB_CALL
readv(int, const struct iovec *, int); readv(int, const struct iovec *, int);
#endif #endif
#ifndef HAVE_PIDFILE
#ifdef NO_PIDFILES #ifdef NO_PIDFILES
#define pidfile(x) ((void) 0) #define pidfile(x) ((void) 0)
#else #else
#define pidfile rk_pidfile #define pidfile rk_pidfile
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*); ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL pidfile (const char*);
#endif #endif
#endif
#ifndef HAVE_BSWAP64 #ifndef HAVE_BSWAP64
#define bswap64 rk_bswap64 #define bswap64 rk_bswap64

View File

@@ -76,7 +76,6 @@ pid_file_delete(char **filename)
} }
} }
#ifndef HAVE_PIDFILE
static char *pidfile_path; static char *pidfile_path;
static void static void
@@ -89,15 +88,26 @@ pidfile_cleanup(void)
ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL ROKEN_LIB_FUNCTION void ROKEN_LIB_CALL
pidfile(const char *bname) pidfile(const char *bname)
{ {
/*
* If the OS has a pidfile(), call that, but still call
* pid_file_write(). Even if both want to write the same file,
* writing it twice will still work.
*/
#ifdef HAVE_PIDFILE
#undef pidfile
pidfile(bname);
#endif
if (pidfile_path != NULL) if (pidfile_path != NULL)
return; return;
if (bname == NULL) if (bname == NULL)
bname = getprogname(); bname = getprogname();
pidfile_path = pid_file_write(bname); pidfile_path = pid_file_write(bname);
#if defined(HAVE_ATEXIT) #if defined(HAVE_ATEXIT)
atexit(pidfile_cleanup); if (pidfile_path != NULL)
atexit(pidfile_cleanup);
#elif defined(HAVE_ON_EXIT) #elif defined(HAVE_ON_EXIT)
on_exit(pidfile_cleanup); if (pidfile_path != NULL)
on_exit(pidfile_cleanup);
#endif #endif
} }
#endif