From 729cc5307f0e7e1a95a9cb67df10b3b6707e09b0 Mon Sep 17 00:00:00 2001 From: Joachim Nilsson Date: Sat, 7 Jan 2017 12:55:26 +0100 Subject: [PATCH] pidfile: Add support for absolute path The OpenBSD version of pidfile() makes sure to place all PID files in the same, canonical, location: _PATH_VARRUN. On Linux, however, some disitributions prefer to place PID files in a sub-directory under the canonical location: _PATH_VARRUN + __progname/ ... This patch adds support for creating PID files in any location. If the PID file name argument starts with a '/', the function assumes the rest of the string is the full PATH to the PID file. Signed-off-by: Joachim Nilsson --- pidfile.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pidfile.c b/pidfile.c index 7fe7ae5..b0b0de8 100644 --- a/pidfile.c +++ b/pidfile.c @@ -75,8 +75,13 @@ pidfile(const char *basename) atexit_already = 1; } - if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1) - return (-1); + if (basename[0] != '/') { + if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1) + return (-1); + } else { + if (asprintf(&pidfile_path, "%s", basename) == -1) + return (-1); + } if ((f = fopen(pidfile_path, "w")) == NULL) { save_errno = errno;