diff options
author | Lennart Poettering <lennart@poettering.net> | 2015-09-01 16:45:34 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2015-09-01 17:20:56 +0200 |
commit | 957c3cf97cd0063a3b78aa068d5351ae3b1b0c0c (patch) | |
tree | 4ad0d029aea00aff1dc8eb9afed2242d7b4ecff7 /src/core/service.c | |
parent | ae2a2c53dd059f0f20fa8080f6b67389be3d3e89 (diff) |
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.
Diffstat (limited to 'src/core/service.c')
-rw-r--r-- | src/core/service.c | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/src/core/service.c b/src/core/service.c index 3c4232417d..a05ae95072 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -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 */ |