Commit Graph
3223 Commits
Author SHA1 Message Date
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
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
Yu Watanabe b40c8ebdc8 sd-id128: fold do_sync flag into Id128FormatFlag 2022-12-12 22:07:48 +09:00
Yu Watanabe e2720340e9 sd-id128: make sd_id128_get_boot() and friend return -ENOSYS when /proc/ is not mounted 2022-12-12 22:04:53 +09:00
Yu Watanabe 9be90c401e sd-id128: make sd_id128_get_boot() and friend return -ENOMEDIUM 2022-12-12 22:04:53 +09:00
Yu Watanabe 057bf780e9 sd-id128: make id128_read() or friends return -ENOPKG when the file contents is "uninitialized"
Then, this drops ID128_PLAIN_OR_UNINIT. Also, this renames
Id128Format -> Id128FormatFlag, and make it bitfield.

Fixes #25634.
2022-12-12 21:57:31 +09:00
Yu Watanabe 28bf2de201 sd-id128: several cleanups
- use SD_ID128_STRING_MAX or friend,
- use sizeof(sd_id128_t),
- use newly introduced ascii_ishex().
2022-12-12 21:48:47 +09:00
Yu Watanabe 733529d812 test: name_assign_type sysattr never exists for enumerated devices
As we filtered out network devices in the test.
2022-12-12 15:04:39 +09:00
Yu Watanabe eb18e7b782 sd-device: fix double-free
If an attribute is read but the value is not used (i.e. ret_value is NULL),
then sd_device_get_sysattr_value() mistakenly frees the read data even though
it is cached internally.

Fixes a bug introduced by acfc2a1d15.

Fixes #25702.
2022-12-12 14:20:47 +09:00
msizanoen1 3d19e122cf core/unit: allow overriding an ongoing freeze operation
Sometimes a freeze operation can hang due to the presence of kernel
threads inside the unit cgroup (e.g. QEMU-KVM). This ensures that the
ThawUnit operation invoked by systemd-sleep at wakeup always thaws the
unit.
2022-12-08 00:54:53 +01:00
Daan De Meyer 04cb8ee880 journal: Ratelimit more log messages
Followup for 8522691d4d.
2022-12-05 14:41:53 +01:00
Daan De Meyer d9799ea2e2 journal: Use shared log ratelimit constant
Instead of maintaining two different constants, move the constant
to journal-internal.h and share it between files.
2022-12-05 14:41:51 +01:00
Yu Watanabe 6b15f2eff9 sd-netlink: fix assertion triggered by message_get_serial()
This fixes an issue introduced by 7b34bae3b1.

Fixes https://github.com/systemd/systemd/pull/25565#issuecomment-1331353945.
2022-11-30 10:16:17 +00:00
Yu Watanabe 52ceba53d3 sd-netlink: append instead of prepend multipart message
Previously, e.g., networkd enumerated network interfaces with ifindex
in a decreasing order, as sd-netlink inverses the order of the received
multipart messages.
Let's keep the order of the multipart messages. Hopefully this changes
no behavior, as our code do not depend on the order of the received
multipart messages.

Before:
===
Nov 26 09:35:10 systemd[1]: Starting Network Configuration...
Nov 26 09:35:11 systemd-networkd[36185]: wlp59s0: Saved new link: ifindex=3, iftype=ETHER(1), kind=n/a
Nov 26 09:35:12 systemd-networkd[36185]: enp0s31f6: Saved new link: ifindex=2, iftype=ETHER(1), kind=n/a
Nov 26 09:35:12 systemd-networkd[36185]: lo: Saved new link: ifindex=1, iftype=LOOPBACK(772), kind=n/a

After:
===
Nov 26 09:45:18 systemd[1]: Starting Network Configuration...
Nov 26 09:45:19 systemd-networkd[38372]: lo: Saved new link: ifindex=1, iftype=LOOPBACK(772), kind=n/a
Nov 26 09:45:19 systemd-networkd[38372]: enp0s31f6: Saved new link: ifindex=2, iftype=ETHER(1), kind=n/a
Nov 26 09:45:19 systemd-networkd[38372]: wlp59s0: Saved new link: ifindex=3, iftype=ETHER(1), kind=n/a
2022-11-26 11:28:27 +09:00
Yu Watanabe a8ac052624 sd-netlink: do not link non-multipart messages
Previously, if a single packet contains multiple non-multipart messages,
then the messages were linked and saved as a single entry, especially
even if the messages has different serial numbers. Though, not sure if
the kernel sends such packet. But at least for safety, let's link only
multipart messages.
2022-11-26 11:28:27 +09:00
Yu Watanabe 9482429af9 sd-netlink: split out parse_message_one() from socket_read_message()
No functional change, just refactoring and preparation for later
commits.
2022-11-26 11:28:27 +09:00
Yu Watanabe 2b176edc74 sd-netlink: do not use serials currently queued 2022-11-26 11:28:27 +09:00
Yu Watanabe 7b34bae3b1 sd-netlink: also manage received messages by serial
Then, we can easily find the received message matching with requested
serial.
2022-11-26 11:28:27 +09:00
Yu Watanabe e417c4ac44 sd-netlink: reimplement received message queue
By using OrderedSet and Hashmap, we can drop all memmove() calls.
No functional changes, just refactoring.
2022-11-26 11:28:27 +09:00
Yu Watanabe 2ea465ef62 sd-netlink: introduce netlink_queue_received_message() and friend
No functional change, just refactoring.
2022-11-26 11:28:27 +09:00
Yu Watanabe 766417bd76 sd-netlink: fix segfault 2022-11-26 11:28:27 +09:00
Yu Watanabe bc1a8e2b6e sd-netlink: fix possible use-after-free
When we receive a multi-part message and fail to parse it, then
the prviously received message is freed with the _cleanup_ attribute,
but still referenced by sd_netlink.rqueue_partial. That causes
use-after-free when we receive another multi-part message.
2022-11-26 11:28:27 +09:00
Yu Watanabe b491454dfc sd-netlink: return earlier when received invalid message 2022-11-26 11:28:27 +09:00
Yu Watanabe fb298ef104 sd-netlink: allocate read buffer when necessary 2022-11-26 11:28:27 +09:00