]> git.ipfire.org Git - thirdparty/systemd.git/commit - man/systemd.exec.xml
core: add "invocation ID" concept to service manager
authorLennart Poettering <lennart@poettering.net>
Tue, 30 Aug 2016 21:18:46 +0000 (23:18 +0200)
committerLennart Poettering <lennart@poettering.net>
Fri, 7 Oct 2016 18:14:38 +0000 (20:14 +0200)
commit4b58153dd22172d817055d2a09a0cdf3f4bd9db3
tree1050683cb79031b8054c99dd1494ddfff0b09b2c
parente5d855d364a2a474cb42da618d2e4372619ac61d
core: add "invocation ID" concept to service manager

This adds a new invocation ID concept to the service manager. The invocation ID
identifies each runtime cycle of a unit uniquely. A new randomized 128bit ID is
generated each time a unit moves from and inactive to an activating or active
state.

The primary usecase for this concept is to connect the runtime data PID 1
maintains about a service with the offline data the journal stores about it.
Previously we'd use the unit name plus start/stop times, which however is
highly racy since the journal will generally process log data after the service
already ended.

The "invocation ID" kinda matches the "boot ID" concept of the Linux kernel,
except that it applies to an individual unit instead of the whole system.

The invocation ID is passed to the activated processes as environment variable.
It is additionally stored as extended attribute on the cgroup of the unit. The
latter is used by journald to automatically retrieve it for each log logged
message and attach it to the log entry. The environment variable is very easily
accessible, even for unprivileged services. OTOH the extended attribute is only
accessible to privileged processes (this is because cgroupfs only supports the
"trusted." xattr namespace, not "user."). The environment variable may be
altered by services, the extended attribute may not be, hence is the better
choice for the journal.

Note that reading the invocation ID off the extended attribute from journald is
racy, similar to the way reading the unit name for a logging process is.

This patch adds APIs to read the invocation ID to sd-id128:
sd_id128_get_invocation() may be used in a similar fashion to
sd_id128_get_boot().

PID1's own logging is updated to always include the invocation ID when it logs
information about a unit.

A new bus call GetUnitByInvocationID() is added that allows retrieving a bus
path to a unit by its invocation ID. The bus path is built using the invocation
ID, thus providing a path for referring to a unit that is valid only for the
current runtime cycleof it.

Outlook for the future: should the kernel eventually allow passing of cgroup
information along AF_UNIX/SOCK_DGRAM messages via a unique cgroup id, then we
can alter the invocation ID to be generated as hash from that rather than
entirely randomly. This way we can derive the invocation race-freely from the
messages.
40 files changed:
Makefile-man.am
man/sd_id128_get_machine.xml
man/systemd.exec.xml
src/basic/cgroup-util.c
src/basic/cgroup-util.h
src/basic/log.c
src/basic/log.h
src/core/automount.c
src/core/busname.c
src/core/cgroup.c
src/core/dbus-manager.c
src/core/dbus-unit.c
src/core/device.c
src/core/execute.c
src/core/manager.c
src/core/manager.h
src/core/mount.c
src/core/org.freedesktop.systemd1.conf
src/core/path.c
src/core/scope.c
src/core/service.c
src/core/slice.c
src/core/socket.c
src/core/swap.c
src/core/target.c
src/core/timer.c
src/core/unit.c
src/core/unit.h
src/journal/journald-server.c
src/journal/journald-server.h
src/libsystemd/libsystemd.sym
src/libsystemd/sd-bus/bus-common-errors.c
src/libsystemd/sd-bus/bus-common-errors.h
src/libsystemd/sd-id128/id128-util.c
src/libsystemd/sd-id128/id128-util.h
src/libsystemd/sd-id128/sd-id128.c
src/network/networkd-link.h
src/network/networkd-netdev.h
src/shared/bus-util.c
src/systemd/sd-id128.h