core: disable event sources before unreffing them
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 10 May 2021 08:22:07 +0000 (10:22 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 20 Jul 2021 15:59:39 +0000 (17:59 +0200)
commit78578b31cd8fc3b6b8d76e5e9820a30cf3dc542a
tree541fae3b4f98dac536beb6f7c8fc750abfcc014a
parent3422b16ef9a85ab0a31558a68db67f148961d4a1
core: disable event sources before unreffing them

This mirrors the change done for systemd-resolved in
97935302283729c9206b84f5e00b1aff0f78ad19. Quoting that patch:

> We generally operate on the assumption that a source is "gone" as soon as we
> unref it. This is generally true because we have the only reference. But if
> something else holds the reference, our unref doesn't really stop the source
> and it could fire again.

In particular, we take temporary references from sd-event code, and when called
from an sd-event callback, we could temporarily see this elevated reference
count. This patch doesn't seem to change anything, but I think it's nicer to do
the same change as in other places and not rely on _unref() immediately
disabling the source.

(cherry picked from commit 5dcadb4c8320f6a7b8a9353404874d43668e4648)
(cherry picked from commit 67782e10f0dd0f2feeb036aa4380fa5c6c55aaea)
13 files changed:
src/core/automount.c
src/core/cgroup.c
src/core/dbus.c
src/core/job.c
src/core/manager.c
src/core/mount.c
src/core/path.c
src/core/scope.c
src/core/service.c
src/core/socket.c
src/core/swap.c
src/core/timer.c
src/core/unit.c