]> git.ipfire.org Git - thirdparty/systemd.git/log
thirdparty/systemd.git
3 years agovirt: use read_virtual_file() for reading /proc/self/setgroups 22923/head
Lennart Poettering [Thu, 31 Mar 2022 11:28:18 +0000 (13:28 +0200)] 
virt: use read_virtual_file() for reading /proc/self/setgroups

3 years agovirt: simplify userns_has_mapping() by using fscanf() instead of scanf()
Lennart Poettering [Thu, 31 Mar 2022 11:27:21 +0000 (13:27 +0200)] 
virt: simplify userns_has_mapping() by using fscanf() instead of scanf()

And while we are at it, also fix propagation of an uninitialized errno
error.

3 years agocryptsetup: fall back to traditional unlocking if any TPM2 operation fails
Antonio Alvarez Feijoo [Thu, 31 Mar 2022 08:09:29 +0000 (10:09 +0200)] 
cryptsetup: fall back to traditional unlocking if any TPM2 operation fails

If any TPM2 operation fails, the boot process should continue and
prompt for a text password (if configured to do so).

Fixes #22870

3 years agoupdate TODO
Lennart Poettering [Thu, 31 Mar 2022 12:27:13 +0000 (14:27 +0200)] 
update TODO

3 years agoSupport -D_FORTIFY_SOURCE=3 by using __builtin_dynamic_object_size.
Martin Liska [Thu, 31 Mar 2022 08:27:45 +0000 (10:27 +0200)] 
Support -D_FORTIFY_SOURCE=3 by using __builtin_dynamic_object_size.

As explained in the issue, -D_FORTIFY_SOURCE=3 requires usage
of __builtin_dynamic_object_size in MALLOC_SIZEOF_SAFE macro.

Fixes: #22801
3 years agomeson: build kernel-install man page when necessary
Franck Bui [Thu, 31 Mar 2022 09:17:10 +0000 (11:17 +0200)] 
meson: build kernel-install man page when necessary

3 years agoFix "link-local" language inconsistencies
Sebastian Pucilowski [Thu, 31 Mar 2022 05:31:28 +0000 (16:31 +1100)] 
Fix "link-local" language inconsistencies

"Link-local" and "link local" are used throughout man pages and program
output, with the former used far more than the latter. This commit makes
it consistent throughout the project.

3 years agoMerge pull request #22899 from yuwata/network-ignore-carrier-loss
Yu Watanabe [Thu, 31 Mar 2022 02:40:30 +0000 (11:40 +0900)] 
Merge pull request #22899 from yuwata/network-ignore-carrier-loss

network: automatically determine timeout of waiting for carrier regain

3 years agonetwork: shorten code a bit 22899/head
Yu Watanabe [Tue, 29 Mar 2022 16:04:26 +0000 (01:04 +0900)] 
network: shorten code a bit

Currently, there exist only two MTU sources, static and DHCPv4, and they
are exclusive. Hence, it is not necessary to check the existence of the
MTU option in the acquired DHCP lease. Let's unconditionally reset the
MTU. Note that, if the current and original MTU are equivalent, then
link_request_to_set_mtu() handles that gracefully.

3 years agonetwork: automatically determine timeout of waiting for carrier regain
Yu Watanabe [Tue, 29 Mar 2022 15:52:09 +0000 (00:52 +0900)] 
network: automatically determine timeout of waiting for carrier regain

The commit 6706ce2fd2a13df0ae5e469b72d688eaf643dac4 made
IgnoreCarrierLoss= setting also take timespan, to make users handle
issues like #18738 or #20887. But still users needed to explicitly set
a timespan.

This makes networkd automatically determine the timeout when the
situations #18738 or #19832 is detected. Unfortunately, still users have
issue #20887 need to specify a value.

Closes #19832.

3 years agoMerge pull request #22913 from yuwata/sd-device-cleanups
Yu Watanabe [Thu, 31 Mar 2022 00:24:38 +0000 (09:24 +0900)] 
Merge pull request #22913 from yuwata/sd-device-cleanups

sd-device,udev: several cleanups

3 years agoveritysetup: fix parsing of root-hash-signature= option
Zbigniew Jędrzejewski-Szmek [Wed, 30 Mar 2022 07:38:33 +0000 (09:38 +0200)] 
veritysetup: fix parsing of root-hash-signature= option

