mirror of
https://github.com/troglobit/libite.git
synced 2026-10-01 05:22:34 +07:00
pidfile(): ensure prefix path ends with slash
For some builds using Buildroot, the system default _PATH_VARRUN did not
include a trailing slas '/', which cause the pidfile() function to fail.
Example:
pidfile("arg") => "/var/runarg.pid"
Since the __pidfile_path can be overridden we add a check if that prefix
path ends with '/', if not we add one in the path composition.
Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
+5
-1
@@ -45,6 +45,7 @@
|
||||
#include <paths.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef pidfile
|
||||
@@ -93,7 +94,10 @@ int pidfile(const char *basename)
|
||||
}
|
||||
|
||||
if (basename[0] != '/') {
|
||||
if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1)
|
||||
size_t len = strlen(__pidfile_path);
|
||||
int slash = __pidfile_path[len > 0 ? len - 1 : 0] != '/';
|
||||
|
||||
if (asprintf(&pidfile_path, "%s%s%s.pid", __pidfile_path, slash ? "/" : "", basename) == -1)
|
||||
return (-1);
|
||||
} else {
|
||||
if (asprintf(&pidfile_path, "%s", basename) == -1)
|
||||
|
||||
Reference in New Issue
Block a user