Zbigniew Jędrzejewski-Szmek [Fri, 25 Mar 2022 14:56:16 +0000 (15:56 +0100)]
test-systemctl-enable: use magic syntax to allow inverted tests
Inspired by
7910ec3bcde2ee0086b3e49f8aaa2a9f13f58d97.
'! true' passes, because it's a conditional expression.
But '( ! true )' fails, because '( … )' creates a subshell, i.e. a separate
program, and '! true' becomes the return value of that program, and the whole
thing apparently is not a conditional expression for the outer shell.
This is shorter, so let's just do this.
Zbigniew Jędrzejewski-Szmek [Fri, 25 Mar 2022 14:43:27 +0000 (15:43 +0100)]
shared/install: when creating symlinks, accept different but equivalent symlinks
We would only accept "identical" links, but having e.g. a symlink
/usr/lib/systemd/system/foo-alias.service → /usr/lib/systemd/system/foo.service
when we're trying to create /usr/lib/systemd/system/foo-alias.service →
./foo.service is OK. This fixes an issue found in ubuntuautopkg package
installation, where we'd fail when enabling systemd-resolved.service, because
the existing alias was absolute, and (with the recent patches) we were trying
to create a relative one.
A test is added.
(For .wants/.requires symlinks we were already doing OK. A test is also
added, to verify.)
Zbigniew Jędrzejewski-Szmek [Thu, 24 Mar 2022 10:52:35 +0000 (11:52 +0100)]
test-systemctl-enable: make shellcheck happy
Quoting is not necessary in many places, but I think it's nicer
to use it consistently.
Zbigniew Jędrzejewski-Szmek [Thu, 17 Mar 2022 15:02:10 +0000 (16:02 +0100)]
shared/install: fix handling of a linked unit file
When we have a symlink that goes outside of our search path, we should just
ignore the target file name. But we were verifying it, and rejecting in
the case where a symlink was created manually.
Zbigniew Jędrzejewski-Szmek [Thu, 17 Mar 2022 14:50:16 +0000 (15:50 +0100)]
shared/install: split UNIT_FILE_SYMLINK into two states
The two states are distinguished, but are treated everywhere identically,
so there is no difference in behaviour except for slighlty different log
output.
Zbigniew Jędrzejewski-Szmek [Thu, 17 Mar 2022 10:46:03 +0000 (11:46 +0100)]
basic/unit-file: reverse negative conditional
Having the reverse condition first makes changes that I want to do
later awkward, so reverse it as a separate step first.
Zbigniew Jędrzejewski-Szmek [Thu, 17 Mar 2022 09:16:30 +0000 (10:16 +0100)]
shared/install: stop passing duplicate root argument to install_name_printf()
All callers were just passing info + info->root, we can simplify this.
Zbigniew Jędrzejewski-Szmek [Wed, 16 Mar 2022 16:37:58 +0000 (17:37 +0100)]
shared/install: when looking for symlinks in .wants/.requires, ignore symlink target
We'd say that file is enabled indirectly if we had a symlink like:
foo@.service ← bar.target.wants/foo@one.service
but not when we had
foo@one.service ← bar.target.wants/foo@one.service
The effect of both link types is the same. In fact we don't care
about the symlink target. (We'll warn if it is mismatched, but we honour
it anyway.)
So let's use the original match logic only for aliases.
For .wants/.requires we instead look for a matching source name,
or a source name that matches after stripping of instance.
Zbigniew Jędrzejewski-Szmek [Wed, 16 Mar 2022 09:17:32 +0000 (10:17 +0100)]
shared/install: create relative symlinks for enablement and aliasing
This is a fairly noticable change, but I think it needs to be done.
So far we'd create an absolute symlink to the target unit file:
.wants/foo.service → /usr/lib/systemd/system/foo.service
or
alias.service → /etc/systemd/system/aliased.service.
This works reasonably well, except in one case: where the unit file
is linked. When we look at a file link, the name of the physical file
isn't used, and we only take the account the symlink source name.
(In fact, the destination filename may not even be a well-formed unit name,
so we couldn't use it, even if we wanted to.) But this means that if
a file is linked, and specifies aliases, we'd create absolute links for
those aliases, and systemd would consider each "alias" to be a separate
unit. This isn't checked by the tests here, because we don't have a running
systemd instance, but it is easy enough to check manually.
The most reasonable way to fix this is to create relative links to the
unit file:
.wants/foo.service → ../foo.service
alias.service → aliased.service.
I opted to use no prefix for aliases, both normal and 'default.target',
and to add "../" for .wants/ and .requires/. Note that the link that is
created doesn't necessarily point to the file. E.g. if we're enabling
a file under /usr/lib/systemd/system, and create a symlink in /etc/systemd/system,
it'll still be "../foo.service", not "../../usr/lib/systemd/system/foo.service".
For our unit loading logic this doesn't matter, and figuring out a path
that actually leads somewhere would be more work. Since the user is allowed
to move the unit file, or add a new unit file in a different location, and
we don't actually follow the symlink, I think it's OK to create a dangling
symlink. The prefix of "../" is useful to give a hint that the link points
to files that are conceptually "one level up" in the directory hierarchy.
With the relative symlinks, systemd knows that those are aliases.
The tests are adjusted to use the new forms. There were a few tests that
weren't really testing something useful: 'test -e x' fails if 'x' is a
a dangling symlink. Absolute links in the chroot would be dangling, even
though the target existed in the expected path, but become non-dangling
when made relative and the test fails.
This should be described in NEWS, but I'm not adding that here, because
it'd likely result in conflicts.
Zbigniew Jędrzejewski-Szmek [Wed, 16 Mar 2022 08:51:24 +0000 (09:51 +0100)]
shared/install: also remove symlinks like .wants/foo@one.service → ../foo@one.service
So far 'systemctl enable' would create absolute links to the target template
name. And we would remove such symlinks just fine. But the user may create
symlinks manually in a different form. In particular, symlinks for instanced
units *must* have the instance in the source name, and then it is natural to
also include it in the target name (.wants/foo@one.service → ../foo@one.service
rather than .wants/foo@one.service → ../foo@.service). We would choke on such
links, or not remove them at all. A test is added:
before:
+ build-rawhide/systemctl --root=/tmp/systemctl-test.001xda disable templ1@.service
Removed "/tmp/systemctl-test.001xda/etc/systemd/system/services.target.wants/templ1@seven.service".
Removed "/tmp/systemctl-test.001xda/etc/systemd/system/services.target.wants/templ1@six.service".
Removed "/tmp/systemctl-test.001xda/etc/systemd/system/services.target.wants/templ1@five.service".
Removed "/tmp/systemctl-test.001xda/etc/systemd/system/services.target.wants/templ1@four.service".
Removed "/tmp/systemctl-test.001xda/etc/systemd/system/services.target.wants/templ1@three.service".
Failed to disable unit, refusing to operate on linked unit file /tmp/systemctl-test.001xda/etc/systemd/system/services.target.wants/templ1@two.service.
Failed to disable unit, refusing to operate on linked unit file /tmp/systemctl-test.001xda/etc/systemd/system/services.target.wants/templ1@two.service.
after:
+ build-rawhide/systemctl --root=/tmp/systemctl-test.QVP0ev disable templ1@.service
Removed "/tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@seven.service".
Removed "/tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@six.service".
Removed "/tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@five.service".
Removed "/tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@four.service".
Removed "/tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@three.service".
Removed "/tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@two.service".
Removed "/tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@one.service".
+ test '!' -h /tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@one.service
+ test '!' -h /tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@two.service
+ test '!' -h /tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@three.service
+ test '!' -h /tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@four.service
+ test '!' -h /tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@five.service
+ test '!' -h /tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@six.service
+ test '!' -h /tmp/systemctl-test.QVP0ev/etc/systemd/system/services.target.wants/templ1@seven.service
Zbigniew Jędrzejewski-Szmek [Wed, 16 Mar 2022 08:28:46 +0000 (09:28 +0100)]
shared/install: skip unnecessary chasing of symlinks in disable
We use the symlink source name and destination names to decide whether to remove
the symlink. But if the source name is enough to decide to remove the symlink,
we'd still look up the destination for no good reason. This is a slow operation,
let's skip it.
Zbigniew Jędrzejewski-Szmek [Tue, 15 Mar 2022 16:45:34 +0000 (17:45 +0100)]
test-systemctl-enable: enhance the test for unit file linking
Current behaviour is wrong, but it cannot be shown in this test, because we
don't have a running systemd instance here.
Zbigniew Jędrzejewski-Szmek [Tue, 15 Mar 2022 15:35:47 +0000 (16:35 +0100)]
shared/install: do not try to resolve symlinks outside of root directory
I linked a file as root, so I had a symlink /root/test.service ← /etc/systemd/system/test.service.
To my surpise, when running test-systemctl-enable, it failed with a cryptic EACCES.
The previous commit made the logs a bit better. Strace shows that we
were trying to follow the symlink without taking --root into account.
It seems that this bug was introduced in
66a19d85a533b15ed32f4066ec880b5a8c06babd:
before it, we'd do readlink_malloc(), which returned a path relative to root. But
we only used that path for checking if the path is in remove_symlinks_to set, which
contains relative paths. So if the path was relative, we'd get a false-negative
answer, but we didn't go outside of the root. (We need to canonicalize the symlink
to get a consistent answer.) But after 66a19 we use chase_symlinks(), without taking
root into account which is completely bogus.
Zbigniew Jędrzejewski-Szmek [Wed, 2 Mar 2022 15:53:54 +0000 (16:53 +0100)]
shared/install: when we fail to chase a symlink, show some logs
When chase_symlinks() fails, we'd get the generic error:
Failed to disable: Permission denied.
Let's at least add the failure to changes list, so the user gets
a slightly better message. Ideally, we'd say where exactly the permission
failure occured, but chase_symlinks() is a library level function and I don't
think we should add logging there. The output looks like this now:
Failed to resolve symlink "/tmp/systemctl-test.1r7Roj/etc/systemd/system/link5alias2.service": Permission denied
Failed to resolve symlink "/tmp/systemctl-test.1r7Roj/etc/systemd/system/link5alias.service": Permission denied
Failed to disable unit, file /tmp/systemctl-test.1r7Roj/etc/systemd/system/link5alias2.service: Permission denied.
Failed to disable unit, file /tmp/systemctl-test.1r7Roj/etc/systemd/system/link5alias.service: Permission denied.
Zbigniew Jędrzejewski-Szmek [Tue, 15 Mar 2022 09:13:18 +0000 (10:13 +0100)]
test-systemctl-enable: extend the test for repeated WantedBy/RequiredBy
I was considering deduplicating the list of target units in
WantedBy/RequiredBy. But to do this meaningfully, we'd need to do alias
expansion first, i.e. after the initial parsing is done. This seems to be
more trouble than it would be worth.
Instead, I added tests that we're doing the right thing and creating symlinks
as expected. For duplicate links, we create the link, and on the second time we
see that the link is already there, so the output is correct.
Zbigniew Jędrzejewski-Szmek [Tue, 15 Mar 2022 08:44:39 +0000 (09:44 +0100)]
shared/install: fix reenable on linked unit files
Zbigniew Jędrzejewski-Szmek [Mon, 14 Mar 2022 11:09:31 +0000 (12:09 +0100)]
shared/install: split unit_file_{disable,enable}() so _reenable doesn't do setup twice
It was pretty ugly that we were creating LookupPaths twice.
Zbigniew Jędrzejewski-Szmek [Fri, 11 Mar 2022 13:27:46 +0000 (14:27 +0100)]
install: when linking a file, create the link first or abort
We'd create aliases and other symlinks first, and only then try to create
the main link. Since that can fail, let's do things in opposite order, and
abort immediately if we can't link the file itself.
Zbigniew Jędrzejewski-Szmek [Thu, 10 Mar 2022 20:33:25 +0000 (21:33 +0100)]
man: fix invalid description of template handling in WantedBy=
We don't need to talk about Alias=. The approach of using Alias= to enable
units is still supported, but hasn't been advertised as the way to do thing
for many years. Using it as an explanation is just confusing.
Also, the description of templated units did not take DefaultInstance=
into account. It is updated and extended.
Zbigniew Jędrzejewski-Szmek [Thu, 10 Mar 2022 19:26:59 +0000 (20:26 +0100)]
shared/install: also check for self-aliases during installation and ignore them
We had a check that was done in unit_file_resolve_symlink(). Let's move
the check to unit_validate_alias_symlink_or_warn(), which makes it available
to the code in install.c.
With this, unit_file_resolve_symlink() behaves almost the same. The warning
about "suspicious symlink" is done a bit later. I think this should be OK.
Zbigniew Jędrzejewski-Szmek [Thu, 10 Mar 2022 15:47:51 +0000 (16:47 +0100)]
systemctl: fix silent failure when --root is not found
Some calls to lookup_path_init() were not followed by any log emission.
E.g.:
$ SYSTEMD_LOG_LEVEL=debug systemctl --root=/missing enable unit; echo $?
1
Let's add a helper function and use it in various places.
$ SYSTEMD_LOG_LEVEL=debug build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
1
$ SYSTEMCTL_SKIP_SYSV=1 build/systemctl --root=/missing enable unit; echo $?
Failed to initialize unit search paths for root directory /missing: No such file or directory
Failed to enable: No such file or directory.
1
The repeated error in the second case is not very nice, but this is a niche
case and I don't think it's worth the trouble to trying to avoid it.
Zbigniew Jędrzejewski-Szmek [Thu, 10 Mar 2022 14:47:12 +0000 (15:47 +0100)]
shared/install: return failure when enablement fails, but process as much as possible
So far we'd issue a warning (before this series, just in the logs on the server
side, and before this commit, on stderr on the caller's side), but return
success. It seems that successfull return was introduced by mistake in
aa0f357fd833feecbea6c3e9be80b643e433bced (my fault :( ), which was supposed to
be a refactoring without a functional change. I think it's better to fail,
because if enablement fails, the user will most likely want to diagnose the
issue.
Note that we still do partial enablement, as far as that is possible. So if
e.g. we have [Install] Alias=foo.service foobar, we'll create the symlink
'foo.service', but not 'foobar', since that's not a valid unit name. We'll
print info about the action taken, and about 'foobar' being invalid, and return
failure.
Zbigniew Jędrzejewski-Szmek [Thu, 10 Mar 2022 10:03:41 +0000 (11:03 +0100)]
shared/install: propagate errors about invalid aliases and such too
If an invalid arg appears in [Install] Alias=, WantedBy=, RequiredBy=,
we'd warn in the logs, but not propagate this information to the caller,
and in particular not over dbus. But if we call "systemctl enable" on a
unit, and the config if invalid, this information is quite important.
Zbigniew Jędrzejewski-Szmek [Thu, 10 Mar 2022 08:19:37 +0000 (09:19 +0100)]
shared/install: simplify unit_file_dump_changes()
No functional change.
Zbigniew Jędrzejewski-Szmek [Wed, 9 Mar 2022 21:29:19 +0000 (22:29 +0100)]
shared/specifier: fix %u/%U/%g/%G when called as unprivileged user
We would resolve those specifiers to the calling user/group. This is mostly OK
when done in the manager, because the manager generally operates as root
in system mode, and a non-root in user mode. It would still be wrong if
called with --test though. But in systemctl, this would be generally wrong,
since we can call 'systemctl --system' as a normal user, either for testing
or even for actual operation with '--root=…'.
When operating in --global mode, %u/%U/%g/%G should return an error.
The information whether we're operating in system mode, user mode, or global
mode is passed as the data pointer to specifier_group_name(), specifier_user_name(),
specifier_group_id(), specifier_user_id(). We can't use userdata, because
it's already used for other things.
Zbigniew Jędrzejewski-Szmek [Wed, 9 Mar 2022 16:51:36 +0000 (17:51 +0100)]
shared/install: move scope into InstallContext
This makes it easier to pass it around in preparation for future changes.
While at it, let's rename InstallContext c → ctx, and InstallInfo i → info.
'c' and 'i' are bad names for variables that are passed through multiple layers
of functions calls. It's easier to follow what is happening with a meaningful
variable names.
Zbigniew Jędrzejewski-Szmek [Wed, 9 Mar 2022 15:06:24 +0000 (16:06 +0100)]
shared/install: provide proper error messages when invalid specifiers are used
$ build/systemctl --root=/tmp/systemctl-test.KXY8fu enable some-some-link6@.socket
Failed to enable unit, invalid specifier in "target@C:%C.socket".
Zbigniew Jędrzejewski-Szmek [Tue, 8 Mar 2022 11:08:00 +0000 (12:08 +0100)]
shared/specifier: provide proper error messages when specifiers fail to read files
ENOENT is easily confused with the file that we're working on not being
present, e.g. when the file contains %o or something else that requires
os-release to be present. Let's use -EUNATCH instead to reduce that chances of
confusion if the context of the error is lost.
And once we have pinpointed the reason, let's provide a proper error message:
+ build/systemctl --root=/tmp/systemctl-test.TO7Mcb enable some-some-link6@.socket
/tmp/systemctl-test.TO7Mcb/etc/systemd/system/some-some-link6@.socket: Failed to resolve alias "target@A:%A.socket": Protocol driver not attached
Failed to enable unit, cannot resolve specifiers in "target@A:%A.socket".
Zbigniew Jędrzejewski-Szmek [Tue, 8 Mar 2022 10:38:46 +0000 (11:38 +0100)]
shared/specifier: clarify and add test for missing data
In systemd.unit we document that unset fields resolve to "". But we didn't
directly test this, so let's do that. Also, we return -ENOENT if the file
is missing, which we didn't document or test.
Zbigniew Jędrzejewski-Szmek [Tue, 8 Mar 2022 09:10:12 +0000 (10:10 +0100)]
man/os-release: add a note about repeating entries
We didn't actually say that keys should not be repeated. At least the
examples in docs (both python and shell) would do that, and any simple
parser that builds a dictionary would most likely behave the same way.
But let's document this expectation, but also say how to deal with malformed
files.
Zbigniew Jędrzejewski-Szmek [Tue, 8 Mar 2022 09:08:05 +0000 (10:08 +0100)]
basic/env-file: make load-env-file deduplicate entries with the same key
We generally assume parsing like the shell would do it, so the last value
should win when there are repeats.
Zbigniew Jędrzejewski-Szmek [Mon, 7 Mar 2022 18:22:01 +0000 (19:22 +0100)]
test-os-util: add basic tests for os-release parsing
Zbigniew Jędrzejewski-Szmek [Mon, 7 Mar 2022 17:54:50 +0000 (18:54 +0100)]
basic: add new variable $SYSTEMD_OS_RELEASE to override location of os-release
The test for the variable is added in test-systemctl-enable because there we
can do it almost for free, and the variable is most likely to be used with
'systemctl enable --root' anyway.
Zbigniew Jędrzejewski-Szmek [Mon, 28 Mar 2022 09:46:38 +0000 (11:46 +0200)]
man: clarify the descriptions of aliases and linked unit files
This just describes the rules that are implemented by the manager, and this
pull request does not change any of them.
Zbigniew Jędrzejewski-Szmek [Mon, 7 Mar 2022 14:06:57 +0000 (15:06 +0100)]
tests: add helper for creating tempfiles with content
I put it in tests because I think we're most likely to use it in tests.
If necessary, it can be moved somewhere else later.
Zbigniew Jędrzejewski-Szmek [Mon, 7 Mar 2022 11:15:42 +0000 (12:15 +0100)]
test: add test for systemctl link & enable
This test has overlap with test-install-root, but it tests things at a
different level, so I think it's useful to add. It immediately shows various
bugs which will be fixed in later patches.
Zbigniew Jędrzejewski-Szmek [Thu, 3 Mar 2022 10:09:25 +0000 (11:09 +0100)]
shared/install: add a bit more quoting
When we are printing a valid unit name, quoting isn't necessary, because
unit names cannot contain whitespace or other confusing characters. In particular
if the unit name is prefixed by " unit " or something else that clearly
identifies the string as a unit name, quoting would just add unnecessary
noise. But when we're printing paths or invalid names, it's better to add
quotes for clarity.
Zbigniew Jędrzejewski-Szmek [Fri, 4 Mar 2022 17:47:31 +0000 (18:47 +0100)]
shared/install: reuse the standard symlink verification subroutine
We save a few lines, but the important thing is that we don't have two
different implementations with slightly different rules used for enablement
and loading. Fixes #22000.
Tested with:
- the report in #22000, it now says:
$ SYSTEMD_LOG_LEVEL=debug systemctl --root=/ enable test.service
Suspicious symlink /etc/systemd/system/test.service→/etc/systemd/system/myown.d/test.service, treating as alias.
unit_file_resolve_symlink: self-alias: /etc/systemd/system/test.service → test.service, ignoring.
running_in_chroot(): Permission denied
Suspicious symlink /etc/systemd/system/test.service→/etc/systemd/system/myown.d/test.service, treating as alias.
unit_file_resolve_symlink: self-alias: /etc/systemd/system/test.service → test.service, ignoring.
Failed to enable unit, refusing to operate on linked unit file test.service
- a symlink to /dev/null:
...
unit_file_resolve_symlink: linked unit file: /etc/systemd/system/test3.service → /dev/null
Failed to enable unit, unit /etc/systemd/system/test3.service is masked.
- the same from the host:
...
unit_file_resolve_symlink: linked unit file: /var/lib/machines/rawhide/etc/systemd/system/test3.service → /var/lib/machines/rawhide/dev/null
Failed to enable unit, unit /var/lib/machines/rawhide/etc/systemd/system/test3.service is masked.
- through the manager:
$ sudo systemctl enable test.service
Failed to enable unit: Refusing to operate on alias name or linked unit file: test.service
$ sudo systemctl enable test3.service
Failed to enable unit: Unit file /etc/systemd/system/test3.service is masked.
As seen in the first example, the warning is repeated. This is because we call
the lookup logic twice: first for sysv-compat, and then again for real. I think
that since this is only for broken setups, and when sysv-compat is enabled, and
in an infrequent manual operation, at debug level, this is OK.
Zbigniew Jędrzejewski-Szmek [Wed, 23 Mar 2022 16:47:33 +0000 (17:47 +0100)]
basic/stat-util: add null_or_empty_path_with_root()
Zbigniew Jędrzejewski-Szmek [Wed, 2 Mar 2022 15:53:54 +0000 (16:53 +0100)]
basic/unit-file: split out the subroutine for symlink verification
The old logs used __func__, but this doesn't make sense now, because the
low-level function will be used in other places. So those are adjusted to be
more generic.
Heiko Becker [Mon, 21 Mar 2022 19:47:02 +0000 (20:47 +0100)]
meson: Detect python instead of hard-coding python3
It allows to specify the desired python executable (and version) via
meson's native file if there are multiple versions available.
Frantisek Sumsal [Wed, 23 Mar 2022 11:47:23 +0000 (12:47 +0100)]
Revert "lgtm: disable cpp/missing-return"
This reverts commit
6f4bffb586dfb0ce8db4e02ccb7f076a45bca419.
Should be, hopefully, fixed by https://github.com/github/codeql/issues/8409.
Lennart Poettering [Wed, 23 Mar 2022 12:47:15 +0000 (13:47 +0100)]
doc: two markdown markup fixes
Lennart Poettering [Wed, 23 Mar 2022 12:43:47 +0000 (13:43 +0100)]
doc: add a bunch of missing <br>
Yu Watanabe [Wed, 23 Mar 2022 12:43:02 +0000 (21:43 +0900)]
Merge pull request #22835 from keszybz/foreach_string-inline-iterator
Inline the iterator declaration in FOREACH_STRING
Zbigniew Jędrzejewski-Szmek [Wed, 23 Mar 2022 11:42:47 +0000 (12:42 +0100)]
Merge pull request #22836 from poettering/more-build-image-docs
docs: more tweaks for the image building docs
Lennart Poettering [Wed, 23 Mar 2022 11:02:43 +0000 (12:02 +0100)]
update TODO
Lennart Poettering [Wed, 23 Mar 2022 11:24:03 +0000 (12:24 +0100)]
docs: extend BUILDING_IMAGES with a section about IMAGE_ID=/IMAGE_VERSION=
Also, beef up links everywhere.
Lennart Poettering [Wed, 23 Mar 2022 11:04:28 +0000 (12:04 +0100)]
docs: link up new image building docs a bit
Lennart Poettering [Wed, 23 Mar 2022 11:02:00 +0000 (12:02 +0100)]
docs: make man page links in markdown Links section use teletype font, as we usually do
Zbigniew Jędrzejewski-Szmek [Wed, 23 Mar 2022 09:49:04 +0000 (10:49 +0100)]
systemctl: use the right name in error message
Zbigniew Jędrzejewski-Szmek [Wed, 23 Mar 2022 09:48:13 +0000 (10:48 +0100)]
strv: declare iterator of FOREACH_STRING() in the loop
Same idea as
03677889f0ef42cdc534bf3b31265a054b20a354.
No functional change intended. The type of the iterator is generally changed to
be 'const char*' instead of 'char*'. Despite the type commonly used, modifying
the string was not allowed.
I adjusted the naming of some short variables for clarity and reduced the scope
of some variable declarations in code that was being touched anyway.
Lennart Poettering [Wed, 23 Mar 2022 10:39:31 +0000 (11:39 +0100)]
Merge pull request #22791 from keszybz/bootctl-invert-order
Invert order of entries w/o sort-key in sd-boot menu
Lennart Poettering [Wed, 23 Mar 2022 09:11:45 +0000 (10:11 +0100)]
Merge pull request #22629 from nishalkulkarni/oomd_service_result
core/oomd: Use oom-kill ServiceResult for oomd
Yu Watanabe [Wed, 23 Mar 2022 03:26:13 +0000 (12:26 +0900)]
sysupdate: fix error handling
Yu Watanabe [Wed, 23 Mar 2022 03:22:53 +0000 (12:22 +0900)]
NEWS: fix typo
Yu Watanabe [Wed, 23 Mar 2022 03:21:54 +0000 (12:21 +0900)]
boot: fix typo
Lennart Poettering [Tue, 22 Mar 2022 12:32:38 +0000 (13:32 +0100)]
fs-util: make sure openat_report_new() initializes return param also on shortcut
Our coding style dictates that return parameters should be initialized
always on success, hence do so here also in the shortcut codepath.
Issue discovered by @fbuihuu:
https://github.com/systemd/systemd/pull/22808/files/
ca8503f168d0632c606110da909aba3057777395#r831911069
Lennart Poettering [Tue, 22 Mar 2022 12:30:54 +0000 (13:30 +0100)]
fs-util: fix typos in comments
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 20:51:33 +0000 (21:51 +0100)]
meson: replace sh+find with an internal glob in the python helper
As suggested in https://github.com/systemd/systemd/pull/22810#discussion_r831708052
This makes the whole thing simpler. A glob is passed to helper which then resolves
it on its own. This way it's trivial to call the helper with a different
set of files for testing.
Yu Watanabe [Wed, 23 Mar 2022 02:34:46 +0000 (11:34 +0900)]
Merge pull request #22825 from keszybz/assorted-cleanups
Assorted cleanups
Luca Boccassi [Tue, 22 Mar 2022 23:03:23 +0000 (23:03 +0000)]
NEWS: adjust MONITOR_ env vars paragraph
This actually never shipped in a release, so it's not a backward-incompatible
change. Move it down and reword it.
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 20:07:41 +0000 (21:07 +0100)]
NEWS: initial writeup for v251
Luca Boccassi [Tue, 22 Mar 2022 20:17:38 +0000 (20:17 +0000)]
Merge pull request #22821 from poettering/udev-tweaklets
Udev tweaklets
Lennart Poettering [Tue, 22 Mar 2022 10:00:11 +0000 (11:00 +0100)]
docs: add some docs about building OS images
It's not trivial to know what to reset how. Let's document this a bit.
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 13:05:37 +0000 (14:05 +0100)]
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 13:02:47 +0000 (14:02 +0100)]
errno-to-awk: simplify expression
No functional change.
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 09:43:03 +0000 (10:43 +0100)]
sd-bus: use _cleanup_ in one more place
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 09:10:39 +0000 (10:10 +0100)]
tools/dbus_exporter: deblackify and shorten code a bit
When we do mkdir, we should just use 0o777 and let the umask take care of the
rest. Specifying an explicit mode is inappropriate. And when touching the code,
let's replace black madness with normal python style.
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 07:44:44 +0000 (08:44 +0100)]
man: clarify that options set the message fields and are not derived from them
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 12:57:28 +0000 (13:57 +0100)]
Merge pull request #22778 from poettering/kernel-install-layout-rework
kernel-install/bootctl: layout fixes
Nishal Kulkarni [Sun, 13 Mar 2022 19:11:11 +0000 (00:41 +0530)]
man: Mention systemd-oomd now follows OOMPolicy
Nishal Kulkarni [Mon, 14 Mar 2022 18:40:39 +0000 (00:10 +0530)]
test/oomd: Add test for new oomd_ooms xattr
Check if `user.oomd_ooms` xattr is being set as part of `oomd_cgroup_kill()`
this xattr tracks OOM kills that were initiated by systemd-oomd.
Nishal Kulkarni [Sun, 13 Mar 2022 19:05:18 +0000 (00:35 +0530)]
core/oomd: Use oom-kill ServiceResult for oomd
To notify user of kill events from systemd-oomd we now use
`SERVICE_FAILURE_OOM_KILL` as the failure result.
`unit_check_oomd_kill` now calls `notify_cgroup_oom` to
update the service result to `oom-kill`.
We add a new xattr `user.oomd_ooms` to keep track of the OOM kills
initiated by systemd-oomd, this helps us resolve a race between sending
SIGKILL to processes and checking for OOM kill status from the xattr.
Related to: #20649
Lennart Poettering [Tue, 22 Mar 2022 11:58:55 +0000 (12:58 +0100)]
sd-device: use path_compare() rather than strcmp() for sorting paths
When sorting paths it actually matters to use the right comparison
function. Example:
```
a/x
a-b/y
a_/z
```
I think people would probably expect this:
```
a/x
a-b/y
a_a/z
```
but if you use strcmp() instead of path_compare() you'd instead get:
```
a-b/y
a/x
a_a/z
```
That's because `/` is between `-` and `a` in the ascii table. I think
that's quite confusing, and we shouldn#t order that way hence.
As discussed: https://github.com/systemd/systemd/pull/22662#discussion_r831174776
Lennart Poettering [Tue, 22 Mar 2022 11:58:31 +0000 (12:58 +0100)]
sd-device: fix trivial typo
Lennart Poettering [Tue, 22 Mar 2022 11:56:32 +0000 (12:56 +0100)]
Merge pull request #22662 from yuwata/udev-trigger-priority
udevadm trigger: add --prioritized-subsystem option
Jason A. Donenfeld [Wed, 9 Mar 2022 16:10:05 +0000 (09:10 -0700)]
random-util: use correct minimum pool size constant
The actual minimum size of the pool across supported kernel versions is
32 bytes. So adjust this minimum.
I've audited every single usage of random_pool_size(), and cannot see
anywhere that this would have any impact at all on anything. We could
actually just not change the constant and everything would be fine, or
we could change it here and that's fine too. From both a functionality
and crypto perspective, it doesn't really seem to make a substantive
difference any which way, so long as the value is ≥32. However, it's
better to be correct and have the function do what it says, so clamp it
to the right minimum.
Zbigniew Jędrzejewski-Szmek [Tue, 22 Mar 2022 07:26:57 +0000 (08:26 +0100)]
Merge pull request #22813 from poettering/sd-boot-man-fixes
man: some sd-boot doc tweaks
Danilo Krummrich [Mon, 14 Jun 2021 15:46:00 +0000 (17:46 +0200)]
udevadm: trigger: implement --initialized-match/nomatch arguments
systemd-udev-trigger.service by default triggeres all devices regardless
of whether they were already recognized by systemd-udevd.
There are machines (especially in embedded environments) where
systemd-udev-trigger.service is configured to run at a later stage of
the boot sequence, which can lead to quite a lot of devices being
triggered although they were already recognized by systemd-udevd.
Re-triggering a lot of devices is a relatively expensive operation and
therefore should be avoided if unnecessary.
Therefore this patch introduces --initialized-nomatch, which filters out
devices that are already present in the udev database. For consistance
reasons --initialized-match is implemented as well, which filters out devices
that are *not* already present in the udev database.
Replaces #19949.
Yu Watanabe [Tue, 8 Mar 2022 04:58:02 +0000 (13:58 +0900)]
sd-device-enumerator: support to list only initialized or uninitialized devices
Yu Watanabe [Mon, 7 Mar 2022 16:33:29 +0000 (01:33 +0900)]
unit: make systemd-udev-trigger.service use --prioritized-subsystem
Replaces #19637 and #22643.
Yu Watanabe [Fri, 4 Mar 2022 12:45:24 +0000 (21:45 +0900)]
udevadm trigger: introduce --type=all option
Yu Watanabe [Fri, 4 Mar 2022 15:23:13 +0000 (00:23 +0900)]
udevadm trigger: introduce --prioritized-subsystem option
Yu Watanabe [Fri, 4 Mar 2022 12:40:41 +0000 (21:40 +0900)]
sd-device-enumerator: introduce device_enumerator_scan_devices_and_subsystems()
Yu Watanabe [Sat, 19 Mar 2022 00:35:32 +0000 (09:35 +0900)]
sd-device-enumerator: drop /sys/subsystem support
This addresses the comment by Lennart
https://github.com/systemd/systemd/pull/22662#discussion_r829799863:
> /sys/subsystem is preparation for a future that never came.
> And given that the main proponent of this left Linux kernel
> development (Kay), I doubt this will ever come. So maybe we
> should start dropping references to /sys/subsystem/ given it's
> unlikely to materialize anytime soon.
Yu Watanabe [Mon, 7 Mar 2022 16:20:42 +0000 (01:20 +0900)]
sd-device-enumerator: introduce device_enumerator_add_prioritized_subsystem()
If a subsystem is specified, then matching devices and their parents are
listed at first.
Yu Watanabe [Fri, 4 Mar 2022 13:40:49 +0000 (22:40 +0900)]
sd-device-enumerator: introduce device_enumerator_sort_devices()
and devices are sorted when the iteration started.
Previously, devices added by udev_enumerate_add_syspath() ->
device_enumerator_add_device() are not sorted. This fixes the issue.
Yu Watanabe [Fri, 4 Mar 2022 12:09:26 +0000 (21:09 +0900)]
sd-device-enumerator: introduce device_enumerator_unref_devices() helper function
Yu Watanabe [Thu, 10 Mar 2022 10:08:04 +0000 (19:08 +0900)]
sd-device-enumerator: introduce sound_device_compare() and devpath_is_late_block() helper functions
Lennart Poettering [Thu, 17 Mar 2022 17:25:40 +0000 (18:25 +0100)]
kernel-install: check for /loader/entries.srel file as explicit marker for standards compliant /loader/entries directory
Lennart Poettering [Thu, 17 Mar 2022 17:19:57 +0000 (18:19 +0100)]
bootctl: automatically write out $BOOT/entries/standard.srel
Lennart Poettering [Thu, 17 Mar 2022 17:18:04 +0000 (18:18 +0100)]
bootctl: generalize open_tmpfile_linkable() use a bit
We want FILE* here, instead of a plain fd. Let's generalize this in
tmpfile-util.c, so we can reuse it later easily.
Lennart Poettering [Thu, 17 Mar 2022 17:35:53 +0000 (18:35 +0100)]
docs: add /loader/entries.srel to the boot loader spec
This new file is supposed to address conflicts with Fedora/Grub's
frankenbootloaderspec implementation, that squatted the /loader/entries/
dir, but place incompatible files in them (that do variable expansion?).
A simple text file /loader/entries.srel shall indicate which spec is
implemented. If it contains the string "type1\n" then the
/loader/entries/ directory implements our standard spec, otherwise
something else.
Lennart Poettering [Mon, 21 Mar 2022 23:21:36 +0000 (00:21 +0100)]
man: clarify that type #1 entries are also read from the XBOOTLDR partition
Lennart Poettering [Mon, 21 Mar 2022 23:19:32 +0000 (00:19 +0100)]
man: also install systemd-stub man page as sd-stub
So, typically systemd-boot is referenced as sd-boot, due to te usual
shorter naming in ESP resources. systemd-stub didnt do that so far,
since it never appears as separate files in the ESP. However it's super
annoying that you can find "man sd-boot", but not the very closely
related "man sd-stub". Let's fix that, and also add an "sd-stub" alias
to the "systemd-stub" man page.
Lennart Poettering [Mon, 21 Mar 2022 23:14:22 +0000 (00:14 +0100)]
man: clarify where the settings in type #1 entries are documented
So (maybe weirdly) loader.conf(5) documents both loader.conf and type #1
entries (because they share a similar syntax). But it then only lists
the options of loader.conf. Let's add an explicit hint where to find
the documentation of the type #1 entries.
Lennart Poettering [Mon, 21 Mar 2022 23:13:10 +0000 (00:13 +0100)]
man: clarify the format used by sd-boot config files
Lennart Poettering [Thu, 17 Mar 2022 16:50:23 +0000 (17:50 +0100)]
NEWS: try to fix old entry regarding KERNEL_INSTALL_LAYOUT
The old text was simply wrong, we used to read $layout from
/etc/kernel/install.conf and the machine ID from
$KERNEL_INSTALL_MACHINE_ID from /etc/machine-info. Correct that.
Apparently KERNEL_INSTALL_MACHINE_ID was already known back in v235
times, hence don't mention it anymore.
it's kinda weird retro-fixing these NEWS entries, given we deprecate
them again, but I couldn't let this really incorrect stuff be.
Lennart Poettering [Thu, 17 Mar 2022 16:20:07 +0000 (17:20 +0100)]
kernel-install: list fields we honour in /etc/kernel/install.conf