The function was named confusingly and we managed to confused ourselves. The
parameter was assigned incorrectly and then reassigned correctly in the caller.
Let's simplify the whole thing by just saving the optarg param.

I considered moving the unhexmemming and/or reading of the file to the parse
function, but decided against it. I think it's nicer to parse all options
before opening external files.

3 years agoudev: rename functions to emphasize whole disk is locked 22913/head
Yu Watanabe [Wed, 30 Mar 2022 19:31:46 +0000 (04:31 +0900)] 
udev: rename functions to emphasize whole disk is locked

3 years agoudev: ignore one more error in device_get_block_device()
Yu Watanabe [Wed, 30 Mar 2022 19:26:22 +0000 (04:26 +0900)] 
udev: ignore one more error in device_get_block_device()

3 years agosd-device: do not ignore critical errors in device_new_from_child()
Yu Watanabe [Wed, 30 Mar 2022 19:14:49 +0000 (04:14 +0900)] 
sd-device: do not ignore critical errors in device_new_from_child()

3 years agosd-device: use path_extract_directory() at one more place
Yu Watanabe [Wed, 30 Mar 2022 19:11:30 +0000 (04:11 +0900)] 
sd-device: use path_extract_directory() at one more place

3 years agosd-device: try to get DISKSEQ from uevent file
Yu Watanabe [Wed, 30 Mar 2022 18:27:17 +0000 (03:27 +0900)] 
sd-device: try to get DISKSEQ from uevent file

Otherwise, if the sd-device object is created from e.g. syspath, then
sd_device_get_diskseq() returns -ENOENT.

3 years agosd-device: drop /sys/subsystem support
Yu Watanabe [Mon, 28 Mar 2022 19:04:54 +0000 (04:04 +0900)] 
sd-device: drop /sys/subsystem support

Follow-ups for 37cf83d9bfdd9f6859b6f2654d8ec3bbb17873b2.

3 years agoman: update root-hash-signature option with value
Gaël PORTAY [Thu, 25 Feb 2021 18:02:26 +0000 (13:02 -0500)] 
man: update root-hash-signature option with value

This documents two possible values expected by the option
root-hash-signature for veritytab and veritysetup-generator.

3 years agoudev: do not use sd_event_source_disable_unref() at more places
Yu Watanabe [Wed, 30 Mar 2022 17:04:44 +0000 (02:04 +0900)] 
udev: do not use sd_event_source_disable_unref() at more places

Fixes a bug introduced by 9612da361a825d70a9fd392f3ee5a53bf8896887.

Follow-up for f777e745a7966ea52ef29f9e4edfdd16874cfe86.

3 years agoudev: do not append unknown errno or signal name
Yu Watanabe [Wed, 30 Mar 2022 09:39:50 +0000 (18:39 +0900)] 
udev: do not append unknown errno or signal name

Follow-up for 6467bda59d571696b645e8bbdf31926676890956.

Addresses https://github.com/systemd/systemd/pull/22871#discussion_r837705779.

3 years agoupdate TODO
Lennart Poettering [Wed, 30 Mar 2022 08:45:31 +0000 (10:45 +0200)] 
update TODO

3 years agoci: drop clang 11 & add clang 14
Frantisek Sumsal [Wed, 30 Mar 2022 09:32:31 +0000 (11:32 +0200)] 
ci: drop clang 11 & add clang 14

3 years agofix typo
Yu Watanabe [Wed, 30 Mar 2022 12:10:06 +0000 (21:10 +0900)] 
fix typo

3 years agoNEWS: specify that public headers are still C89
Luca Boccassi [Tue, 29 Mar 2022 20:54:01 +0000 (21:54 +0100)] 
NEWS: specify that public headers are still C89

3 years agoNEWS: mention that C11 is now used
Luca Boccassi [Tue, 29 Mar 2022 20:52:21 +0000 (21:52 +0100)] 
NEWS: mention that C11 is now used

3 years agoNEWS: add entry for the unit enablement stuff v251-rc1
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 18:28:47 +0000 (20:28 +0200)] 
NEWS: add entry for the unit enablement stuff

It should be merged soon.

3 years agotest-systemctl-enable: skip test for %v if kver is not a valid instance
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 20:39:08 +0000 (22:39 +0200)] 
test-systemctl-enable: skip test for %v if kver is not a valid instance

On arm, we'd fail with:
target@v:5.16.8-200.fc35.armv7hl+lpae.socket: not a valid unit name "target@v:5.16.8-200.fc35.armv7hl+lpae.socket": Invalid argument

