Systemd/src/libsystemd
Lennart Poettering 1b3f9dd759 bus-message: introduce two kinds of references to bus messages
Before this commit bus messages had a single reference count: when it
reached zero the message would be freed. This simple approach meant a
cyclic dependency was typically seen: a message that was enqueued in a
bus connection object would reference the bus connection object but also
itself be referenced by the bus connection object. So far out strategy
to avoid cases like this was: make sure to process the bus connection
regularly so that messages don#t stay queued, and at exit flush/close
the connection so that the message queued would be emptied, and thus the
cyclic dependencies resolved. Im many cases this isn't done properly
however.

With this change, let's address the issue more systematically: let's
break the reference cycle. Specifically, there are now two types of
references to a bus message:

1. A regular one, which keeps both the message and the bus object it is
   associated with pinned.

2. A "queue" reference, which is weaker: it pins the message, but not
   the bus object it is associated with.

The idea is then that regular user handling uses regular references, but
when a message is enqueued on its connection, then this takes a "queue"
reference instead. This then means that a queued message doesn't imply
the connection itself remains pinned, only regular references to the
connection or a message associated with it do. Thus, if we end up in the
situation where a user allocates a bus and a message and enqueues the
latter in the former and drops all refs to both, then this will detect
this case and free both.

Note that this scheme isn't perfect, it only covers references between
messages and the busses they are associated with. If OTOH a bus message
is enqueued on a different bus than it is associated with cyclic deps
cannot be recognized with this simple algorithm, and thus if you enqueue
a message associated with a bus A on a bus B, and another message
associated with bus B on a bus A, a cyclic ref will be in effect and not
be discovered. However, given that this is an exotic case (though one
that happens, consider systemd-bus-stdio-bridge), it should be OK not to
cover with this, and people have to explicit flush all queues on exit in
that case.

Note that this commit only establishes the separate reference counters
per message. A follow-up commit will start making use of this from the
bus connection object.
2019-03-01 15:37:39 +01:00
..
sd-bus bus-message: introduce two kinds of references to bus messages 2019-03-01 15:37:39 +01:00
sd-daemon sd-daemon: make sd_booted() return negative errno on unexpected error 2019-02-07 14:44:44 +01:00
sd-device sd-device: split device_read_db_internal() into two part 2019-02-26 12:55:43 +09:00
sd-event sd-event: introduce event_free_signal_data() 2019-01-18 13:53:43 +01:00
sd-hwdb sd-hwdb: fix matching for characters with an ord > 127 2019-02-13 23:19:20 +01:00
sd-id128 Use c99 static array size declarations in exported functions too 2019-01-04 12:37:25 +01:00
sd-login Remove 'inline' attributes from static functions in .c files (#11426) 2019-01-15 08:12:28 +01:00
sd-netlink netlink: fix routing-policy-rule integer type for FRA_TUN_ID 2019-02-18 15:23:35 +01:00
sd-network Remove 'inline' attributes from static functions in .c files (#11426) 2019-01-15 08:12:28 +01:00
sd-path Move LONG_LINE_MAX definition to fileio.h 2018-11-14 16:25:32 +01:00
sd-resolve Delete duplicate lines 2019-01-12 16:02:26 +01:00
sd-utf8 tree-wide: drop empty comments 2018-06-29 11:00:30 +09:00
disable-mempool.c mempool: only enable mempool use when linked to libsystemd-shared.so 2018-10-11 11:10:37 +02:00
libsystemd.pc.in meson: define PROJECT_VERSION as the "bare" project version 2018-12-20 21:35:29 +01:00
libsystemd.sym sd-bus: add sd_bus_close_unref() helper 2019-01-17 16:12:38 +01:00
meson.build meson: simplify handling of pkgconfigdatadir=no, pkgconfiglibdir=no 2018-12-21 13:43:20 +01:00