unit: unify some code

This commit is contained in:
Lennart Poettering 2010-09-01 03:35:04 +02:00
parent 8f6df3fa98
commit 18ffdfda48
4 changed files with 18 additions and 9 deletions

View File

@ -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] = {

View File

@ -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 {

View File

@ -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",

View File

@ -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);