Yu Watanabe [Thu, 9 Mar 2023 04:05:57 +0000 (13:05 +0900)]
Merge pull request #26698 from ldv-alt/udevadm-verify
Implement a udev rules syntax checker in the form of
`udevadm verify [OPTIONS] FILE...` command that is based on
`udev_rules_parse_file` interface and would apply further checks
on top of it in the future.
> I feel like the logging here may be a bit confusing on the new path.
> Previously you did get a message that explained what was going on. Now you get
> an info message that the layout could not be compiled, and … that's all. I can
> imagine this being a confusing red herring if someone was trying to debug a
> problem and saw this message. Perhaps we should log something else instead/as
> well, on the case where libxkbcommon isn't present, to say that's what we're
> logging about and it just means we can't validate the configuration, not that
> it's definitely invalid?
Dmitry V. Levin [Wed, 8 Mar 2023 08:00:00 +0000 (08:00 +0000)]
udev_rules_parse_file: issue diagnostics about line continuation at EOF
When udev rules file ends with a line continuation, the parser
used to silently ignore the line without any diagnostics at all.
It's time to break the vow of silence and let the parser issue some
error diagnostics.
Dmitry V. Levin [Fri, 3 Mar 2023 08:00:00 +0000 (08:00 +0000)]
meson.build: check udev rules using udevadm verify
Although udev rules are already being checked by rule-syntax-check.py
script, also check them using udevadm verify which performs more
thorough checks.
Dmitry V. Levin [Thu, 2 Mar 2023 08:00:00 +0000 (08:00 +0000)]
udevadm: introduce new 'verify' command
We seem to have no tool to verify udev rule files. There is a simple
udev rules syntax checker in the tree, test/rule-syntax-check.py, but
it is too simple to detect less trivial issues not detected by udev,
e.g. redundant comparisons (#26593) or labels without references.
Such a tool would be beneficial not only for maintaining udev rules
distributed along with udev, but also and even more so for maintaining
third party udev rules that are more likely to have issues with syntax
and semantic correctness.
Implement a udev rules syntax and semantics checker in the form of
'udevadm verify [OPTIONS] FILE...' command that is based on
udev_rules_parse_file() interface and would apply further checks
on top of it in subsequent commits.
Dmitry V. Levin [Wed, 1 Mar 2023 08:00:00 +0000 (08:00 +0000)]
udev_rules_parse_file: mark logged issues
Traditionally, all issues found in udev rules by udev_rules_parse_file()
are logged and ignored, so there was no mechanism to propagate the
information about these issues back to the caller.
Introduce such a mechanism by adding a new member to UdevRuleFile.
This new member is a bitmask describing which log levels were used
in messages logged with regards to the rule file.
This mechanism is going to be used by udevadm verify in subsequent
commits.
Luca Boccassi [Wed, 8 Mar 2023 12:59:40 +0000 (12:59 +0000)]
core: log message when reloading finishes
Reloading might be slow, especially when under memory pressure, and watchdogs
might be triggered. It is useful to have timestamped telemetry in the journal
to see how long a reload takes.
See #26688: getenv() is not thread-safe, and could a possible source of
problems when a multi-threaded program calls setenv()/putenv()/unsetenv() in
parallel. It is not possible to avoid getenv() calls in general, since $PATH,
$LANG, $SHELL, $USER, $HOME, $TZ may need to be accessed at any time.
Add a warning to our docs so that people are aware of the issue.
Closes #26688. (Real fixes will need to be in glibc and gnome-shell or other
programs.)
The text is added to threads-aware.xml to be included in various places. By
including it in libsystemd-pkgconfig.xml, it is automatically added to all sd-*
pages. The text is also included explicitly in pages for a few other functions
which are call getenv().
Chitoku [Wed, 8 Mar 2023 10:52:55 +0000 (19:52 +0900)]
timesync: stop re-sync on network configuration change when no link servers are configured (#26708)
This commit fixes an issue where systemd-timesyncd re-synchronizes the
system clock every time the network configuration is updated, no matter
whether link servers are actually changed.
localed: skip verification when libxkbcommon is not installed
When compliled without libxkbcommon, we do no verification and accept the
arguments as given. When compliled against with, if dlopen() works, we do the
verification. But if dlopen() fails, we would refuse the call and return
SD_BUS_ERROR_INVALID_ARGS. 5de344704df64d8f31448f1222432bc87ddcfbef added things
this way when converting to dlopen(), but it seems not very useful: it can be
expected that when the library is supported but missing at runtime, we degrade
softly, and that the behaviour is something inbetween the cases of hard disable
at compilation time and full support. But right now we behave more strictly then
if disabled at compilation. Change the code to just warn if dlopen fails, but
accept the arguments.
(There are various minimization scenarios where forcing the installation of
libxkbcommon is not useful. E.g. a small installation where we want to set the
keymap via logind, but the configuration is managed by a configuration
management system and is known to be valid. Verification via libxkbcommon is
just overhead in this case.)
800f65f827c9828d4c872d44b19ca8a008505690 moved the check earlier, so now even
a noop case of setting the values that were already in place can fail.
C.f. https://bugzilla.redhat.com/show_bug.cgi?id=2175244.
For any user on a semi-recent kernel, effectively this setting is pointless.
We should deprecate it once not needed anymore for the v1 hierarchy. For
now, adjust the description.
When cpu controller is disabled, thing would often still behave as if
it was. And since the cpu controller can be enabled "magically" e.g. by
starting user@1000, add a note for users to be careful. Autogrouping
is described well in the man page, incl. how to enable or disable it,
so it should be enough to refer to that.
man: tweak details in descriptions of pids and cpu configuration
For CPUWeight=: there is an important distinction between our default of
[not set], and the kernel default of "100". Let's not say that our default
is "100" because then 'systemctl show' output is hard to explain.
For task accounting, it's the kernel that does the accounting, not systemd.
man: describe how cgroup controllers are turned on
For a user, information which cgroup controllers are enabled based on
the unit configuration is rather important. Not only because it determines
what resource control is peformed by the kernel, but also because controllers
have a non-negligible cost, especially for deep nesting, and users may want
to *not* have controllers enabled.
Our documentation did its best to avoid the topic so far. This was partially
caused by the support for cgroup v1, which meant that any discussion of
controllers had to be conditional and messy. But v1 is deprecated on its way
out, so it should be fine to just describe what happens with v2.
The text is extended with a discussion of how controllers are enabled and
disabled, and an example, and for various settings that enable controllers
the relevant controller is now mentioned.
The details discussion of how search and route-only domains work is in
systemd-resolved.service(8). But users are more likely to look at
resolved.conf(5), because that's where Domains= is described. So let's add a
reference to the other man page there, and also strengthen the text a bit. In
particular, in systemd-resolved.service(8) we say "route-only", which makes
the distinction with search domains clearer. Let's use the same in the other
man page too.
This is based on feedback from Lukáš Nykrýn that the man page is not clear
enough.
Joshua Goins [Sat, 4 Mar 2023 03:02:02 +0000 (22:02 -0500)]
udev: Don't mark as tablet if device has relative coordinates
Tablets don't typically have relative coordinates (they are separated on
the kernel device layer). However, some Logitech mice report similar
supported events, so use the existence of EV_REL to determiner whether or
not the device is really a tablet.
dissect: implement external helper plugin interface for /bin/mount
With this change we'll install a symlink /sbin/mount.ddi →
systemd-dissect. If invoked that way we'll do the equivalent of
systemd-dissect --mount.
This makes DDIs mountable directly via the "mount" command, by
specifying the "-t ddi" pseudo file system type. Moreover you can now
mount DDIs directly via /etc/fstab, by specifying "ddi" in the file
system column (3rd column).
Adrian Vovk [Thu, 2 Mar 2023 18:20:51 +0000 (13:20 -0500)]
base-filesystem: Support Arch-style multilib
On distros like Arch and on carbonOS, libraries end up in /usr/lib.
Thus, /lib64 should point to /usr/lib. This commit adds this
functionality as a final fallback (if neither Debian-style nor
Fedora-style multilib can be detected)
Adrian Vovk [Thu, 2 Mar 2023 18:00:28 +0000 (13:00 -0500)]
gpt-auto: Check for /boot before putting ESP there
We prefer /efi as a mount point for the ESP, and use /boot as a fallback
if /efi doesn't exist. However, when root=tmpfs, neither /efi nor /boot
exist. gpt-auto should mount to /efi in this case, but it mounted to
/boot instead. This is because gpt-auto didn't check for the existence
of /boot. Here, we correct this
Dmitry V. Levin [Tue, 28 Feb 2023 08:00:00 +0000 (08:00 +0000)]
udev_rules_parse_file: do not skip ENOENT
Starting with commit ed88bcfb7c15029f9fc95ee2380759a9eb782d46,
udev_rules_parse_file() silently skips files it fails to open with
ENOENT error, e.g. when they are broken symlinks. As this behavior is
undocumented and it seems to be unintended, let's treat ENOENT like any
other error. This change would also simplify the implementation of the
udev rules syntax checker mentioned in #26606.
udev_rules_load(), the only user of udev_rules_parse_file(), is not
affected by this change because it essentially ignores the value
returned by the latter, the only visible difference would be a log
message issued for every udev rules file that couldn't be open because
of ENOENT.
Fixes: ed88bcfb7c15 ("Be more careful when checking for empty files")
Include <threads.h> if possible to get thread_local definition
IN C23, thread_local is a reserved keyword and we shall therefore
do nothing to redefine it. glibc has it defined for older standard
version with the right conditions.
v2 by Yu Watanabe:
Move the definition to missing_threads.h like the way we define e.g.
missing syscalls or missing definitions, and include it by the users.
Yu Watanabe [Mon, 6 Mar 2023 00:25:14 +0000 (09:25 +0900)]
tree-wide: replace IOVEC_INIT with IOVEC_MAKE
We use gnu11 to build, hence we can use structured initializer with
casting, and it is not necessary to use different patterns on
initialization and assignment.
Mike Yuan [Sat, 4 Mar 2023 11:38:35 +0000 (19:38 +0800)]
journalctl: fix output when --since is used with --lines
Before this commit, if --since is used with --lines=N,
we seek to the place of --since and search afterwards
there, resulting in outputing the first N lines.
After this commit, we only do the above if --since is used without
--reverse and --lines. Otherwise we seek to the tail first and check
if the entry is within the range of --since later.
Mike Yuan [Sat, 4 Mar 2023 11:06:00 +0000 (19:06 +0800)]
journalctl: fix output when --until is used with --lines
Before this commit, when --lines is specified, we jump to the tail and
search afterwards from there, thus breaking --until if used together.
After this commit:
If both --until and any of --reverse and --lines is specified, things get
a little tricky. We seek to the place of --until first. If only --reverse or
--reverse and --lines is specified, we search backwards and let the output
counter handle --lines for us. If only --lines is used, we just jump backwards
arg_lines and search afterwards from there.
systemctl: explicitly cast the constants to uint64_t
Otherwise under certain conditions `va_arg()` might get garbage instead
of the expected value, i.e.:
$ sudo build-o0/systemctl disable asdfasfaf
sd_bus_message_appendv: Got uint64_t: 0
Failed to disable unit: Unit file asdfasfaf.service does not exist.
Yu Watanabe [Fri, 3 Mar 2023 13:52:06 +0000 (22:52 +0900)]
mkdir: fix error code on failure
Before:
====
$ systemctl edit network.target
Failed to create directories for "/etc/systemd/system/network.target.d/override.conf": No such file or directory
====
After:
====
$ systemctl edit network.target
Failed to create directories for "/etc/systemd/system/network.target.d/override.conf": Permission denied
====
Fixes: #21787
(Strictly speaking, this leaves a race window open: the the system is
powered off in the short interval when we linked in the prepared hwdb
file into the dir under a temporary name and are about to rename it to
the final name, then the file might be left over after all. But this
minimizes the window so much that this shouldn't be an issue in
real-life. Key after all is that with this change we'll build up the
hwdb file under O_TMPFILE, and thus are robust to power loss during the
slow operation)