mirror of
https://github.com/troglobit/libite.git
synced 2026-10-11 17:02:26 +07:00
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 <troglobit@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user