Skip to content

Commit

Permalink
core: do not GC units/jobs that are in the D-Bus queue
Browse files Browse the repository at this point in the history
Let's make sure that D-Bus messages are always sent out when pending,
before we might GC a unit/job.

This is kinda a follow-up for 8db9989,
and a similar logic really applies: GC should only be done if we
processed everything else, generated evertyhing else and really don't
need it anymore.

(cherry picked from commit af05bb9)

Related: RHEL-55301
  • Loading branch information
poettering authored and jamacku committed Jan 7, 2025
1 parent 7d3d8e5 commit 3700206
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/core/dbus-job.c
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ void bus_job_send_change_signal(Job *j) {
if (j->in_dbus_queue) {
LIST_REMOVE(dbus_queue, j->manager->dbus_job_queue, j);
j->in_dbus_queue = false;

/* The job might be good to be GC once its pending signals have been sent */
job_add_to_gc_queue(j);
}

r = bus_foreach_bus(j->manager, j->bus_track, j->sent_dbus_new_signal ? send_changed_signal : send_new_signal, j);
Expand Down
3 changes: 3 additions & 0 deletions src/core/dbus-unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,9 @@ void bus_unit_send_change_signal(Unit *u) {
if (u->in_dbus_queue) {
LIST_REMOVE(dbus_queue, u->manager->dbus_unit_queue, u);
u->in_dbus_queue = false;

/* The unit might be good to be GC once its pending signals have been sent */
unit_add_to_gc_queue(u);
}

if (!u->id)
Expand Down
4 changes: 4 additions & 0 deletions src/core/job.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,10 @@ bool job_may_gc(Job *j) {
if (!UNIT_VTABLE(j->unit)->gc_jobs)
return false;

/* Make sure to send out pending D-Bus events before we unload the unit */
if (j->in_dbus_queue)
return false;

if (sd_bus_track_count(j->bus_track) > 0)
return false;

Expand Down
4 changes: 4 additions & 0 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ bool unit_may_gc(Unit *u) {
if (u->in_cgroup_empty_queue || u->in_cgroup_oom_queue)
return false;

/* Make sure to send out D-Bus events before we unload the unit */
if (u->in_dbus_queue)
return false;

if (sd_bus_track_count(u->bus_track) > 0)
return false;

Expand Down

0 comments on commit 3700206

Please sign in to comment.