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 committed 2021-03-11 21:52:44 +01:00
1 parent 30e3f5a33c
commit 5c4146cfe4
2 files changed
+9 -7

No files matched your search

+8 -7
View File
@@ -143,12 +143,13 @@ int pid_file_create(svc_t *svc)
return fclose(fp); 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); file = pid_file(svc);
if (!file)
return -1;
}
if (file[0] == '!') { if (file[0] == '!') {
not = 1; not = 1;
@@ -202,7 +203,7 @@ int pid_file_parse(svc_t *svc, char *arg)
arg += 4; arg += 4;
if ((arg[0] == '!' && arg[1] == '/') || arg[0] == '/') if ((arg[0] == '!' && arg[1] == '/') || arg[0] == '/')
return pid_realpath(svc, arg); return pid_file_set(svc, arg, 0);
if (arg[0] == '!') { if (arg[0] == '!') {
arg++; arg++;
@@ -213,12 +214,12 @@ int pid_file_parse(svc_t *svc, char *arg)
if (len > 4 && strcmp(&path[len - 4], ".pid")) if (len > 4 && strcmp(&path[len - 4], ".pid"))
strlcat(path, ".pid", sizeof(path)); strlcat(path, ".pid", sizeof(path));
return pid_realpath(svc, path); return pid_file_set(svc, path, 0);
} }
/* 'pid' arg, no argument following */ /* 'pid' arg, no argument following */
if (!strcmp(arg, "pid")) if (!strcmp(arg, "pid"))
return pid_realpath(svc, NULL); return pid_file_set(svc, NULL, 0);
return 1; 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_get_name (pid_t pid, char *name, size_t len);
char *pid_file (svc_t *svc); 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); pid_t pid_file_read (const char *fn);
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);