Export pid_file_set() function, useful to other subsystems as well

Rename, refactor, and export.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg
2021-03-11 21:52:44 +01:00
parent 30e3f5a33c
commit 5c4146cfe4
2 changed files with 9 additions and 7 deletions
+8 -7
View File
@@ -143,12 +143,13 @@ int pid_file_create(svc_t *svc)
return fclose(fp);
}
static int pid_realpath(svc_t *svc, char *file)
int pid_file_set(svc_t *svc, char *file, int not)
{
int not = 0;
if (!file)
if (!file) {
file = pid_file(svc);
if (!file)
return -1;
}
if (file[0] == '!') {
not = 1;
@@ -202,7 +203,7 @@ int pid_file_parse(svc_t *svc, char *arg)
arg += 4;
if ((arg[0] == '!' && arg[1] == '/') || arg[0] == '/')
return pid_realpath(svc, arg);
return pid_file_set(svc, arg, 0);
if (arg[0] == '!') {
arg++;
@@ -213,12 +214,12 @@ int pid_file_parse(svc_t *svc, char *arg)
if (len > 4 && strcmp(&path[len - 4], ".pid"))
strlcat(path, ".pid", sizeof(path));
return pid_realpath(svc, path);
return pid_file_set(svc, path, 0);
}
/* 'pid' arg, no argument following */
if (!strcmp(arg, "pid"))
return pid_realpath(svc, NULL);
return pid_file_set(svc, NULL, 0);
return 1;
}
+1
View File
@@ -32,6 +32,7 @@ int pid_alive (pid_t pid);
char *pid_get_name (pid_t pid, char *name, size_t len);
char *pid_file (svc_t *svc);
int pid_file_set (svc_t *svc, char *file, int not);
pid_t pid_file_read (const char *fn);
int pid_file_create (svc_t *svc);
int pid_file_parse (svc_t *svc, char *arg);