]> git.ipfire.org Git - thirdparty/systemd.git/log
thirdparty/systemd.git
2 years agotest: abstract the common test parts into a utility script 27603/head
Frantisek Sumsal [Wed, 10 May 2023 19:12:01 +0000 (21:12 +0200)] 
test: abstract the common test parts into a utility script

Also, instead of bailing out on the first failed subtest, always run all
subtests and print a summary at the end (with an appropriate exit code).

2 years agotest: merge TEST-20-MAINPIDGAMES into TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 18:17:19 +0000 (20:17 +0200)] 
test: merge TEST-20-MAINPIDGAMES into TEST-07-PID1

2 years agotest: merge TEST-51-ISSUE-16115 into TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 12:26:08 +0000 (14:26 +0200)] 
test: merge TEST-51-ISSUE-16115 into TEST-07-PID1

2 years agotest: merge TEST-47-ISSUE-14566 into TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 12:19:40 +0000 (14:19 +0200)] 
test: merge TEST-47-ISSUE-14566 into TEST-07-PID1

2 years agotest: move TEST-23's units into a dedicated subfolder
Frantisek Sumsal [Wed, 10 May 2023 12:02:54 +0000 (14:02 +0200)] 
test: move TEST-23's units into a dedicated subfolder

To remain consistent with other tests.

2 years agotest: merge TEST-12-ISSUE-3171 into TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 11:58:13 +0000 (13:58 +0200)] 
test: merge TEST-12-ISSUE-3171 into TEST-07-PID1

2 years agotest: merge TEST-11-ISSUE-3166 into TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 11:49:34 +0000 (13:49 +0200)] 
test: merge TEST-11-ISSUE-3166 into TEST-07-PID1

2 years agotest: merge TEST-10-ISSUE-2467 with TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 11:41:03 +0000 (13:41 +0200)] 
test: merge TEST-10-ISSUE-2467 with TEST-07-PID1

2 years agotest: merge TEST-09-ISSUE-2691 into TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 11:13:12 +0000 (13:13 +0200)] 
test: merge TEST-09-ISSUE-2691 into TEST-07-PID1

2 years agotest: merge TEST-08-ISSUE-2730 into TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 11:07:26 +0000 (13:07 +0200)] 
test: merge TEST-08-ISSUE-2730 into TEST-07-PID1

2 years agotest: rename TEST-07-ISSUE-1981 to TEST-07-PID1
Frantisek Sumsal [Wed, 10 May 2023 10:38:57 +0000 (12:38 +0200)] 
test: rename TEST-07-ISSUE-1981 to TEST-07-PID1

2 years agodirent: conditionalize dirent assert based on dirent64 existence
Sam James [Wed, 10 May 2023 00:47:13 +0000 (01:47 +0100)] 
dirent: conditionalize dirent assert based on dirent64 existence

>=musl-1.2.4 doesn't define dirent64 and its LFS friends as its "native"
functions are already LFS-aware.

Check for dirent64 in meson.build and only assert if it exists.

Bug: https://bugs.gentoo.org/905900
Closes: https://github.com/systemd/systemd/pull/25809
2 years agonetwork/tc: rename settings in log messages too
Mike Yuan [Tue, 9 May 2023 16:15:14 +0000 (00:15 +0800)] 
network/tc: rename settings in log messages too

Follow-up for c03ef420fa7157b8d4881636fe72596a06e08bb6

2 years agosd-bus: bus_message_type_from_string is not pure
Xi Ruoyao [Tue, 9 May 2023 17:41:28 +0000 (01:41 +0800)] 
sd-bus: bus_message_type_from_string is not pure

GCC document [1] says:

    The pure attribute prohibits a function from modifying the state
    of the program that is observable by means other than inspecting
    the function’s return value.

And there is an example:

    `int hash (char *) __attribute__ ((pure));`
    ... Even though hash takes a non-const pointer argument it must
    not modify the array it points to, ...

But we are modifying the object pointed to by the pointer u, which is
clearly a violation of the semantic of pure.

With -ftrivial-auto-var-init (enabled by -Dmode=release), on some
targets (GCC 12.2 on AArch64 and GCC 13.1 on x86_64) performs an
optimization: as the variable "u" in bus_match_parse has been
zero-initialized (by the -ftrivial-auto-var-init option) and never
modified (because a "pure" bus_message_type_from_string is not allowed
to modify it), "u" will be always 0.

Then 0 is used to initialize .value_u8 field of struct
bus_match_component.  This then causes a infinite event loop, so
"systemctl restart" never stops, and pam_systemd timeouts communicating
with logind, etc.

So we should remove the "pure" attribute here.

Fixes #26395.

[1]:https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-pure-function-attribute

2 years agoMerge pull request #27597 from mrc0mmand/more-test-shenanigans
Yu Watanabe [Tue, 9 May 2023 23:16:29 +0000 (08:16 +0900)] 
Merge pull request #27597 from mrc0mmand/more-test-shenanigans

test: slightly extend systemd-cryptenroll coverage

2 years agocore/mount: replace invalid UTF-8 code points in "what" and "options"
Michal Sekletar [Fri, 5 May 2023 10:50:15 +0000 (12:50 +0200)] 
core/mount: replace invalid UTF-8 code points in "what" and "options"