3 years agotest-copy: use non-0 data block in copy_holes
наб [Tue, 29 Mar 2022 17:43:01 +0000 (19:43 +0200)] 
test-copy: use non-0 data block in copy_holes

Some filesystems (e.g. zfs with compression!=off, which is the default
configuration) automatically hole-punch all-zero blocks ‒ write a block
full of ones instead

3 years agoMerge pull request #22649 from keszybz/symlink-enablement-yet-again-punish-me-harder
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 19:10:03 +0000 (21:10 +0200)] 
Merge pull request #22649 from keszybz/symlink-enablement-yet-again-punish-me-harder

Fixups to the unit enablement logic

3 years agoMerge pull request #22871 from yuwata/udev-worker-error-code
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 19:08:44 +0000 (21:08 +0200)] 
Merge pull request #22871 from yuwata/udev-worker-error-code

udev: append error code on failure

3 years agomeson: bump numbers for v251-rc1
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 17:46:47 +0000 (19:46 +0200)] 
meson: bump numbers for v251-rc1

3 years agoNEWS: update contributor list
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 17:43:54 +0000 (19:43 +0200)] 
NEWS: update contributor list

3 years agotools/git-contrib: list contributions not only from Weblate
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 17:42:01 +0000 (19:42 +0200)] 
tools/git-contrib: list contributions not only from Weblate

It seems that --invert-grep used to affect --author, but now it doesn't (with
git-2.35.1-1.fc36.x86_64), so effectively we would only show the one entry that
was supposed to be filtered out.

3 years agoNEWS: two more small features and some rewordings
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 17:36:29 +0000 (19:36 +0200)] 
NEWS: two more small features and some rewordings

3 years agoFix typos in user-util.c and dbus-unit.c
наб [Tue, 29 Mar 2022 16:32:07 +0000 (18:32 +0200)] 
Fix typos in user-util.c and dbus-unit.c

3 years agotest: add tests for worker error code 22871/head
Yu Watanabe [Tue, 29 Mar 2022 05:58:58 +0000 (14:58 +0900)] 
test: add tests for worker error code

3 years agoudev: append error code in broadcasted message
Yu Watanabe [Fri, 25 Mar 2022 17:01:42 +0000 (02:01 +0900)] 
udev: append error code in broadcasted message

So, libudev listners can easily detect errors.

Addresses https://github.com/systemd/systemd/pull/22717#discussion_r834420878.

3 years agosd-device: introduce device_add_propertyf()
Yu Watanabe [Fri, 25 Mar 2022 17:00:02 +0000 (02:00 +0900)] 
sd-device: introduce device_add_propertyf()

3 years agoNEWS: mention kernel requirement change 3.13 -> 3.15
Luca Boccassi [Tue, 29 Mar 2022 16:22:08 +0000 (17:22 +0100)] 
NEWS: mention kernel requirement change 3.13 -> 3.15

3 years agoMerge pull request #22894 from keszybz/hwdb-update
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 16:17:32 +0000 (18:17 +0200)] 
Merge pull request #22894 from keszybz/hwdb-update

Update hwdb again

3 years agohwdb: update autosuspend entries 22894/head
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 10:22:21 +0000 (12:22 +0200)] 
hwdb: update autosuspend entries

3 years agohwdb: update for v251
Zbigniew Jędrzejewski-Szmek [Thu, 9 Dec 2021 10:05:15 +0000 (11:05 +0100)] 
hwdb: update for v251

As usual, there are mostly additions of new entries, and some spelling
correction and company renames, no big removals.

3 years agohwdb: fix parser to work with newer pyparsing
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 10:17:51 +0000 (12:17 +0200)] 
hwdb: fix parser to work with newer pyparsing

The handling of whitespace in pyparsing is a bother. There's some
global state, and per-element state, and it's hard to get a handle on
things. With python3-pyparsing-2.4.7-10.fc36.noarch the grammar would
not match. After handling of tabs was fixed to not accept duplicate tabs,
the grammar passes.

It seems that the entry for usb:v8087p8087*
was generated incorrectly because we treated the interface line
(with two TABs) as a device line (with one TAB).

3 years agocryptsetup: shorten message a bit
Zbigniew Jędrzejewski-Szmek [Fri, 25 Mar 2022 09:54:39 +0000 (10:54 +0100)] 
cryptsetup: shorten message a bit

