Fix #212: service PID file lost after initctl reload

Clearing of the svc->pidfile was introduced in e1b87d70 for a
restriction that has now been removed.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg committed 2022-01-11 15:54:53 +01:00
1 parent 950ca953f5
commit 9a5bb46f78
3 files changed
+11 -4

No files matched your search

+3 -1
View File
@@ -84,8 +84,10 @@ static void pidfile_update_conds(char *dir, char *name, uint32_t mask)
mkcond(svc, cond, sizeof(cond)); mkcond(svc, cond, sizeof(cond));
if (mask & (IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) { if (mask & (IN_CLOSE_WRITE | IN_ATTRIB | IN_MODIFY | IN_MOVED_TO)) {
svc_started(svc); svc_started(svc);
if (!svc_has_pidfile(svc)) if (!svc_has_pidfile(svc)) {
_d("Setting %s PID file to %s", svc->name, fn);
pid_file_set(svc, fn, 1); pid_file_set(svc, fn, 1);
}
if (svc_is_forking(svc)) { if (svc_is_forking(svc)) {
pid_t pid; pid_t pid;
+8 -1
View File
@@ -717,6 +717,7 @@ static int show_status(char *arg)
while (arg && arg[0]) { while (arg && arg[0]) {
long now = jiffies(); long now = jiffies();
char uptm[42] = "N/A"; char uptm[42] = "N/A";
char *pidfn = NULL;
int exact = 0; int exact = 0;
for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) { for (svc = client_svc_iterator(1); svc; svc = client_svc_iterator(0)) {
@@ -737,6 +738,12 @@ static int show_status(char *arg)
if (quiet) if (quiet)
return svc->state != SVC_RUNNING_STATE; return svc->state != SVC_RUNNING_STATE;
pidfn = svc->pidfile;
if (pidfn[0] == '!')
pidfn++;
else if (pidfn[0] == 0)
pidfn = "none";
printf(" Status : %s\n", status(svc, 1)); printf(" Status : %s\n", status(svc, 1));
printf(" Identity : %s\n", svc_ident(svc, ident, sizeof(ident))); printf(" Identity : %s\n", svc_ident(svc, ident, sizeof(ident)));
printf("Description : %s\n", svc->desc); printf("Description : %s\n", svc->desc);
@@ -744,7 +751,7 @@ static int show_status(char *arg)
printf("Environment : %s\n", svc_environ(svc, buf, sizeof(buf))); printf("Environment : %s\n", svc_environ(svc, buf, sizeof(buf)));
printf("Condition(s): %s\n", svc_cond(svc, buf, sizeof(buf))); printf("Condition(s): %s\n", svc_cond(svc, buf, sizeof(buf)));
printf(" Command : %s\n", svc_command(svc, buf, sizeof(buf))); printf(" Command : %s\n", svc_command(svc, buf, sizeof(buf)));
printf(" PID file : %s\n", svc->pidfile); printf(" PID file : %s\n", pidfn);
printf(" PID : %d\n", svc->pid); printf(" PID : %d\n", svc->pid);
printf(" User : %s\n", svc->username); printf(" User : %s\n", svc->username);
printf(" Group : %s\n", svc->group); printf(" Group : %s\n", svc->group);
-2
View File
@@ -1310,8 +1310,6 @@ int service_register(int type, char *cfg, struct rlimit rlimit[], char *file)
svc_unblock(svc); svc_unblock(svc);
} }
/* Always clear svc PID file, for now. See TODO */
svc->pidfile[0] = 0;
/* Decode any optional pid:/optional/path/to/file.pid */ /* Decode any optional pid:/optional/path/to/file.pid */
if (pid && svc_is_daemon(svc) && pid_file_parse(svc, pid)) if (pid && svc_is_daemon(svc) && pid_file_parse(svc, pid))
_e("Invalid 'pid' argument to service: %s", pid); _e("Invalid 'pid' argument to service: %s", pid);