]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/service: use switch in service_notify_message_authorized()
authorMike Yuan <me@yhndnzj.com>
Sun, 14 Jul 2024 18:32:34 +0000 (20:32 +0200)
committerMike Yuan <me@yhndnzj.com>
Sun, 21 Jul 2024 20:48:54 +0000 (22:48 +0200)
src/core/service.c

index 921373686787accbe7770cea0c6341b5fc4fbd49..b4d283686c8e42e4cf167faafb35a980d3688485 100644 (file)
@@ -4345,24 +4345,31 @@ 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);
+        switch (service_get_notify_access(s)) {
 
-        if (notify_access == NOTIFY_NONE) {
+        case 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);
                 return false;
-        }
 
-        if (notify_access == NOTIFY_MAIN && pid != s->main_pid.pid) {
+        case NOTIFY_ALL:
+                return true;
+
+        case NOTIFY_MAIN:
+                if (pid == s->main_pid.pid)
+                        return true;
+
                 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
                         log_unit_debug(UNIT(s), "Got notification message from PID "PID_FMT", but reception only permitted for main PID which is currently not known", pid);
 
                 return false;
-        }
 
-        if (notify_access == NOTIFY_EXEC && pid != s->main_pid.pid && pid != s->control_pid.pid) {
+        case NOTIFY_EXEC:
+                if (pid == s->main_pid.pid || pid == s->control_pid.pid)
+                        return true;
+
                 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);
@@ -4374,9 +4381,10 @@ static bool service_notify_message_authorized(Service *s, pid_t pid) {
                         log_unit_debug(UNIT(s), "Got notification message from PID "PID_FMT", but reception only permitted for main PID and control PID which are currently not known", pid);
 
                 return false;
-        }
 
-        return true;
+        default:
+                assert_not_reached();
+        }
 }
 
 static void service_notify_message(