From 18ffdfda48c327f56cac0aabdc6bada91cc9b7df Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 1 Sep 2010 03:35:04 +0200 Subject: [PATCH] unit: unify some code --- src/manager.c | 9 +-------- src/socket.c | 2 +- src/unit.c | 14 ++++++++++++++ src/unit.h | 2 ++ 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/manager.c b/src/manager.c index ff1c70b48..e2f13b20e 100644 --- a/src/manager.c +++ b/src/manager.c @@ -2591,17 +2591,10 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) { assert(name); /* Returns true if the unit is inactive or going down */ - if (!(u = manager_get_unit(m, name))) return true; - if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u))) - return true; - - if (u->meta.job && u->meta.job->type == JOB_STOP) - return true; - - return false; + return unit_pending_inactive(u); } static const char* const manager_running_as_table[_MANAGER_RUNNING_AS_MAX] = { diff --git a/src/socket.c b/src/socket.c index fd975fd99..34068b919 100644 --- a/src/socket.c +++ b/src/socket.c @@ -1167,7 +1167,7 @@ static void socket_enter_running(Socket *s, int cfd) { /* We don't take connections anymore if we are supposed to * shut down anyway */ - if (s->meta.job && s->meta.job->type == JOB_STOP) { + if (unit_pending_inactive(UNIT(s))) { if (cfd >= 0) close_nointr_nofail(cfd); else { diff --git a/src/unit.c b/src/unit.c index bca4d9799..d5ed5e142 100644 --- a/src/unit.c +++ b/src/unit.c @@ -2125,6 +2125,20 @@ Unit *unit_following(Unit *u) { return NULL; } +bool unit_pending_inactive(Unit *u) { + assert(u); + + /* Returns true if the unit is inactive or going down */ + + if (UNIT_IS_INACTIVE_OR_DEACTIVATING(unit_active_state(u))) + return true; + + if (u->meta.job && u->meta.job->type == JOB_STOP) + return true; + + return false; +} + static const char* const unit_load_state_table[_UNIT_LOAD_STATE_MAX] = { [UNIT_STUB] = "stub", [UNIT_LOADED] = "loaded", diff --git a/src/unit.h b/src/unit.h index 15e7fedd0..c85d968b8 100644 --- a/src/unit.h +++ b/src/unit.h @@ -499,6 +499,8 @@ void unit_reset_failed(Unit *u); Unit *unit_following(Unit *u); +bool unit_pending_inactive(Unit *u); + const char *unit_load_state_to_string(UnitLoadState i); UnitLoadState unit_load_state_from_string(const char *s); -- 2.30.2