unit: suppress unnecessary cgroup empty check

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.
This commit is contained in:
Lennart Poettering
2015-09-01 17:20:56 +02:00
parent ae2a2c53dd
commit 957c3cf97c
+21 -6
View 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 */