If it is reported as missing, we don't need to say that we assume
it is missing.

3 years agoMerge pull request #22843 from poettering/bootspec-json
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 16:11:32 +0000 (18:11 +0200)] 
Merge pull request #22843 from poettering/bootspec-json

bootctl: bootspec improvements and clean-ups

3 years agoRename UnitFileScope to LookupScope 22649/head
Zbigniew Jędrzejewski-Szmek [Tue, 29 Mar 2022 13:55:59 +0000 (15:55 +0200)] 
Rename UnitFileScope to LookupScope

As suggested in
https://github.com/systemd/systemd/pull/22649/commits/8b3ad3983f5440eef812b34e5ed862ca59fdf7f7#r837345892

The define is generalized and moved to path-lookup.h, where it seems to fit
better. This allows a recursive include to be removed and in general makes
things simpler.

3 years agotest-systemctl-enable: disable the test for %a for now
Zbigniew Jędrzejewski-Szmek [Mon, 28 Mar 2022 18:20:09 +0000 (20:20 +0200)] 
test-systemctl-enable: disable the test for %a for now

3 years agotest-systemctl-enable: also use freshly-built systemd-id128
Zbigniew Jędrzejewski-Szmek [Mon, 28 Mar 2022 18:03:37 +0000 (20:03 +0200)] 
test-systemctl-enable: also use freshly-built systemd-id128

Tests were failing on centos7 because systemd-id128 is not in path.

3 years agotest-systemctl-enable: use magic syntax to allow inverted tests
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.

3 years agoshared/install: when creating symlinks, accept different but equivalent symlinks
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.)

3 years agotest-systemctl-enable: make shellcheck happy
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.

3 years agoshared/install: fix handling of a linked unit file
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.

3 years agoshared/install: split UNIT_FILE_SYMLINK into two states
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.

3 years agobasic/unit-file: reverse negative conditional
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.

3 years agoshared/install: stop passing duplicate root argument to install_name_printf()
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.

3 years agoshared/install: when looking for symlinks in .wants/.requires, ignore symlink target
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.

3 years agoshared/install: create relative symlinks for enablement and aliasing
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.

3 years agoshared/install: also remove symlinks like .wants/foo@one.service → ../foo@one.service
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

3 years agoshared/install: skip unnecessary chasing of symlinks in disable
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.

3 years agotest-systemctl-enable: enhance the test for unit file linking
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.

3 years agoshared/install: do not try to resolve symlinks outside of root directory
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.

3 years agoshared/install: when we fail to chase a symlink, show some logs
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.

3 years agotest-systemctl-enable: extend the test for repeated WantedBy/RequiredBy
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.

3 years agoshared/install: fix reenable on linked unit files
Zbigniew Jędrzejewski-Szmek [Tue, 15 Mar 2022 08:44:39 +0000 (09:44 +0100)] 
shared/install: fix reenable on linked unit files

3 years agoshared/install: split unit_file_{disable,enable}() so _reenable doesn't do setup...
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.

3 years agoinstall: when linking a file, create the link first or abort
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.

3 years agoman: fix invalid description of template handling in WantedBy=
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.

3 years agoshared/install: also check for self-aliases during installation and ignore them
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.

3 years agosystemctl: fix silent failure when --root is not found
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.

3 years agoshared/install: return failure when enablement fails, but process as much as possible
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.

3 years agoshared/install: propagate errors about invalid aliases and such too
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.

3 years agoshared/install: simplify unit_file_dump_changes()
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.

3 years agoshared/specifier: fix %u/%U/%g/%G when called as unprivileged user
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.

3 years agoshared/install: move scope into InstallContext
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.

3 years agoshared/install: provide proper error messages when invalid specifiers are used
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".

3 years agoshared/specifier: provide proper error messages when specifiers fail to read files
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".

3 years agoshared/specifier: clarify and add test for missing data
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.

3 years agoman/os-release: add a note about repeating entries
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.

3 years agobasic/env-file: make load-env-file deduplicate entries with the same key
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.

3 years agotest-os-util: add basic tests for os-release parsing
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

3 years agobasic: add new variable $SYSTEMD_OS_RELEASE to override location of os-release
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.

3 years agoman: clarify the descriptions of aliases and linked unit files
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.

3 years agotests: add helper for creating tempfiles with content
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.

3 years agotest: add test for systemctl link & enable
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.

