Commit Graph
3645 Commits
Author SHA1 Message Date
Lennart Poettering a133189eee journal-file: be a tiny bit more careful with generating seqnums
Let's handle overflows in a vaguely reasonable way, i.e. avoid the
special values 0 and UINT64_MAX
2023-01-26 15:27:16 +01:00
Lennart Poettering 50bf54ad0a Merge pull request #26198 from poettering/journal-strict-mode
journal: enforce strict ordering only when writing journal files from journald, but not from journal-remote and similar
2023-01-26 11:19:54 +01:00
Lennart Poettering bd524f497f journal: automatically pick up boot ID in journal_file_append_entry()
Let's pick up the boot ID early if unspecified, in
journal_file_append_entry(). This is symmetric to the fact that we
already pick up the monotonic timestamp in journal_file_append_entry()
if unspecified, and given that the monotonic clock is not too useful
without its boot ID it makes a lot of sense to pick them up at the same
time.

There are two relevant callers of journal_file_append_entry() right now:
journald (which leaves the boot ID unspecified) and journal-remote
(there are also some tests, but those don't matter too much). The former
calls it to store new entries in the journal file, the latter for
converting/processing/merging existing ones (where it passes along the
original boot ID). This new code hence only is relevant on the former,
and using the boot ID of the current system is the right choice for live
generated entries.

Note that this effectively changes little, since the lower-level
function journal_file_append_entry_internal() will copy boot ID stored
in the file header into all records if unspecified, and typically that's
the one of the local system. But strictly speaking this is not the right
thing to do, since we actually might end up appending to journal files
from previous boots. (The lower level function is indirectly used by
various tests, where the copying-from-header logic kinda makes sense
since they are detached from any live messages streaming in from the
host after all).
2023-01-26 09:52:49 +01:00
Lennart Poettering ce92dc27a1 journal-file: make strict order optional
This is a follow-up for 1d8d483f59 and
makes the strict ordering by realtime clock within each journal file
optional, not mandatory. It then enables it for all journal files
written by journald, but leaves it off on others (for example those
written by journald-remote).

This relaxes the logic behind writing journal files to the status quo
ante for all cases where the journal files are not generated, but are
merged/processed/propagated. Typically when processing journal records
from many files ordering by realtime clock and monotonic clock are
contradictory, and cannot be universally guaranteed as the records are
interleaved. By enforcing strict rules we would thus end up generating
myriads of separate journal files, each with just a few records in them.

Hence, let's losen restrictions again, but continue to enforce them in
journald, i.e. when we original create the journal files locally.

Note that generally there's nothing really wring with having journal
files with non-monotonically ordered entries by realtime clock. Looking
for records will not be deterministic anymore, but that's inherent to a
realtime clock that jumps up and down. So you won't get the "only"
answer, but still *a* answer that is correct if you seek for a realtime
clock.

This also adds similar logic on the monotonic clock, which is also only
enabled when generating journal files locally. This should be harder to
trigger (as journald will generate the messages, and should run with a
stable boot id and monotonic clock), but let's better be safe than
sorry, and refuse on the lower layer what makes no sense, even if it's
unlikely the higher layer will ever generate records that aren't ordered
by their monotonic clock.
2023-01-25 22:12:29 +01:00
Lennart Poettering 79f7681621 Merge pull request #26204 from poettering/journal-header-compoung-init
journal: use compound initialization for journal file "Header" structure
2023-01-25 21:22:07 +01:00
Lennart Poettering c3dd0dcb88 journal: use compound initialization for journal file Header structure 2023-01-25 18:48:31 +01:00
Lennart Poettering 6fe167d0a7 journal-def: fix type of signature to match the actual field in the Header structure 2023-01-25 18:47:05 +01:00
Lennart Poettering 8c29ac2f8a journal-file: cast file size to to fixed size type
(We generally avoid using off_t for file sizes/offsets, and instead use
uint64_t to get the same behaviour everywhere. Do so here too.)
2023-01-25 14:17:20 +01:00
Lennart Poettering b45a7215fd journal-file: fix type of array counter 2023-01-25 14:16:44 +01:00
Jan Janssen 4a7ee0a521 meson: Do not include headers in source lists
Meson+ninja+compiler do this for us and are better at it.

https://mesonbuild.com/FAQ.html#do-i-need-to-add-my-headers-to-the-sources-list-like-in-autotools
2023-01-24 22:04:03 +01:00
Zbigniew Jędrzejewski-Szmek e830d6dd2d Merge pull request #25145 from yuwata/udevadm-trigger
udev: make 'udevadm trigger --settle' work even if device is renamed
2023-01-23 13:49:20 +01:00
David Tardon 7100653885 sd-path: export env. generators paths 2023-01-21 11:27:40 +00:00
Yu Watanabe 1dcfbc514c systemctl,test: -EBADF instead of -EBADFD
Follow-up for da20baaecc.
2023-01-21 10:47:54 +01:00
Lennart Poettering 404803e6ca sd-journal: validate monotonic timestamp before returning it 2023-01-21 10:46:02 +01:00
Lennart Poettering 6f30a67a7a journal: use compound initializors at one more place 2023-01-20 21:46:50 +01:00
Lennart Poettering 6320409c56 journal: modernize match_make_string() 2023-01-20 21:46:32 +01:00
Lennart Poettering fba1033151 Merge pull request #26114 from bluca/sd_login_pidfd
sd-login: add sd_pidfd_* APIs
2023-01-20 17:28:13 +01:00
Luca Boccassi 71c6f0ac52 Merge pull request #23309 from DaanDeMeyer/log-context
basic: Add log context
2023-01-20 15:01:03 +00:00
Luca Boccassi da20baaecc sd-login: add sd_pidfd_* APIs
Same as the sd_pid_* counterparts, but take a pid file descriptor instead of
a pid, so that the callers can be sure that the returned values are really
about the process they asked for, and not about a recycled PID.
2023-01-20 12:18:05 +00:00
Yu Watanabe 3e61656fab sd-id128: introduce id128_hash_ops_free 2023-01-19 17:55:21 +09:00
Lennart Poettering 11b6d7cba9 Merge pull request #26021 from fbuihuu/some-journald-improvements
Some journald improvements
2023-01-18 15:05:40 +01:00
Franck Bui aeefa4d248 udev: support '-=' operator for SYMLINK
For some (corner) cases, it might be desirable to disable the generation of
some persistent storage symlinks that 60-persistent-storage.rules creates.

For example on big setups with a high number of partitions which uses the same
label name, this can result in a noticeable slow-down in the (re)start of the
udevd as there are many contenders for the symlink /dev/disk/by-partlabel.

However it's currently pretty hard to overwrite just some specific part of the
rule file. Indeed one need to copy and modify the whole rule file in /etc but
will lost any upcoming updates/fixes that the distro might release in the
future.

With this simple patch, one can now disable the generation of the
"by-partlabel" symlinks (for example) with the following single rule:

$ cat /etc/udev/rules.d/99-no-by-partlabel.rules
ENV{ID_PART_ENTRY_NAME}=="?*", SYMLINK-="disk/by-partlabel/$env{ID_PART_ENTRY_NAME}"

Closes #24607.
2023-01-17 14:39:24 +09:00
Franck Bui 596c3c7f1b journald: introduce journal_file_parse_uid_from_filename() helper 2023-01-16 15:04:29 +01:00
Daan De Meyer a2640646f1 network: Show network and link file dropins in networkctl status
Fixes #24428
2023-01-12 13:44:52 +09:00
Luca Boccassi c32b049dfb Merge pull request #25986 from yuwata/test-netlink
test-netlink: cleanups
2023-01-10 21:21:24 +00:00
Daan De Meyer 68634c2665 Merge pull request #24939 from msizanoen1/journal-realtime-enforce-consistency
journal: enforce strict consistency for realtime timestamps on write
2023-01-10 14:30:53 +01:00
Yu Watanabe 5ccbe7fb19 test-netlink: use dummy interface to test assigning new interface name
Fixes #25981.
2023-01-10 21:01:59 +09:00
Yu Watanabe eedfef0f0d sd-device: introduce device_get_property_int() 2023-01-10 14:25:20 +09:00
msizanoen1 1d8d483f59 journal: enforce strict consistency for realtime timestamps on write
Ensure all realtime timestamps in a journal file are strictly
ordered on write as a defense-in-depth measure. All known callers of
journal_file_append_entry and journal_file_copy_entry, which call this
function, should be able to handle the error by rotating the journal.

This is especially helpful for systems with RTC local time enabled,
where all log entries from initramfs might be recorded as several hours
later than it actually is, which won't get caught by journald during log
flushing. In those cases, the resulting inconsistency can cause libsystemd
to loop infinitely through journal files as observed in
`abrt-dump-journal-oops`.
2023-01-09 22:57:30 +07:00
Yu Watanabe eafff21da2 test: modernize test-netlink.c 2023-01-09 20:33:35 +09:00
Yu Watanabe ff88b94953 udev: move device_rename() from device-private.c
The function is used only by udevd.
2023-01-09 15:02:55 +09:00
Yu Watanabe 1de6a49721 sd-device: do not directly access entry in sd-device object
No functional change, just refactoring.
2023-01-09 15:00:56 +09:00
Yu Watanabe 9a26098e90 sd-device: make device_set_syspath() clear sysname and sysnum
Otherwise, when a new syspath is assigned to the sd-device object,
sd_device_get_sysname() or _sysnum() will provide an outdated device
name or number.
2023-01-09 14:00:20 +09:00
Daan De Meyer e808a1d12e device-monitor: Add extra fields to the log context before callback 2023-01-08 16:31:16 +01:00
Daan De Meyer 1773292745 sd-bus: Log extra fields when processing bus message 2023-01-08 16:31:16 +01:00
Luca Boccassi 9907a7e00b Merge pull request #25915 from poettering/arm-timer-rel
pid1: rework service_arm_timer() to optionally take a relative time v…
2023-01-07 17:56:14 +01:00
Lennart Poettering ef8591951a sd-event: don't mistake USEC_INFINITY passed in for overflow
Let's pass USEC_INFINITY from sd_event_source_set_time_relative() to
sd_event_source_set_time() instead of raising EOVERFLOW.

We should raise EOVERFLOW only if your addition fails, but not if the
input already is USEC_INFINITY, since it's an entirely valid operation
to have an infinite time-out, and we should support that.
2023-01-06 11:29:09 +01:00
Luca Boccassi 6c94cfcda5 sd_notify: support AF_VSOCK
Allow sending notifications via AF_VSOCK, so that VMs can communicate
to the hypervisor/VMM that they are finished booting.

Note that if the hypervisor does not support SOCK_DGRAM over AF_VSOCK
(ie: qemu at the time of writing), SOCK_SEQPACKET will be used instead.
2023-01-05 23:07:16 +01:00
Lennart Poettering 8656f4a6ae prioq: make prioq_reshuffle() void
We never use the return value, and it's confusing and kinda pointless
what we return there.

Hence drop it.

Originally noticed by: tristone13th <tristone13th@outlook.com>

Alternative to: #25810
2022-12-23 23:26:26 +01:00
Yu Watanabe 5bb1d7fbab tree-wide: use -EBADF more 2022-12-21 01:50:33 +09:00
Yu Watanabe 19ee48a6c2 tree-wide: introduce PIPE_EBADF macro 2022-12-20 11:12:58 +09:00
Zbigniew Jędrzejewski-Szmek 3401477982 tree-wide: use -EBADF also in pipe initializers
In some places, initialization is dropped when unnecesary.
2022-12-19 15:00:59 +01:00
Zbigniew Jędrzejewski-Szmek 254d1313ae tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various
places. Let's make things consistent in the new style.

Note that there are two candidates:
EBADF 9 Bad file descriptor
EBADFD 77 File descriptor in bad state

Since we're initializating the fd, we're just assigning a value that means
"no fd yet", so it's just a bad file descriptor, and the first errno fits
better. If instead we had a valid file descriptor that became invalid because
of some operation or state change, the other errno would fit better.

In some places, initialization is dropped if unnecessary.
2022-12-19 15:00:57 +01:00
Zbigniew Jędrzejewski-Szmek cbff793ffb sd-event: never pass negative errnos as signalfd to signalfd
We treat any negative value as "invalid fd", but signalfd only
accepts -1.
2022-12-19 14:56:28 +01:00
Nick Rosbrook b338a8bb40 sd-netlink: add a test for rtnl_set_link_name()
Add a test that verifies a deleted alternative name is restored on error
in rtnl_set_link_name().
2022-12-15 09:39:05 -05:00
Nick Rosbrook 4d600667f8 sd-netlink: restore altname on error in rtnl_set_link_name
If a current alternative name is to be used to rename a network
interface, the alternative name must be removed first. If interface
renaming fails, restore the alternative name that was deleted if
necessary.
2022-12-15 09:35:26 -05:00
Nick Rosbrook 080afbb57c sd-netlink: do not swap old name and alternative name
Commit 434a348380 ("netlink: do not fail when new interface name is
already used as an alternative name") added logic to set the old
interface name as an alternative name, but only when the new name is
currently an alternative name. This is not the desired outcome in most
cases, and the important part of this commit was to delete the new name
from the list of alternative names if necessary.
2022-12-15 09:21:53 -05:00
Yu Watanabe 75fa1f25c0 sd-id128: also refuse an empty invocation ID 2022-12-15 00:07:17 +09:00
Yu Watanabe 786b652c89 sd-id128: allow sd_id128_get_machine() and friend to be called with NULL
It may be useful to check if the machine ID or friends is set or not.
2022-12-15 00:07:17 +09:00
Yu Watanabe e8a6625422 sd-id128: make sd_id128_get_machine() or friends return -EUCLEAN when an ID is in an invalid format
EINVAL suggests that the caller passes an invalid argument. EIO is
for "input/output error", i.e. the error you'd get if the disk or
file system is borked, and this error code could be returned by the
underlying read/write functions.

Let's make the functions return an unambiguous error code.
2022-12-15 00:07:13 +09:00