Previously, these strings were copied w/o any modification. However, if
mount table contained e.g. remote fs mount like NFS or CIFS that was
mounted from server running with non UTF-8 locale then those strings
might have contained some non UTF-8 characters.

If then client asked about status of such mount unit we tried to forward
these non UTF-8 strings over D-Bus. That is the violation of the
protocol and we ended up kicked from the bus.

2 years agotest: slightly extend systemd-cryptenroll coverage 27597/head
Frantisek Sumsal [Tue, 9 May 2023 20:47:42 +0000 (22:47 +0200)] 
test: slightly extend systemd-cryptenroll coverage

2 years agocryptenroll: fix an assertion with weak passwords
Frantisek Sumsal [Tue, 9 May 2023 20:17:15 +0000 (22:17 +0200)] 
cryptenroll: fix an assertion with weak passwords

Passing 0 to log_xxx_errno() leads to an assertion, so let's not do that:

$ NEWPASSWORD="" build-san/systemd-cryptenroll --unlock-key-file=/tmp/password --password "$img"
/tmp/password has 0644 mode that is too permissive, please adjust the ownership and access mode.
Assertion '(_error) != 0' failed at src/cryptenroll/cryptenroll-password.c:164, function enroll_password(). Aborting.
Aborted (core dumped)

2 years agotest: TEST-70-TPM2 cleanup
Frantisek Sumsal [Tue, 9 May 2023 19:14:24 +0000 (21:14 +0200)] 
test: TEST-70-TPM2 cleanup

No functional changes.

2 years agotest: add coverage for #27533
Frantisek Sumsal [Tue, 9 May 2023 17:59:13 +0000 (19:59 +0200)] 
test: add coverage for #27533

Issue: https://github.com/systemd/systemd/issues/27533
Fix: https://github.com/systemd/systemd/pull/27553

2 years agotest: discard kill's output
Frantisek Sumsal [Tue, 9 May 2023 17:55:04 +0000 (19:55 +0200)] 
test: discard kill's output

2 years agotest: merge unit file related tests into TEST-23-UNIT-FILE
Frantisek Sumsal [Mon, 8 May 2023 20:38:34 +0000 (22:38 +0200)] 
test: merge unit file related tests into TEST-23-UNIT-FILE

Rename TEST-23-TYPE-EXEC to TEST-23-UNIT-FILE and merge it with
following tests:
  - TEST-37-RUNTIMEDIRECTORYPRESERV
  - TEST-40-EXEC-COMMAND-EX
  - TEST-41-ONESHOT-RESTART
  - TEST-42-EXECSTOPPOST
  - TEST-57-ONSUCCESS-UPHOLD

2 years agounits: Add CAP_NET_ADMIN condition to systemd-networkd-wait-online@.service as well
Daan De Meyer [Sun, 7 May 2023 08:49:57 +0000 (10:49 +0200)] 
units: Add CAP_NET_ADMIN condition to systemd-networkd-wait-online@.service as well

It was added to CAP_NET_ADMIN but we forgot to add it to the template
service as well.

2 years agosd-dhcp-client: client ID always has non-zero data
Yu Watanabe [Tue, 9 May 2023 08:57:33 +0000 (17:57 +0900)] 
sd-dhcp-client: client ID always has non-zero data

Follow-up for f04c991a2fbb3531c3b464ed8e6dd7543e521f7a.
Fixes CID#1510978.

2 years agoMerge pull request #27534 from keszybz/deperlify
Yu Watanabe [Tue, 9 May 2023 09:06:51 +0000 (18:06 +0900)] 
Merge pull request #27534 from keszybz/deperlify

Rewrite udev-test.pl in Python

2 years agomkosi,ci: do not install perl 27534/head
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 11:50:50 +0000 (13:50 +0200)] 
mkosi,ci: do not install perl

2 years agotest: use sed and grep instead of perl
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 11:43:03 +0000 (13:43 +0200)] 
test: use sed and grep instead of perl

This gets rid of the all-but-one remaining uses of perl. I tested the new code
on my machine, so I'm fairly confident that it works as expected.

install_iscsi() has one majestic perl invocation, but we can't get rid of it
easily: it extends the code of tgt-admin to print some list of files. Obviously
this only works because tgt-admin is written in perl, and perl will be installed
if tgt-admin is installed. install_iscsi() is used in TEST-64-UDEV-STORAGE
conditionally if tgtadm is installed, so this can stay as is.

2 years agotools/oss-fuzz: s/perl/awk/
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 10:48:37 +0000 (12:48 +0200)] 
tools/oss-fuzz: s/perl/awk/

The pattern is not exactly the same, but I don't think we need to
be super-precise here.

2 years agotest-execute: use bash instead of perl
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 10:24:37 +0000 (12:24 +0200)] 
test-execute: use bash instead of perl

I think this is easier to grok too.

2 years agotest-udev: skip test on python3.6
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 09:38:25 +0000 (11:38 +0200)] 
test-udev: skip test on python3.6

2 years agoREADME: require python >= 3.7, clean up module descriptions
Zbigniew Jędrzejewski-Szmek [Sun, 7 May 2023 09:16:21 +0000 (11:16 +0200)] 
README: require python >= 3.7, clean up module descriptions

