[systemd-devel] [PATCH] Fix timeout when stopping Type=notify service

Olivier Brunel jjk at jjacky.com
Fri Sep 20 13:53:52 PDT 2013

Since 41efeaec a call to service_unwatch_main_pid() is done from
service_set_main_pid(), which is called upon receiving message MAINPID=

This had the side effect of not watching pid anymore, and would result in a
useless timeout when stopping the service, as the unit wouldn't be identified
from the pid, so not marked stopped which would result in systemd thinking this
was a timeout.
I'm not exactly familiar with systemd's internals, so this might not be the
correct way to fix this, please correct me if it isn't.

 src/core/service.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/core/service.c b/src/core/service.c
index 246a86e..1dccdff 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -3388,9 +3388,17 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags) {
                                          "Failed to parse notification message %s", e);
                 else {
+                        int r;
                                        "%s: got %s", u->id, e);
                         service_set_main_pid(s, pid);
+                        r = unit_watch_pid(u, pid);
+                        if (r < 0)
+                                /* FIXME: we need to do something here */
+                                log_warning_unit(u->id,
+                                                 "Failed to watch PID %lu from service %s",
+                                                 (unsigned long) pid, u->id);

More information about the systemd-devel mailing list