From 7c102d60925a9af92c192ebae4d088c7618874a2 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 28 Feb 2017 16:07:56 +0100 Subject: [PATCH 1/3] core: use PID_FMT where appropriate --- src/core/service.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/service.c b/src/core/service.c index 5581ec8b06..3f87e08369 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3286,7 +3286,7 @@ static void service_bus_name_owner_change( if (r >= 0) r = sd_bus_creds_get_pid(creds, &pid); if (r >= 0) { - log_unit_debug(u, "D-Bus name %s is now owned by process %u", name, (unsigned) pid); + log_unit_debug(u, "D-Bus name %s is now owned by process " PID_FMT, name, pid); service_set_main_pid(s, pid); unit_watch_pid(UNIT(s), pid); From e8b509d3bec0cd32746315cf83c79cc3a7618c9c Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 28 Feb 2017 16:08:21 +0100 Subject: [PATCH 2/3] service: make use of log_unit_warning_errno()'s return value --- src/core/service.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index 3f87e08369..5bc8df3e1c 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -849,11 +849,8 @@ static int service_load_pid_file(Service *s, bool may_warn) { return r; r = unit_watch_pid(UNIT(s), pid); - if (r < 0) { - /* FIXME: we need to do something here */ - log_unit_warning_errno(UNIT(s), r, "Failed to watch PID "PID_FMT" for service: %m", pid); - return r; - } + if (r < 0) /* FIXME: we need to do something here */ + return log_unit_warning_errno(UNIT(s), r, "Failed to watch PID "PID_FMT" for service: %m", pid); return 0; } @@ -1374,8 +1371,7 @@ static int service_spawn( return r; r = unit_watch_pid(UNIT(s), pid); - if (r < 0) - /* FIXME: we need to do something here */ + if (r < 0) /* FIXME: we need to do something here */ return r; *_pid = pid; From 6939ce648aae1bf7e515731c0547a54eb939c259 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 28 Feb 2017 16:08:40 +0100 Subject: [PATCH 3/3] service: refuse using PID 1 as MAINPID for a service --- src/core/service.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/service.c b/src/core/service.c index 5bc8df3e1c..74054887b9 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -3093,6 +3093,8 @@ static void service_notify_message(Unit *u, pid_t pid, char **tags, FDSet *fds) log_unit_warning(u, "Failed to parse MAINPID= field in notification message: %s", e); else if (pid == s->control_pid) log_unit_warning(u, "A control process cannot also be the main process"); + else if (pid == getpid() || pid == 1) + log_unit_warning(u, "Service manager can't be main process, ignoring sd_notify() MAINPID= field"); else { service_set_main_pid(s, pid); unit_watch_pid(UNIT(s), pid);