libpython was added in 2cc86f094a8c316f7feb0336df3827a3264b116d, it seems
because of python-systemd module that we built. But libpython by itself
is not enough for actual python programs, and now we also list python itself,
so let's drop libpython from the list.

meson requires >= 3.7. We have CI that runs on CentOS8 with Python 3.6, but
let's not provide official support for an EOL Python version. Individual
distributions can provide backports, but we don't need to mention that in
the user-facing docs. According to [1], 3.7 is on life support and 3.6 is EOL.

[1] https://devguide.python.org/versions/

2 years agotools/check-includes: compat with Python 3.7
Zbigniew Jędrzejewski-Szmek [Sun, 7 May 2023 09:01:33 +0000 (11:01 +0200)] 
tools/check-includes: compat with Python 3.7

I thought that 3.8 is enough. But Centos8 CI chokes on the walrus.

2 years agotest/run-unit-tests, TEST-02: skip tests where the interpeter is not installed
Zbigniew Jędrzejewski-Szmek [Sat, 6 May 2023 09:49:31 +0000 (11:49 +0200)] 
test/run-unit-tests, TEST-02: skip tests where the interpeter is not installed

When the interpeter is missing, we get an exit code of 127. Let's treat those
tests as skipped too. If we could run the test far enough so that it could do
the check itself, it would return 77 anyway.

$ test/asdf; echo $?
exec: Failed to execute process 'test/asdf': The file specified the interpreter '/bin/asdf', which is not an executable command.
127
$ test/asdf; echo $?
/usr/bin/env: ‘/bin/asdf’: No such file or directory
127

This should resolve the problem that TEST-02 fails or Debian's 'unit-tests' fail
when python3 is not installed. Installing python3 via the mechanism that is
used to construct TEST images, i.e. the dracut dependency chasing scheme, would
be a lot of work for python with its modules in multiple locations and hundreds
of little files. So I think it OK to just skip the test there, and also in
other cases where python is not available.

2 years agotest: rework how udev-test is invoked
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 12:46:34 +0000 (14:46 +0200)] 
test: rework how udev-test is invoked

As part of the build, we would populate build/test/sys/ using
sys-script.py, and then udev-test.p[ly] would create a tmpfs instance
on build/test/tmpfs and copy the sys tree to build/test/tmpfs/sys.

Also, we had udev-test.p[ly] which called test-udev. test-udev was
marked as a manual test and installed, but neither udev-test.p[ly] or
sys-script.py were.

test-udev is renamed to udev-rule-runner, which reduces confusion and
frees up the test-udev name. udev-test.py is renamed to test-udev.py.
All three files are now installed.

test-udev.py is modified to internally call sys-script.py to set up the
sys tree. Copying and creating it from scratch should take the same
amount of time. We avoid having a magic directory, everything is now
done underneath a temporary directory.

test-udev.py is now a normal installed test, and run-unit-tests.py will
pick it up. When test-udev.py is invoked from meson, the path to
udev-rule-runner is passed via envvar; when it is invoked via
run-unit-tests.py or directly, it looks for udev-rule-runner in a relative
path.

The goal of this whole change is to let Debian drop the 'udev' test.
It called sys-script.py and udev-test.pl from the source directory and
had to recreate a bunch of the logic. Now test-udev.py will now be called
via 'upstream'.

2 years agotest: drop udev-test.pl
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 06:49:18 +0000 (08:49 +0200)] 
test: drop udev-test.pl

2 years agotest: rewrite udev-test.pl in Python
Zbigniew Jędrzejewski-Szmek [Thu, 4 May 2023 20:40:38 +0000 (22:40 +0200)] 
test: rewrite udev-test.pl in Python

I tried to keep this a 1:1 rewrite with the same field names.
Nevertheless, some changes were made:
- exp_add_error and exp_rem_error are dropped. Those fields meant that
  "./test-udev add <devpath>" actually succeeded, but symlinks were not
  created, and exp_links was ignored and could contain bogus content.
  Instead, exp_links and not_exp_links are adjusted to not contain
  garbage and the tests check that "./test-udev add" succeeds and that
  the links are as expected from exp_links and not_exp_links.
- cleanup was only used in one rule, and that rule was expected to fail,
  so cleanup wasn't actually necessary. So the cleanup field and the
  logic to call cleanup from individual tests is removed.
- a bunch of fields were set, but didn't seem to be connected to any
  implementation: not_exp_name, not_exp_test.
  e62acc3159935781f05fa59c48e5a74e85c61ce2 did a rewrite of some of the
  tests and it seems that not_exp_test was added by mistake and
  not_exp_name was left behind by mistake.
  In Python, the field list is declared in the class, so it's harder to
  assign an unused attribute. Those uses were converted to not_exp_links.
- in most rules, r"""…""" is used, so that escaping is not necessary.
- the logic to generate devices was only used in one place, and the
  generator function also had provisions to handle arguments that were
  never given. all_block_devs() is made much simpler.
- Descriptions that started with a capital letter were shortened
  and lowercased.
- no special test case counting is done. pytest just counts the cases
  (Rules objects).
- the output for failures is also removed. If something goes wrong, the
  user can use pytest --pdb or such to debug the issue.
