mirror of
https://github.com/troglobit/finit.git
synced 2026-11-24 20:21:44 +00:00
Fix #100: Adjust path to COND_RECONF /var/run symlink may be missing
On systems with the new /run hierarchy the compat symlink from /var/run may be missing, or not yet be set up by bootmisc.so. This patch adds a layer of safety to the condition layer, both set and get cond ops now perform an adjustmed of the condition path if needed. Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
90249e50ef
commit
dc7039b8d8
3 files changed
+26
-5
No files matched your search
+6
-2
@@ -31,12 +31,16 @@
|
|||||||
#include "pid.h"
|
#include "pid.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
|
||||||
static int cond_set_gen(const char *path, unsigned int gen)
|
static int cond_set_gen(const char *file, unsigned int gen)
|
||||||
{
|
{
|
||||||
|
char *ptr, path[256];
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fp = fopen(path, "w");
|
/* /var/run --> /run symlink may not exist (yet) */
|
||||||
|
ptr = pid_runpath(file, path, sizeof(path));
|
||||||
|
|
||||||
|
fp = fopen(ptr, "w");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
|||||||
+6
-2
@@ -51,13 +51,17 @@ const char *cond_path(const char *name)
|
|||||||
return pid_runpath(tmp, file, sizeof(file));
|
return pid_runpath(tmp, file, sizeof(file));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int cond_get_gen(const char *path)
|
unsigned int cond_get_gen(const char *file)
|
||||||
{
|
{
|
||||||
|
char *ptr, path[256];
|
||||||
unsigned int gen;
|
unsigned int gen;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
fp = fopen(path, "r");
|
/* /var/run --> /run symlink may not exist (yet) */
|
||||||
|
ptr = pid_runpath(file, path, sizeof(path));
|
||||||
|
|
||||||
|
fp = fopen(ptr, "r");
|
||||||
if (!fp)
|
if (!fp)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,17 @@ char *pid_file (svc_t *svc);
|
|||||||
int pid_file_create (svc_t *svc);
|
int pid_file_create (svc_t *svc);
|
||||||
int pid_file_parse (svc_t *svc, char *arg);
|
int pid_file_parse (svc_t *svc, char *arg);
|
||||||
|
|
||||||
static inline char *pid_runpath(char *file, char *path, size_t len)
|
/**
|
||||||
|
* pid_runpath - Adjust /var/run --> /run path depending on system
|
||||||
|
* @file: Path to file in /run/path or /var/run/path
|
||||||
|
* @path: Pointer to buffer to write correct path
|
||||||
|
* @len: Length, in bytes, of @path buffer
|
||||||
|
*
|
||||||
|
* Returns:
|
||||||
|
* Always returns a valid pointer, which can be either @path with a /run
|
||||||
|
* or /var/run prefix to @file, or it may be @file if the prefix is OK.
|
||||||
|
*/
|
||||||
|
static inline char *pid_runpath(const char *file, char *path, size_t len)
|
||||||
{
|
{
|
||||||
static int unknown = 1;
|
static int unknown = 1;
|
||||||
static char *prefix = "/var/run";
|
static char *prefix = "/var/run";
|
||||||
@@ -45,6 +55,9 @@ static inline char *pid_runpath(char *file, char *path, size_t len)
|
|||||||
unknown = 0;
|
unknown = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strncmp(file, prefix, strlen(prefix)))
|
||||||
|
return (char *)file;
|
||||||
|
|
||||||
if (!strncmp(file, "/var/run/", 9))
|
if (!strncmp(file, "/var/run/", 9))
|
||||||
file += 9;
|
file += 9;
|
||||||
else if (!strncmp(file, "/run/", 5))
|
else if (!strncmp(file, "/run/", 5))
|
||||||
|
|||||||
Reference in new issue
Block a user