X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fservice.c;h=5050bcafa1e993553b7979ba5e3195340f43ea10;hb=c72dcc54315a5bb854849e17a34c6ad8a3f9dfaa;hp=6f1a85e943d02f43ee39bd33e708215b3b64c36a;hpb=00ca7f07825dd3d0a8820eafdd8fcdbd2c7809d9;p=elogind.git diff --git a/src/service.c b/src/service.c index 6f1a85e94..5050bcafa 100644 --- a/src/service.c +++ b/src/service.c @@ -1269,11 +1269,8 @@ static int service_load_pid_file(Service *s) { assert(s); - if (s->main_pid_known) - return 0; - if (!s->pid_file) - return 0; + return -ENOENT; if ((r = read_one_line_file(s->pid_file, &k)) < 0) return r; @@ -1290,6 +1287,16 @@ static int service_load_pid_file(Service *s) { return -ESRCH; } + if (s->main_pid_known) { + if (pid == s->main_pid) + return 0; + + log_debug("Main PID changing: %lu -> %lu", + (unsigned long) s->main_pid, (unsigned long) pid); + service_unwatch_main_pid(s); + s->main_pid_known = false; + } + if ((r = service_set_main_pid(s, pid)) < 0) return r; @@ -2575,6 +2582,11 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) { success = is_clean_exit(code, status); if (s->main_pid == pid) { + /* Forking services may occasionally move to a new PID. + * As long as they update the PID file before exiting the old + * PID, they're fine. */ + if (service_load_pid_file(s) == 0) + return; s->main_pid = 0; exec_status_exit(&s->main_exec_status, &s->exec_context, pid, code, status);