3 years agoshared/install: add a bit more quoting
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.

3 years agoshared/install: reuse the standard symlink verification subroutine
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.

3 years agobasic/stat-util: add null_or_empty_path_with_root()
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()

3 years agoportable: allow reattaching when one image has a version and the other does not
Luca Boccassi [Wed, 23 Mar 2022 21:29:04 +0000 (21:29 +0000)] 
portable: allow reattaching when one image has a version and the other does not

A reattach might go from img.raw to img_0.1.raw or viceversa, but this is
not allowed right now as we try to match the full name.

Also take into account that running strcspn(a, '/') on an image name, without
leading path, will return the length of the full string, but the versions
might be different so they won't match, eg:

img_0.1.raw -> 12
img_0.1.1.raw -> 14

So adjust the check to take that into account, and skip it if we are not
dealing with directories

3 years agohwdb: Add mic mute key mapping for HP Elite x360
Andy Chi [Tue, 29 Mar 2022 07:36:13 +0000 (15:36 +0800)] 
hwdb: Add mic mute key mapping for HP Elite x360

On the new Elite x360 2 in 1 HP laptops, the microphone mute hotkey is "Fn+F8" and
the scancode for this hotkey is 0x81, but this scancode was mapped to
fn_esc in the HP generic keymap section. To fix this problem, we add
a machine specific keymap section to add the correct keymap rule.

3 years agobasic/unit-file: split out the subroutine for symlink verification
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.

3 years agoudev: do not call sd_event_source_disable_unref() in workers for event sources create...
Yu Watanabe [Tue, 29 Mar 2022 03:14:40 +0000 (12:14 +0900)] 
udev: do not call sd_event_source_disable_unref() in workers for event sources created by the main process

Fixes a bug introduced by 9612da361a825d70a9fd392f3ee5a53bf8896887.

3 years agoinotify-util: fix wrong warnings in FOREACH_INOTIFY_EVENT()
Yu Watanabe [Fri, 25 Mar 2022 06:34:29 +0000 (15:34 +0900)] 
inotify-util: fix wrong warnings in FOREACH_INOTIFY_EVENT()

Follow-up for 00adc340bb15bc9d634db6caa48f1c964b99f79a.

This fixes the wrong "Received invalid inotify event, ignoring." warnings
caused by the missing curly brackets and the priorities of `&&` and `?:`.

This also replaces the ternary operators with `||`.

3 years agobuild: include status of TPM2 in the feature string show by --version
Franck Bui [Mon, 28 Mar 2022 12:59:59 +0000 (14:59 +0200)] 
build: include status of TPM2 in the feature string show by --version

3 years agoMerge pull request #22885 from poettering/kill-clock-boottime-or-monotonic
Yu Watanabe [Mon, 28 Mar 2022 18:06:54 +0000 (03:06 +0900)] 
Merge pull request #22885 from poettering/kill-clock-boottime-or-monotonic

time-util: assume CLOCK_BOOTTIME always exists

3 years agoveritysetup: fix typo (#22886)
Gaël PORTAY [Mon, 28 Mar 2022 17:09:36 +0000 (13:09 -0400)] 
veritysetup: fix typo (#22886)

3 years agofix typo
Yu Watanabe [Mon, 28 Mar 2022 16:21:51 +0000 (01:21 +0900)] 
fix typo

3 years agoUpdate NEWS
Yu Watanabe [Mon, 28 Mar 2022 16:19:13 +0000 (01:19 +0900)] 
Update NEWS

- categorize entries
- add several news for networkd and udevd

3 years agotime-util: assume CLOCK_BOOTTIME always exists 22885/head
Lennart Poettering [Mon, 28 Mar 2022 14:41:10 +0000 (16:41 +0200)] 
time-util: assume CLOCK_BOOTTIME always exists

Let's raise our supported baseline a bit: CLOCK_BOOTTIME started to work
with timerfd in kernel 3.15 (i.e. back in 2014), let's require support
for it now.

This will raise our baseline only modestly from 3.13 → 3.15.

3 years agonetwork: rename netdev kind virtual-wlan -> wlan
Yu Watanabe [Mon, 28 Mar 2022 07:23:19 +0000 (16:23 +0900)] 
network: rename netdev kind virtual-wlan -> wlan

The Kind= setting in [Match] section of .network files takes "wlan".
This makes the same setting in .netdev files matches the one in .network
files.