- perl version used a semaphore to manage udev runners, and would fork,
  optionally wait a bit, and then start the runner. In the python
  version, we just spawn them all and wait for them to exit. It's not
  very convenient to call fork() from python, so instead the runner
  was modified (in previous commit) to wait.

The test can be called as:
  (cd build && sudo pytest -v ../test/udev-test.py)
  sudo meson test -C build udev-test.py -v

I think this generally provides functionality that is close to the perl
version. It seems some of the checks are now more fully implemented.
Support for strace/gdb/valgrind is missing.

Runtime goes down: 8.36 s → 5.78 s.

2 years agocheck-includes: print path relative to project root
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 07:38:15 +0000 (09:38 +0200)] 
check-includes: print path relative to project root

Instead of /home/zbyszek/src/systemd-work/build/../src/xdg-autostart-generator/xdg-autostart-service.h:11,
print just src/xdg-autostart-generator/xdg-autostart-service.h:11.

This is a bit annoying that this requires so much verbosity, but the output
with the full names was too annoying.

2 years agomeson: fix indentation
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 07:36:00 +0000 (09:36 +0200)] 
meson: fix indentation

2 years agomeson: add check-includes test to the test suite
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 07:35:54 +0000 (09:35 +0200)] 
meson: add check-includes test to the test suite

Let's just call it always. It is quite fast (meson says 0.12 s).

2 years agomeson: include .cc files in tags too
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 07:33:12 +0000 (09:33 +0200)] 
meson: include .cc files in tags too

We only have one, but it seems reasonable to not exclude it.
Result tested with emacs.

2 years agoRewrite check-includes.pl in python
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 07:03:12 +0000 (09:03 +0200)] 
Rewrite check-includes.pl in python

2 years agopid1: drop duplicate include
Zbigniew Jędrzejewski-Szmek [Fri, 5 May 2023 06:54:01 +0000 (08:54 +0200)] 
pid1: drop duplicate include

2 years agotest_ukify: print message when skipping whole test file
Zbigniew Jędrzejewski-Szmek [Thu, 4 May 2023 20:54:41 +0000 (22:54 +0200)] 
test_ukify: print message when skipping whole test file

2 years agotest-udev: add an optional timeout argument
Zbigniew Jędrzejewski-Szmek [Thu, 4 May 2023 20:43:54 +0000 (22:43 +0200)] 
test-udev: add an optional timeout argument

The tests wants to call some workers with a delay. This implements the delay
directly in test-udev so that the caller can be simplified.

Note that the argument is to be used by the other test file, so this is
purposefully implemented in a simple way.

2 years agobus-util: drop unnecessary continue
Yu Watanabe [Mon, 8 May 2023 19:02:54 +0000 (04:02 +0900)] 
bus-util: drop unnecessary continue

2 years agounits: add/fix Documentation= about bus interface
Yu Watanabe [Mon, 8 May 2023 19:01:34 +0000 (04:01 +0900)] 
units: add/fix Documentation= about bus interface

2 years agotest-journal-verify: Use a more thorough machine ID check
Daan De Meyer [Sat, 6 May 2023 09:34:34 +0000 (11:34 +0200)] 
test-journal-verify: Use a more thorough machine ID check

Let's not only check if the file exists but also check if it contains
a valid machine ID.

2 years agoMerge pull request #27579 from YHNdnzj/refuse-dbus-activation
Yu Watanabe [Mon, 8 May 2023 21:09:25 +0000 (06:09 +0900)] 
Merge pull request #27579 from YHNdnzj/refuse-dbus-activation

core: refuse dbus activation if dbus is not running

2 years agoMerge pull request #27578 from yuwata/sd-dhcp-client-client-id-len
Yu Watanabe [Mon, 8 May 2023 21:08:32 +0000 (06:08 +0900)] 
Merge pull request #27578 from yuwata/sd-dhcp-client-client-id-len

sd-dhcp-client: several cleanups for client_id_len

2 years agocore/service: fix error cause in the log
Yu Watanabe [Mon, 8 May 2023 15:21:20 +0000 (00:21 +0900)] 
core/service: fix error cause in the log

Fixes a bug caused by a5648b809457d120500b2acb18b31e2168a4817a.
Fixes #27575.

2 years agoMerge pull request #27553 from yuwata/sd-journal-generic-array-bisect
Daan De Meyer [Mon, 8 May 2023 18:29:24 +0000 (20:29 +0200)] 
Merge pull request #27553 from yuwata/sd-journal-generic-array-bisect

sd-journal: several fixes for generic_array_bisect()

2 years agocore: refuse dbus activation if dbus is not running 27579/head
Mike Yuan [Mon, 8 May 2023 16:07:45 +0000 (00:07 +0800)] 
core: refuse dbus activation if dbus is not running

dbus-broker issues StartUnit directly for activation requests,
so let's add a check on bus state in bus_unit_queue_job to refuse
that if dbus is not running.

Replaces #27570
Closes #26799

2 years agocore/manager: export manager_dbus_is_running
Mike Yuan [Mon, 8 May 2023 15:10:07 +0000 (23:10 +0800)] 
core/manager: export manager_dbus_is_running

2 years agotest-specifier: Ignore -ENOPKG from specifier_printf()
Daan De Meyer [Sat, 6 May 2023 09:33:22 +0000 (11:33 +0200)] 
test-specifier: Ignore -ENOPKG from specifier_printf()

