]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
unit: suppress unnecessary cgroup empty check
authorLennart Poettering <lennart@poettering.net>
Tue, 1 Sep 2015 14:45:34 +0000 (16:45 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 1 Sep 2015 15:20:56 +0000 (17:20 +0200)
Rework the "service is good" check, to only check the cgroup state if we
really need to instead of always.

This allows us to suppress going to the cgroupfs for an empty check for
the majority of services.

No functional change.

src/core/service.c

index 3c4232417da597fecf7923e6448aed3fb0f9855a..a05ae950720c3f95538278474d69bfa946e38dc5 100644 (file)
@@ -1520,18 +1520,33 @@ fail:
         service_enter_signal(s, SERVICE_STOP_SIGTERM, SERVICE_FAILURE_RESOURCES);
 }
 
+static bool service_good(Service *s) {
+        int main_pid_ok;
+        assert(s);
+
+        if (s->type == SERVICE_DBUS && !s->bus_name_good)
+                return false;
+
+        main_pid_ok = main_pid_good(s);
+        if (main_pid_ok > 0) /* It's alive */
+                return true;
+        if (main_pid_ok == 0) /* It's dead */
+                return false;
+
+        /* OK, we don't know anything about the main PID, maybe
+         * because there is none. Let's check the control group
+         * instead. */
+
+        return cgroup_good(s) != 0;
+}
+
 static void service_enter_running(Service *s, ServiceResult f) {
-        int main_pid_ok, cgroup_ok;
         assert(s);
 
         if (f != SERVICE_SUCCESS)
                 s->result = f;
 
-        main_pid_ok = main_pid_good(s);
-        cgroup_ok = cgroup_good(s);
-
-        if ((main_pid_ok > 0 || (main_pid_ok < 0 && cgroup_ok != 0)) &&
-            (s->bus_name_good || s->type != SERVICE_DBUS)) {
+        if (service_good(s)) {
 
                 /* If there are any queued up sd_notify()
                  * notifications, process them now */