Skip to content

Commit 9bfe54f

Browse files
committed
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 <[email protected]>
1 parent 960e7f6 commit 9bfe54f

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/pidfile.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <paths.h>
4646
#include <stdio.h>
4747
#include <stdlib.h>
48+
#include <string.h>
4849
#include <unistd.h>
4950

5051
#ifndef pidfile
@@ -93,7 +94,10 @@ int pidfile(const char *basename)
9394
}
9495

9596
if (basename[0] != '/') {
96-
if (asprintf(&pidfile_path, "%s%s.pid", __pidfile_path, basename) == -1)
97+
size_t len = strlen(__pidfile_path);
98+
int slash = __pidfile_path[len > 0 ? len - 1 : 0] != '/';
99+
100+
if (asprintf(&pidfile_path, "%s%s%s.pid", __pidfile_path, slash ? "/" : "", basename) == -1)
97101
return (-1);
98102
} else {
99103
if (asprintf(&pidfile_path, "%s", basename) == -1)

0 commit comments

Comments
 (0)