If /etc/machine-id contains "uninitialized", specifier_printf() with
%m will fail with ENOPKG, so ignore that error as well.

2 years agoshell completion: add timesync-status and show-timesync to zsh completion file (...
Marko Korhonen [Mon, 8 May 2023 16:01:16 +0000 (19:01 +0300)] 
shell completion: add timesync-status and show-timesync to zsh completion file (#27574)

Fixes #27560

2 years agosd-dhcp-client: do not use implicit cast to boolean 27578/head
Yu Watanabe [Mon, 8 May 2023 15:37:29 +0000 (00:37 +0900)] 
sd-dhcp-client: do not use implicit cast to boolean

2 years agosd-dhcp-client: make return arguments for sd_dhcp_client_get_client_id() optional
Yu Watanabe [Mon, 8 May 2023 15:34:06 +0000 (00:34 +0900)] 
sd-dhcp-client: make return arguments for sd_dhcp_client_get_client_id() optional

2 years agosd-dhcp-client: drop redundant condition
Yu Watanabe [Mon, 8 May 2023 15:27:22 +0000 (00:27 +0900)] 
sd-dhcp-client: drop redundant condition

Closes #27561.

2 years agonulstr-util: make ret_size in strv_make_nulstr() optional
Yu Watanabe [Mon, 8 May 2023 11:06:33 +0000 (20:06 +0900)] 
nulstr-util: make ret_size in strv_make_nulstr() optional

2 years agoMerge pull request #27569 from keszybz/mkosi-nicer-output
Daan De Meyer [Mon, 8 May 2023 13:37:22 +0000 (15:37 +0200)] 
Merge pull request #27569 from keszybz/mkosi-nicer-output

Prettification for mkosi build output

2 years agodoc: remove legacy DefaultControlGroup from dbus properties
Miao Wang [Mon, 8 May 2023 11:44:09 +0000 (19:44 +0800)] 
doc: remove legacy DefaultControlGroup from dbus properties

DefaultControlGroup does not exist any more.

2 years agomkosi.build: print important build commands 27569/head
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 13:03:24 +0000 (15:03 +0200)] 
mkosi.build: print important build commands

This undoes the effect of 1394a3ec351048bae008627a0775d1f9a6c46294 partially.
We print the fairly verbose output of the build commands, so let's also
print the commands themselves. This makes it much easier to understand what
is going on.

(The style was copied from other scripts where we do 'set -x' for one command.)

2 years agomkosi/fedora: silence warning about sysusers config mismatch
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 12:40:39 +0000 (14:40 +0200)] 
mkosi/fedora: silence warning about sysusers config mismatch

2 years agomkosi.build: use bash, use array for configuration options, shellcheckify
Zbigniew Jędrzejewski-Szmek [Mon, 8 May 2023 12:24:20 +0000 (14:24 +0200)] 
mkosi.build: use bash, use array for configuration options, shellcheckify

With bash, we can use an array for options. This is nice because we can
construct the commandline more easily. The file is now shellcheck-clean.

2 years agocore/unit: check the validity of unit type with activation_details_vtable
Yu Watanabe [Sat, 6 May 2023 05:27:02 +0000 (14:27 +0900)] 
core/unit: check the validity of unit type with activation_details_vtable

Follow-up for 24e91e08f8958241195f97472353adef94884b33.

2 years agoparse-util: make parse_fd() return -EBADF
Yu Watanabe [Sat, 6 May 2023 05:11:08 +0000 (14:11 +0900)] 
parse-util: make parse_fd() return -EBADF

The previous error code -ERANGE is slightly ambiguous, and use more
specific one. This also drops unnecessary error handlings.

Follow-up for 754d8b9c330150fdb3767491e24975f7dfe2a203 and
e652663a043cb80936bb12ad5c87766fc5150c24.

2 years agozsh: add service-log-{level,target} completions for systemctl
Ronan Pigott [Sun, 7 May 2023 21:08:29 +0000 (14:08 -0700)] 
zsh: add service-log-{level,target} completions for systemctl

