mirror of
https://github.com/systemd/systemd.git
synced 2025-02-14 05:57:40 +03:00
core: allocate sets of startup and failed units on-demand
There's a good chance we never needs these sets, hence allocate them only when needed.
This commit is contained in:
parent
aa36007ca1
commit
5269eb6b32
@ -602,14 +602,6 @@ int manager_new(ManagerRunningAs running_as, bool test_run, Manager **_m) {
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
|
||||||
r = set_ensure_allocated(&m->startup_units, NULL);
|
|
||||||
if (r < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
r = set_ensure_allocated(&m->failed_units, NULL);
|
|
||||||
if (r < 0)
|
|
||||||
goto fail;
|
|
||||||
|
|
||||||
r = sd_event_default(&m->event);
|
r = sd_event_default(&m->event);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
goto fail;
|
goto fail;
|
||||||
@ -3069,8 +3061,9 @@ const char *manager_get_runtime_prefix(Manager *m) {
|
|||||||
getenv("XDG_RUNTIME_DIR");
|
getenv("XDG_RUNTIME_DIR");
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager_update_failed_units(Manager *m, Unit *u, bool failed) {
|
int manager_update_failed_units(Manager *m, Unit *u, bool failed) {
|
||||||
unsigned size;
|
unsigned size;
|
||||||
|
int r;
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(u->manager == m);
|
assert(u->manager == m);
|
||||||
@ -3078,13 +3071,19 @@ void manager_update_failed_units(Manager *m, Unit *u, bool failed) {
|
|||||||
size = set_size(m->failed_units);
|
size = set_size(m->failed_units);
|
||||||
|
|
||||||
if (failed) {
|
if (failed) {
|
||||||
|
r = set_ensure_allocated(&m->failed_units, NULL);
|
||||||
|
if (r < 0)
|
||||||
|
return log_oom();
|
||||||
|
|
||||||
if (set_put(m->failed_units, u) < 0)
|
if (set_put(m->failed_units, u) < 0)
|
||||||
log_oom();
|
return log_oom();
|
||||||
} else
|
} else
|
||||||
set_remove(m->failed_units, u);
|
(void) set_remove(m->failed_units, u);
|
||||||
|
|
||||||
if (set_size(m->failed_units) != size)
|
if (set_size(m->failed_units) != size)
|
||||||
bus_manager_send_change_signal(m);
|
bus_manager_send_change_signal(m);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ManagerState manager_state(Manager *m) {
|
ManagerState manager_state(Manager *m) {
|
||||||
|
@ -369,7 +369,7 @@ const char *manager_get_runtime_prefix(Manager *m);
|
|||||||
|
|
||||||
ManagerState manager_state(Manager *m);
|
ManagerState manager_state(Manager *m);
|
||||||
|
|
||||||
void manager_update_failed_units(Manager *m, Unit *u, bool failed);
|
int manager_update_failed_units(Manager *m, Unit *u, bool failed);
|
||||||
|
|
||||||
const char *manager_state_to_string(ManagerState m) _const_;
|
const char *manager_state_to_string(ManagerState m) _const_;
|
||||||
ManagerState manager_state_from_string(const char *s) _pure_;
|
ManagerState manager_state_from_string(const char *s) _pure_;
|
||||||
|
@ -528,7 +528,7 @@ void unit_free(Unit *u) {
|
|||||||
|
|
||||||
unit_release_cgroup(u);
|
unit_release_cgroup(u);
|
||||||
|
|
||||||
manager_update_failed_units(u->manager, u, false);
|
(void) manager_update_failed_units(u->manager, u, false);
|
||||||
set_remove(u->manager->startup_units, u);
|
set_remove(u->manager->startup_units, u);
|
||||||
|
|
||||||
free(u->description);
|
free(u->description);
|
||||||
@ -1172,6 +1172,7 @@ static int unit_add_mount_dependencies(Unit *u) {
|
|||||||
|
|
||||||
static int unit_add_startup_units(Unit *u) {
|
static int unit_add_startup_units(Unit *u) {
|
||||||
CGroupContext *c;
|
CGroupContext *c;
|
||||||
|
int r;
|
||||||
|
|
||||||
c = unit_get_cgroup_context(u);
|
c = unit_get_cgroup_context(u);
|
||||||
if (!c)
|
if (!c)
|
||||||
@ -1181,6 +1182,10 @@ static int unit_add_startup_units(Unit *u) {
|
|||||||
c->startup_blockio_weight == CGROUP_BLKIO_WEIGHT_INVALID)
|
c->startup_blockio_weight == CGROUP_BLKIO_WEIGHT_INVALID)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
r = set_ensure_allocated(&u->manager->startup_units, NULL);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
return set_put(u->manager->startup_units, u);
|
return set_put(u->manager->startup_units, u);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1807,7 +1812,7 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Keep track of failed units */
|
/* Keep track of failed units */
|
||||||
manager_update_failed_units(u->manager, u, ns == UNIT_FAILED);
|
(void) manager_update_failed_units(u->manager, u, ns == UNIT_FAILED);
|
||||||
|
|
||||||
/* Make sure the cgroup is always removed when we become inactive */
|
/* Make sure the cgroup is always removed when we become inactive */
|
||||||
if (UNIT_IS_INACTIVE_OR_FAILED(ns))
|
if (UNIT_IS_INACTIVE_OR_FAILED(ns))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user