From 3a45fdfce074e38b3498316b14f986d83e204aeb Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 1 Mar 2024 21:45:32 +0800 Subject: [PATCH 1/3] core/service: reorder two functions --- src/core/service.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index d017515c92..086404f675 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -4311,6 +4311,16 @@ static int service_dispatch_watchdog(sd_event_source *source, usec_t usec, void return 0; } +static void service_force_watchdog(Service *s) { + if (!UNIT(s)->manager->service_watchdogs) + return; + + log_unit_error(UNIT(s), "Watchdog request (last status: %s)!", + s->status_text ?: ""); + + service_enter_signal(s, SERVICE_STOP_WATCHDOG, SERVICE_FAILURE_WATCHDOG); +} + static bool service_notify_message_authorized(Service *s, pid_t pid, FDSet *fds) { assert(s); @@ -4348,16 +4358,6 @@ static bool service_notify_message_authorized(Service *s, pid_t pid, FDSet *fds) return true; } -static void service_force_watchdog(Service *s) { - if (!UNIT(s)->manager->service_watchdogs) - return; - - log_unit_error(UNIT(s), "Watchdog request (last status: %s)!", - s->status_text ?: ""); - - service_enter_signal(s, SERVICE_STOP_WATCHDOG, SERVICE_FAILURE_WATCHDOG); -} - static void service_notify_message( Unit *u, const struct ucred *ucred, From b7a22068ae9aee01807f981f693b561749923174 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 1 Mar 2024 21:43:12 +0800 Subject: [PATCH 2/3] core/service: rearrange variables, use ASSERT_PTR --- src/core/service.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index 086404f675..77531bbba9 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -4364,25 +4364,23 @@ static void service_notify_message( char * const *tags, FDSet *fds) { - Service *s = SERVICE(u); - bool notify_dbus = false; - usec_t monotonic_usec = USEC_INFINITY; - const char *e; + Service *s = ASSERT_PTR(SERVICE(u)); int r; - assert(u); assert(ucred); if (!service_notify_message_authorized(s, ucred->pid, fds)) return; if (DEBUG_LOGGING) { - _cleanup_free_ char *cc = NULL; - - cc = strv_join(tags, ", "); + _cleanup_free_ char *cc = strv_join(tags, ", "); log_unit_debug(u, "Got notification message from PID "PID_FMT" (%s)", ucred->pid, empty_to_na(cc)); } + usec_t monotonic_usec = USEC_INFINITY; + bool notify_dbus = false; + const char *e; + /* Interpret MAINPID= */ e = strv_find_startswith(tags, "MAINPID="); if (e && IN_SET(s->state, SERVICE_START, SERVICE_START_POST, SERVICE_RUNNING, SERVICE_RELOAD, SERVICE_RELOAD_SIGNAL, SERVICE_RELOAD_NOTIFY)) { From f8d66947834039bb982d15ffce863f6eaa085f29 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Fri, 1 Mar 2024 21:48:23 +0800 Subject: [PATCH 3/3] core/service: remove unused function param and minor cleanup --- src/core/service.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index 77531bbba9..9ba2e09a81 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -4321,14 +4321,15 @@ static void service_force_watchdog(Service *s) { service_enter_signal(s, SERVICE_STOP_WATCHDOG, SERVICE_FAILURE_WATCHDOG); } -static bool service_notify_message_authorized(Service *s, pid_t pid, FDSet *fds) { +static bool service_notify_message_authorized(Service *s, pid_t pid) { assert(s); + assert(pid_is_valid(pid)); NotifyAccess notify_access = service_get_notify_access(s); if (notify_access == NOTIFY_NONE) { /* Warn level only if no notifications are expected */ - log_unit_warning(UNIT(s), "Got notification message from PID "PID_FMT", but reception is disabled.", pid); + log_unit_warning(UNIT(s), "Got notification message from PID "PID_FMT", but reception is disabled", pid); return false; } @@ -4344,7 +4345,7 @@ static bool service_notify_message_authorized(Service *s, pid_t pid, FDSet *fds) if (notify_access == NOTIFY_EXEC && pid != s->main_pid.pid && pid != s->control_pid.pid) { if (pidref_is_set(&s->main_pid) && pidref_is_set(&s->control_pid)) log_unit_debug(UNIT(s), "Got notification message from PID "PID_FMT", but reception only permitted for main PID "PID_FMT" and control PID "PID_FMT, - pid, s->main_pid.pid, s->control_pid.pid); + pid, s->main_pid.pid, s->control_pid.pid); else if (pidref_is_set(&s->main_pid)) log_unit_debug(UNIT(s), "Got notification message from PID "PID_FMT", but reception only permitted for main PID "PID_FMT, pid, s->main_pid.pid); else if (pidref_is_set(&s->control_pid)) @@ -4369,7 +4370,7 @@ static void service_notify_message( assert(ucred); - if (!service_notify_message_authorized(s, ucred->pid, fds)) + if (!service_notify_message_authorized(s, ucred->pid)) return; if (DEBUG_LOGGING) {