2 years agohwdb: add landscape IdeaPad Miix 310 sensor orientation (#27555)
Janne Sirén [Sun, 7 May 2023 00:18:55 +0000 (03:18 +0300)] 
hwdb: add landscape IdeaPad Miix 310 sensor orientation (#27555)

Enables support for landscape orientated display variants of the IdeaPad Miix 310 2-in-1 laptop.

2 years agocrypttab: Support for VeraCrypt PIM and detached headers for TrueCrypt/VeraCrypt...
Klaus Zipfel [Sat, 6 May 2023 20:55:05 +0000 (22:55 +0200)] 
crypttab: Support for VeraCrypt PIM and detached headers for TrueCrypt/VeraCrypt (#27548)

* Added veracrypt-pim=<PIM> LUKS option for crypttab

2 years agoMerge pull request #26357 from ddstreet/tpm2_policy_session
Luca Boccassi [Sat, 6 May 2023 16:02:26 +0000 (17:02 +0100)] 
Merge pull request #26357 from ddstreet/tpm2_policy_session

Tpm2 policy session

2 years agosd-journal: split out generic_array_bisect_one() from generic_array_bisect() 27553/head
Yu Watanabe [Sat, 6 May 2023 15:19:24 +0000 (00:19 +0900)] 
sd-journal: split out generic_array_bisect_one() from generic_array_bisect()

This also makes journal corruption always handled gracefully, and drop
potentially unsatisfied assertion on corrupted journal.

Fixes #27533.

2 years agosd-journal: re-read entry array object
Yu Watanabe [Sat, 6 May 2023 15:16:30 +0000 (00:16 +0900)] 
sd-journal: re-read entry array object

`test_object()` may call `journal_file_move_to_object()` and thus
the `array` object may be invalidated.

2 years agosd-journal: drop unnecessary initialization
Yu Watanabe [Sat, 6 May 2023 15:15:49 +0000 (00:15 +0900)] 
sd-journal: drop unnecessary initialization

2 years agosd-journal: rebreak comments
Yu Watanabe [Sat, 6 May 2023 15:23:44 +0000 (00:23 +0900)] 
sd-journal: rebreak comments

2 years agosd-journal: fix comment
Yu Watanabe [Sat, 6 May 2023 15:15:28 +0000 (00:15 +0900)] 
sd-journal: fix comment

2 years agoMerge pull request #27262 from keszybz/ukify-install
Zbigniew Jędrzejewski-Szmek [Sat, 6 May 2023 11:34:08 +0000 (13:34 +0200)] 
Merge pull request #27262 from keszybz/ukify-install

Add kernel-install plugin that calls ukify

2 years agohwdb: do not include '#' in modalias
Yu Watanabe [Sat, 6 May 2023 05:36:19 +0000 (14:36 +0900)] 
hwdb: do not include '#' in modalias

Follow-up for 7bd3d6e35a6de8b1bf93e2fae28a64f0c7ffd2ac.
Fixes #27516.

2 years agoMerge pull request #27527 from mrc0mmand/fuzz-manager-serialize
Luca Boccassi [Sat, 6 May 2023 00:53:26 +0000 (01:53 +0100)] 
Merge pull request #27527 from mrc0mmand/fuzz-manager-serialize

core: a couple of follow-ups for issues found by fuzz-manager-serialize

2 years agotpm2: move policy building out of policy session creation 26357/head
Dan Streetman [Wed, 7 Dec 2022 16:23:59 +0000 (11:23 -0500)] 
tpm2: move policy building out of policy session creation

This retains the use of policy sessions instead of trial sessions
in most cases, based on the code comment that some TPMs do not
implement trial sessions correctly. However, it's likely that the
issue was not the TPMs, but our code's incorrect use of PolicyPCR
inside a trial session; we are not providing expected PCR values
with our call to PolicyPCR inside a trial session, but the spec
indicates that in a trial session, the TPM *may* return error if
the expected PCR value(s) are not provided. That may have been the
source of the original confusion about trial sessions.

More details:
https://github.com/systemd/systemd/pull/26357#pullrequestreview-1409983694

Also, future commits will replace the use of trial sessions with
policy calculations, which avoids the problem entirely.

2 years agotpm2: add tpm2_is_encryption_session()
Dan Streetman [Wed, 7 Dec 2022 16:23:59 +0000 (11:23 -0500)] 
tpm2: add tpm2_is_encryption_session()

2 years agozsh: remove usage of PREFIX in _systemctl
Ronan Pigott [Fri, 5 May 2023 19:33:29 +0000 (12:33 -0700)] 
zsh: remove usage of PREFIX in _systemctl

The usage of PREFIX in this completion is mostly counter to the intended
usage of compsys in zsh. It is generally expected that completion code
provide the available completions and tags in that word position so that
compsys, with user configuration, can filter them to the appropriate set.

One egregious error caused by the usage of PREFIX here is the caching of
SYS_ALL_UNITS, which stored only the unit names prematurely filtered by
the completion prefix, affecting all future completions. For example,

  $ systemctl cat nonsense<TAB>

might find no matching units if nonsense* has no matches, but now

  $ systemctl cat <TAB>

will fail in all future completions even though every unit file
is a valid match, because the cached set has been erroneously filtered
by the last prefix.

2 years agotest: add a test case for #27521 27527/head
Frantisek Sumsal [Fri, 5 May 2023 20:07:12 +0000 (22:07 +0200)] 
test: add a test case for #27521

Which got resolved by e652663a04.

2 years agocore: check the unit type more thoroughly when deserializing
Frantisek Sumsal [Thu, 4 May 2023 14:56:28 +0000 (16:56 +0200)] 
core: check the unit type more thoroughly when deserializing

Resolves: #27523

2 years agoshared: refuse fd == INT_MAX
Frantisek Sumsal [Thu, 4 May 2023 14:45:36 +0000 (16:45 +0200)] 
shared: refuse fd == INT_MAX

Since we do `FD_TO_PTR(fd)` that expands to `INT_TO_PTR(fd) + 1` which
triggers an integer overflow.

Resolves: #27522

2 years agocore: use extract_first_word() instead of sscanf()
Frantisek Sumsal [Thu, 4 May 2023 14:25:25 +0000 (16:25 +0200)] 
core: use extract_first_word() instead of sscanf()

2 years agobasic/audit-util: make a test request before enabling use of audit
Nick Rosbrook [Tue, 2 May 2023 16:30:31 +0000 (12:30 -0400)] 
basic/audit-util: make a test request before enabling use of audit

If a container manager does not follow the guidance in
https://systemd.io/CONTAINER_INTERFACE/ regarding audit capabilities,
then the current check may not be sufficient to determine that audit
will function properly. In particular, when calling bind() on the audit
fd, we will get EPERM if running in a user-namespaced container.

Expand the check to make an AUDIT_GET_FEATURE request on the audit fd to
test if it is working. If this fails with ECONNREFUSED, we know it is
because the kernel does not support the use of audit outside of the
initial user namespace.

Note that the approach of this patch was suggested here:
https://github.com/systemd/systemd/pull/19443#issuecomment-829566659

Fixes: #6519
2 years agoMerge pull request #27536 from dtardon/checked-fd-parsing
Luca Boccassi [Fri, 5 May 2023 19:55:48 +0000 (20:55 +0100)] 
Merge pull request #27536 from dtardon/checked-fd-parsing

Always check parsed fds for validity

2 years agotest_ukify: add test for combining config and cmdline 27262/head
Zbigniew Jędrzejewski-Szmek [Thu, 4 May 2023 13:17:27 +0000 (15:17 +0200)] 
test_ukify: add test for combining config and cmdline

2 years agoman: describe all the changes to ukify
Zbigniew Jędrzejewski-Szmek [Mon, 24 Apr 2023 10:40:08 +0000 (12:40 +0200)] 
man: describe all the changes to ukify

As in mkosi(1), let's describe the config file and commandline options
together. This is nice for us, because we don't need to duplicate descriptions
and we're less likely to forget to update one place or the other. This is also
nice for users, because they can easily figure out what can be configured
where.

The options are now ordered by config file section.

--summary was not described before.

More examples are added.

2 years agoci: install pytest-flakes
Zbigniew Jędrzejewski-Szmek [Sat, 22 Apr 2023 11:17:32 +0000 (13:17 +0200)] 
ci: install pytest-flakes

Some web searches say that it's packaged for those distros and not the others…

v2:
- drop arch. https://aur.archlinux.org/packages/python-pytest-flakes exists,
  but installation fails in CI.

2 years agotest_ukify: rework how --flakes argument is appended
Zbigniew Jędrzejewski-Szmek [Sat, 22 Apr 2023 11:10:28 +0000 (13:10 +0200)] 
test_ukify: rework how --flakes argument is appended

The usual approach is to put 'addopts = --flakes' in setup.cfg. Unfortunately
this fails badly when pytest-flakes is not installed:
  ERROR: usage: test_ukify.py [options] [file_or_dir] [file_or_dir] [...]
  test_ukify.py: error: unrecognized arguments: --flakes

pytest-flakes is not packaged everywhere, and this test is not very important,
so let's just do it only if pytest-flakes is available. We now detect if
pytest-flakes is available and only add '--flakes' conditionally. This
unfortunately means that when invoked via 'pytest' or directly as
'src/ukify/test/test_ukify.py', '--flakes' will not be appended automatically.
But I don't see a nice way to achieve previous automatic behaviour.

(I first considered making 'setup.cfg' templated. But then it is created
in the build directory, but we would need it in the source directory for
pytest to load it automatically. So to load the file, we'd need to give an
argument to pytest anyway, so we don't gain anything with this more complex
approach.)

2 years agotest_ukify: propagate failure
Zbigniew Jędrzejewski-Szmek [Sat, 22 Apr 2023 09:20:11 +0000 (11:20 +0200)] 
test_ukify: propagate failure

Oops. This explains why the tests were "passing" in CI even
though a direct pytest invocation would fail.

2 years agoukify: appease mypy
Zbigniew Jędrzejewski-Szmek [Fri, 21 Apr 2023 16:43:50 +0000 (18:43 +0200)] 
ukify: appease mypy

Note to self: PEP 585 introduced using collection types as types,
and is available since 3.9. PEP 604 allows writing unions with "|",
but is only available since 3.10, so not yet here because we maintain
compat with 3.9.

2 years agoTODO: remove two entries
Zbigniew Jędrzejewski-Szmek [Fri, 14 Apr 2023 16:53:49 +0000 (18:53 +0200)] 
TODO: remove two entries

0ccfd3564b2532a4da6526a9e030362c4a142b77 implemented one of the items, and this
pull requests handles the other one.

2 years agotest/60-ukify: override stub location in tests
Zbigniew Jędrzejewski-Szmek [Fri, 14 Apr 2023 16:45:24 +0000 (18:45 +0200)] 
test/60-ukify: override stub location in tests

Without this, build would fail if the stub is not available in /usr/lib/.

2 years agotest-kernel-install: test 60-ukify.install and 90-uki-copy.install
Zbigniew Jędrzejewski-Szmek [Thu, 13 Apr 2023 16:11:39 +0000 (18:11 +0200)] 
test-kernel-install: test 60-ukify.install and 90-uki-copy.install

We install a kernel with layout=uki and uki_generator=ukify, and test
that a UKI gets installed in the expected place. The two plugins cooperate,
so it's easiest to test them together.

2 years ago60-ukify: kernel-install plugin that calls ukify to create a UKI
Zbigniew Jędrzejewski-Szmek [Thu, 13 Apr 2023 16:07:22 +0000 (18:07 +0200)] 
60-ukify: kernel-install plugin that calls ukify to create a UKI

60-ukify.install calls ukify with a config file, so singing and policies and
splash will be done through the ukify config file, without 60-ukify.install
knowing anything directly.

In meson.py, the variable for loaderentry.install.in is used just once, let's
drop it. (I guess this approach was copied from kernel_install_in, which is
used in another file.)

The general idea is based on cvlc12's #27119, but now in Python instead of
bash.

2 years agotest_ukify: add tests for the new functionality
Zbigniew Jędrzejewski-Szmek [Fri, 21 Apr 2023 14:06:53 +0000 (16:06 +0200)] 
test_ukify: add tests for the new functionality

2 years agoukify: PeError → PEError
Zbigniew Jędrzejewski-Szmek [Thu, 20 Apr 2023 18:23:18 +0000 (20:23 +0200)] 
ukify: PeError → PEError

We don't lowercase acronyms in systemd usually.
Remove unnused f'' prefix to avoid a pylint warning.

2 years agoukify: rework option parsing to support a config file
Zbigniew Jędrzejewski-Szmek [Thu, 20 Apr 2023 18:22:25 +0000 (20:22 +0200)] 
ukify: rework option parsing to support a config file

In some ways this is similar to mkosi: we have a argparse.ArgumentParser()
with a bunch of options, and a configparser.ConfigParser() with an
overlapping set of options. Many options are settable in both places, but
not all. In mkosi, we define this in three places (a dataclass, and a
function for argparse, and a function for configparser). Here, we have one
huge list of ConfigItem instances. Each instance specifies the full metadata
for both parsers. Argparse generates a --help string for all the options,
and we also append a config file sample to --help based on the ConfigItem
data:

$ python src/ukify/ukify.py --help|tail -n 25
config file:
  [UKI]
  Linux = LINUX
  Initrd = INITRD…
  Cmdline = TEXT|@PATH
  OSRelease = TEXT|@PATH
  DeviceTree = PATH
  Splash = BMP
  PCRPKey = KEY
  Uname = VERSION
  EFIArch = ia32|x64|arm|aa64|riscv64
  Stub = STUB
  PCRBanks = BANK…
  SigningEngine = ENGINE
  SecureBootPrivateKey = SB_KEY
  SecureBootCertificate = SB_CERT
  SignKernel = SIGN_KERNEL

  [PCRSignature:NAME]
  PCRPrivateKey = PATH
  PCRPublicKey = PATH
  Phases = PHASE-PATH…

While writing this I needed to check the argument parsing, so I added
a --summary switch. It just pretty-prints the resulting option dictionary:

$ python src/ukify/ukify.py /efi//3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/linux /efi//3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/initrd --pcr-private-key=PRIV.key --pcr-public-key=PUB.key --config=man/ukify-example.conf --summary
Host arch 'x86_64', EFI arch 'x64'
{'_groups': [0, 'initrd', 'system'],
 'cmdline': 'A1 B2 C3',
 'config': 'man/ukify-example.conf',
 'devicetree': None,
 'efi_arch': 'x64',
 'initrd': [PosixPath('initrd1'),
            PosixPath('initrd2'),
            PosixPath('initrd3'),
            PosixPath('/efi/3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/initrd')],
 'linux': PosixPath('/efi/3a9d668b4db749398a4a5e78a03bffa5/6.2.11-300.fc38.x86_64/linux'),
 'measure': None,
 'os_release': PosixPath('/etc/os-release'),
 'output': 'linux.efi',
 'pcr_banks': ['sha1', 'sha384'],
 'pcr_private_keys': [PosixPath('PRIV.key'),
                      PosixPath('pcr-private-initrd-key.pem'),
                      PosixPath('pcr-private-system-key.pem')],
 'pcr_public_keys': [PosixPath('PUB.key'),
                     PosixPath('pcr-public-initrd-key.pem'),
                     PosixPath('pcr-public-system-key.pem')],
 'pcrpkey': None,
 'phase_path_groups': [None,
                       ['enter-initrd'],
                       ['enter-initrd:leave-initrd',
                        'enter-initrd:leave-initrd:sysinit',
                        'enter-initrd:leave-initrd:sysinit:ready']],
 'sb_cert': PosixPath('mkosi.secure-boot.crt'),
 'sb_key': PosixPath('mkosi.secure-boot.key'),
 'sections': [],
 'sign_kernel': None,
 'signing_engine': None,
 'splash': None,
 'stub': PosixPath('/usr/lib/systemd/boot/efi/linuxx64.efi.stub'),
 'summary': True,
 'tools': None,
 'uname': None}

With --summary, existence of input paths is not checked. I think we'll
want to show them, instead of throwing an error, but in red, similarly to
'bootctl list'.

This also fixes tests which were failing with e.g.
E       FileNotFoundError: [Errno 2] No such file or directory: '/ARG1'
=========================== short test summary info ============================
FAILED ../src/ukify/test/test_ukify.py::test_parse_args_minimal - FileNotFoun...
FAILED ../src/ukify/test/test_ukify.py::test_parse_args_many - FileNotFoundEr...
FAILED ../src/ukify/test/test_ukify.py::test_parse_sections - FileNotFoundErr...
=================== 3 failed, 10 passed, 3 skipped in 1.51s ====================