]> git.ipfire.org Git - thirdparty/systemd.git/log
thirdparty/systemd.git
2 years agocore/job: use new job ID when we failed to deserialize job ID 27413/head
Yu Watanabe [Wed, 26 Apr 2023 05:39:56 +0000 (14:39 +0900)] 
core/job: use new job ID when we failed to deserialize job ID

This is for the case when we fail to deserialize job ID.
In job_install_deserialized(), we also check the job type, and that is
for the case when we failed to deserialize the job.
Let's gracefully handle the failure in deserializing the job ID.
This is paranoia, and just for safety. Should not change any behavior.

2 years agocore/job: handle job ID overflow or conflict more sanely
Yu Watanabe [Wed, 26 Apr 2023 05:37:26 +0000 (14:37 +0900)] 
core/job: handle job ID overflow or conflict more sanely

This is paranoia, and just for safety. Should not change any behavior.

2 years agocore/job: fix indentation
Yu Watanabe [Wed, 26 Apr 2023 05:24:12 +0000 (14:24 +0900)] 
core/job: fix indentation

2 years agocore/job: add one more assertion
Yu Watanabe [Wed, 26 Apr 2023 05:23:12 +0000 (14:23 +0900)] 
core/job: add one more assertion

In this stage, the unit should not have installed job of the type.

2 years agocore/transaction: use hashmap_remove_value() to make not remove job with same ID
Yu Watanabe [Wed, 26 Apr 2023 04:59:34 +0000 (13:59 +0900)] 
core/transaction: use hashmap_remove_value() to make not remove job with same ID

When we fail to deserialize job ID, or the current_job_id is overflowed,
we may have jobs with the same ID.
This is paranoia, and just for safety.
Note, we already use hashmap_remove_value() in job_uninstall().

2 years agoportablectl: add --extension to bash completion
Luca Boccassi [Tue, 25 Apr 2023 15:45:06 +0000 (16:45 +0100)] 
portablectl: add --extension to bash completion

2 years agoMerge pull request #27409 from mrc0mmand/more-tests
Yu Watanabe [Tue, 25 Apr 2023 23:24:52 +0000 (08:24 +0900)] 
Merge pull request #27409 from mrc0mmand/more-tests

test: add a couple of sanity tests for systemd-creds

2 years agotest: add a couple of sanity tests for systemd-creds 27409/head
Frantisek Sumsal [Tue, 25 Apr 2023 16:32:07 +0000 (18:32 +0200)] 
test: add a couple of sanity tests for systemd-creds

2 years agocreds: make --pretty behave in a slightly more expected manner
Frantisek Sumsal [Tue, 25 Apr 2023 10:58:15 +0000 (12:58 +0200)] 
creds: make --pretty behave in a slightly more expected manner

2 years agotest: cover missed stuff from securebits-util.h
Frantisek Sumsal [Tue, 18 Apr 2023 10:10:36 +0000 (12:10 +0200)] 
test: cover missed stuff from securebits-util.h

2 years agoSupport /etc/system-update for OSTree systems
Eric Curtin [Mon, 17 Apr 2023 21:09:24 +0000 (22:09 +0100)] 
Support /etc/system-update for OSTree systems

This is required when / is immutable and cannot be written at runtime.

Co-authored-by: Richard Hughes <richard@hughsie.com>
2 years agoMerge pull request #27347 from bluca/sd_bus_nonce
Lennart Poettering [Tue, 25 Apr 2023 15:40:15 +0000 (17:40 +0200)] 
Merge pull request #27347 from bluca/sd_bus_nonce

sd: avoid closing sd-bus in a fork, store module-global id for sd-bus/sd-session/sd-journal

2 years agomount-util: split remount_idmap() in two
Lennart Poettering [Tue, 14 Mar 2023 21:55:32 +0000 (22:55 +0100)] 
mount-util: split remount_idmap() in two

This will make things a bit longer for now, but more powerful as we can
reuse the userns fd between calls to remount_idmap() if we need to
adjust multiple mounts.

No change in behaviour, just some minor refactoring.

2 years agosd-daemon: add sd_pid_notifyf_with_fds()
Lennart Poettering [Fri, 14 Apr 2023 15:48:47 +0000 (17:48 +0200)] 
sd-daemon: add sd_pid_notifyf_with_fds()

I guess it was only a question of time until we need to add the final
frontier of notification functions: one that combines the features of
all the others:

1. specifiying a source PID
2. taking a list of fds to send along
3. accepting a format string for the status string

Hence, let's add it.

2 years agopam: do not attempt to close sd-bus after fork in pam_end()
Luca Boccassi [Thu, 20 Apr 2023 11:55:06 +0000 (12:55 +0100)] 
pam: do not attempt to close sd-bus after fork in pam_end()

When pam_end() is called after a fork, and it cleans up caches, it sets
PAM_DATA_SILENT in error_status. FDs will be shared with the parent, so
we do not want to attempt to close them from a child process, or we'll
hit assertions. Complain loudly and skip.

2 years agoman: /usr/lib/systemd/random-seed -> /usr/lib/systemd/systemd-random-seed
Vitaly Kuznetsov [Tue, 25 Apr 2023 14:51:09 +0000 (16:51 +0200)] 
man: /usr/lib/systemd/random-seed -> /usr/lib/systemd/systemd-random-seed

/usr/lib/systemd/random-seed is not a thing.

Signed-off-by: Vitaly Kuznetsov <vkuznets@redhat.com>
2 years agologind: always use 64bit session IDs
Lennart Poettering [Tue, 25 Apr 2023 10:02:32 +0000 (12:02 +0200)] 
logind: always use 64bit session IDs

it's a bit confusing that on 32bit systems we'd risk session IDs
overruns like this. Let's expose the same behaviour everywhere and stick
to 64bit ids.

Since we format the ids as strings anyway this doesn't really change
anything performance-wise, it just pushes out collisions by overrun to
basically never happen.

2 years agodocs: fix LoadCredentialEncrypted example (#27387)
Lawrence Thorpe [Tue, 25 Apr 2023 13:41:01 +0000 (14:41 +0100)] 
docs: fix LoadCredentialEncrypted example (#27387)

Embedded credential name 'ciphertext.cred' does not match filename 'foobar', refusing.

2 years agosd-login: add SetTTY session object #26611
Thorsten Kukuk [Wed, 19 Apr 2023 14:11:55 +0000 (16:11 +0200)] 
sd-login: add SetTTY session object #26611

2 years agodoc: say in CODING_STYLE that AT_EMPTY_PATH should be implied on openat() style APIs...
Lennart Poettering [Tue, 25 Apr 2023 11:56:20 +0000 (13:56 +0200)] 
doc: say in CODING_STYLE that AT_EMPTY_PATH should be implied on openat() style APIs (and NULL path is OK)

As discussed here:

https://github.com/systemd/systemd/pull/27397#issuecomment-1521630044

2 years agouser-record-nss: make return values optional
Lennart Poettering [Tue, 14 Mar 2023 16:23:25 +0000 (17:23 +0100)] 
user-record-nss: make return values optional

If we only want to know if some user ID/user name is already allocated,
we don't care for the returned data.

2 years agomountpoint-util: make path_get_mnt_id_at() work with a NULL path
Lennart Poettering [Thu, 20 Apr 2023 16:42:36 +0000 (18:42 +0200)] 
mountpoint-util: make path_get_mnt_id_at() work with a NULL path

2 years agosd-event: store and compare per-module static origin id 27347/head
Luca Boccassi [Tue, 25 Apr 2023 00:46:22 +0000 (01:46 +0100)] 
sd-event: store and compare per-module static origin id

sd-event objects use hashmaps, which use module-global state, so it is not safe
to pass a sd-event object created by a module instance to another module instance
(e.g.: when two libraries static linking sd-event are pulled in a single process).
Initialize a random per-module origin id and store it in the object, and compare
it when entering a public API, and error out if they don't match, together with
the PID.

2 years agosd-journal: store and compare per-module static origin id
Luca Boccassi [Tue, 25 Apr 2023 00:08:46 +0000 (01:08 +0100)] 
sd-journal: store and compare per-module static origin id

sd-journal objects use hashmaps, which use module-global state, so it is not safe
to pass a sd-journal object created by a module instance to another module instance
(e.g.: when two libraries static linking sd-journal are pulled in a single process).
Initialize a random per-module origin id and store it in the object, and compare
it when entering a public API, and error out if they don't match, together with
the PID.

2 years agosd-bus: store and compare per-module static origin id
Luca Boccassi [Mon, 24 Apr 2023 23:56:06 +0000 (00:56 +0100)] 
sd-bus: store and compare per-module static origin id

sd-bus objects use hashmaps, which use module-global state, so it is not safe
to pass a sd-bus object created by a module instance to another module instance
(e.g.: when two libraries static linking sd-bus are pulled in a single process).
Initialize a random per-module origin id and store it in the object, and compare
it when entering a public API, and error out if they don't match, together with
the PID.

2 years agomacro: add helper for module origin id
Luca Boccassi [Mon, 24 Apr 2023 23:37:51 +0000 (00:37 +0100)] 
macro: add helper for module origin id

These need to be redefined in every module that we need to guard, so add
a macro

2 years agoMerge pull request #27261 from keszybz/test-cleanup
Frantisek Sumsal [Tue, 25 Apr 2023 09:41:27 +0000 (11:41 +0200)] 
Merge pull request #27261 from keszybz/test-cleanup

Cleanup syntax and use idiomatic bash in test scripts

2 years agofs-util: make sure open_mkdir_at() does something roughly sensible when invoked with '/'
Lennart Poettering [Thu, 20 Apr 2023 16:44:21 +0000 (18:44 +0200)] 
fs-util: make sure open_mkdir_at() does something roughly sensible when invoked with '/'

2 years agoMerge pull request #27380 from poettering/bpf-meson-tweaks
Yu Watanabe [Tue, 25 Apr 2023 09:37:36 +0000 (18:37 +0900)] 
Merge pull request #27380 from poettering/bpf-meson-tweaks

two bpf build system changes

2 years agomkosi: Update fedora to release 38
Daan De Meyer [Tue, 25 Apr 2023 08:14:42 +0000 (10:14 +0200)] 
mkosi: Update fedora to release 38

2 years agoMerge pull request #27388 from poettering/assert-fd
Lennart Poettering [Tue, 25 Apr 2023 07:54:20 +0000 (09:54 +0200)] 
Merge pull request #27388 from poettering/assert-fd

add ASSERT_FD() similar to ASSERT_PTR(), but for fds

2 years agoDrop log level of header limits log message
Daan De Meyer [Mon, 24 Apr 2023 18:55:15 +0000 (20:55 +0200)] 
Drop log level of header limits log message

Especially when using in-memory logging, these are too noisy so
let's drop them back to debug level.

2 years agoMerge pull request #27386 from dtardon/test-cleanup
Luca Boccassi [Tue, 25 Apr 2023 01:00:56 +0000 (02:00 +0100)] 
Merge pull request #27386 from dtardon/test-cleanup

More automatic cleanup in tests

2 years agocryptsetup-fido2: Depend on libcryptsetup
Wolfgang Müller [Mon, 24 Apr 2023 18:00:56 +0000 (20:00 +0200)] 
cryptsetup-fido2: Depend on libcryptsetup

crypsetup-fido2 always depended on both libfido2 and libcryptsetup, but
0a8e026e825dda142a8f1552a4b45815cbfd0b48 forgot to make the then
implicit dependency on libcryptsetup explicit when moving it from
cryptsetup/ to shared/. This breaks builds when libfido2 is autodetected
but the system is missing libcryptsetup.

Introduce an explicit check for HAVE_LIBCRYPTSETUP such that
cryptsetup-fido2 is only built when both libraries are available.

Fixes #27374.

2 years agosd-bus: check for pid change before closing
Luca Boccassi [Thu, 20 Apr 2023 00:24:42 +0000 (01:24 +0100)] 
sd-bus: check for pid change before closing

If we try to close after a fork, the FDs will have been cloned
too and we'll assert. This can happen for example in PAM modules.

Avoid the macro and define ref/unref by hand to do the same check.

2 years agohomed: rename make_userns() to avoid name conflict with mount-util.[ch]
Lennart Poettering [Tue, 14 Mar 2023 21:48:25 +0000 (22:48 +0100)] 
homed: rename make_userns() to avoid name conflict with mount-util.[ch]

This doesn't really matter too much as both are static functions. But
it's confusing as hell both when debugging and reading code, given that
homed actually uses mount-util.c

Hence, let's just rename one of the two, to minimize confusion.

No actual change in behaviour.

(and sooner or later we might want to export mount-util.c's version of
the function, since it's generically useful)

2 years agoMerge pull request #27113 from keszybz/variable-expansion-rework
Zbigniew Jędrzejewski-Szmek [Mon, 24 Apr 2023 20:03:06 +0000 (22:03 +0200)] 
Merge pull request #27113 from keszybz/variable-expansion-rework

Rework serialization of command lines in pid1 and make run not expand variables

2 years agotest: use idiomatic bash loop iteration 27261/head
Zbigniew Jędrzejewski-Szmek [Fri, 7 Apr 2023 08:17:15 +0000 (10:17 +0200)] 
test: use idiomatic bash loop iteration

In a few cases, also avoid a sleep in the last (failed) iteration of the loop.
It doesn't matter too much, but it's still ugly.

2 years agotestsuite-54: drop unnecessary pipe
Zbigniew Jędrzejewski-Szmek [Wed, 5 Apr 2023 13:52:16 +0000 (15:52 +0200)] 
testsuite-54: drop unnecessary pipe

2 years agotestsuite-70: drop unnecessary env
Zbigniew Jędrzejewski-Szmek [Wed, 5 Apr 2023 13:51:56 +0000 (15:51 +0200)] 
testsuite-70: drop unnecessary env

2 years agotest: drop uses of "&& { echo 'unexpected success'; exit 1; }"
Zbigniew Jędrzejewski-Szmek [Wed, 5 Apr 2023 13:50:42 +0000 (15:50 +0200)] 
test: drop uses of "&& { echo 'unexpected success'; exit 1; }"

Brief is sweet.

2 years agoparse-util: allow parse_pid() to work with NULL return parameter
Lennart Poettering [Thu, 20 Apr 2023 16:46:55 +0000 (18:46 +0200)] 
parse-util: allow parse_pid() to work with NULL return parameter

That way the function becomes useful for validating pids formatted as
strings.

2 years agotest-hashmap-plain: use _cleanup_ 27386/head
David Tardon [Mon, 24 Apr 2023 18:58:19 +0000 (20:58 +0200)] 
test-hashmap-plain: use _cleanup_

2 years agotest-set: use _cleanup_
David Tardon [Mon, 24 Apr 2023 18:48:33 +0000 (20:48 +0200)] 
test-set: use _cleanup_

2 years agoloop-util: port some code over to ASSERT_FD() 27388/head
Lennart Poettering [Mon, 24 Apr 2023 16:58:57 +0000 (18:58 +0200)] 
loop-util: port some code over to ASSERT_FD()

2 years agofd-util: add ASSERT_FD() that is similar to ASSERT_PTR() but for fds
Lennart Poettering [Thu, 20 Apr 2023 08:10:35 +0000 (10:10 +0200)] 
fd-util: add ASSERT_FD() that is similar to ASSERT_PTR() but for fds

2 years agotest-calendarspec: use _cleanup_
David Tardon [Mon, 24 Apr 2023 18:44:29 +0000 (20:44 +0200)] 
test-calendarspec: use _cleanup_

2 years agomkosi: Update to latest
Daan De Meyer [Mon, 24 Apr 2023 11:21:21 +0000 (13:21 +0200)] 
mkosi: Update to latest

This pulls in a fix for Debian rpmdb locations, which results in a
substantial speedup for centos/fedora builds.

2 years agonspawn: Don't follow /etc/resolv.conf symlinks
Daan De Meyer [Mon, 24 Apr 2023 09:54:50 +0000 (11:54 +0200)] 
nspawn: Don't follow /etc/resolv.conf symlinks

When we're checking if /etc/resolv.conf exists so we can bind mount
on top of it, we care about whether the symlink itself exists if
/etc/resolv.conf exists and not the file it points to, so add
CHASE_NOFOLLOW to make sure we check existence of the symlink and
not the file it points to.

2 years agopid1: simplify bpf meson import 27380/head
Lennart Poettering [Thu, 16 Mar 2023 14:37:04 +0000 (15:37 +0100)] 
pid1: simplify bpf meson import

2 years agomeson: move bpf hookup into main meson build file
Lennart Poettering [Thu, 16 Mar 2023 14:36:26 +0000 (15:36 +0100)] 
meson: move bpf hookup into main meson build file

This way we can use it in systemd-userdbd later on, too.

2 years agoman: fix LogControl1 manpage example
Luca Boccassi [Mon, 24 Apr 2023 12:42:16 +0000 (13:42 +0100)] 
man: fix LogControl1 manpage example

Follow-up for c6b8fffdfaf1f7c9a1dac73e1e54993a06c766c0

2 years agopam: cache sd-bus separately per module
Luca Boccassi [Sun, 16 Apr 2023 13:55:09 +0000 (14:55 +0100)] 
pam: cache sd-bus separately per module

sd-bus connection is cached by the two pam modules globally, but this
can lead to issues due to hashmaps (used by sd-bus) using a global
static variable for the shared hash key, which is different per module
as both modules are loaded in the same process.

This happens because the sd-bus object is create in one module, but
used in the other, so global state does not match.

Use a different pam cache identifier for the sd-bus pointer, so that
each module uses a different sd-bus connection as a workaround.

Fixes https://github.com/systemd/systemd/issues/27216
Fixes https://github.com/systemd/systemd/issues/17266

2 years agopam_systemd_home: clean up sd-bus when called about something else's user
Luca Boccassi [Thu, 20 Apr 2023 11:58:18 +0000 (12:58 +0100)] 
pam_systemd_home: clean up sd-bus when called about something else's user

acquire_home() takes a reference to a sd-bus object, which the open_session
hook cleans on success. But only when handling a user actually owned by homed,
it did not clean it up when skipping because it is being invoked on a system
user.
We need to be careful with sd-bus here as pam_sm_open_session is the last
hook before forking, and we want to clean up sd-bus before that happens, or
we'll have a broken reference (FDs are cloexec) in the child process, which
will then assert when attempting to close them, or leak the bus connection
which causes dbus to complain loudly:

 dbus-daemon[62]: [system] Connection has not authenticated soon enough, closing it (auth_timeout=30000ms, elapsed: 30020ms)

2 years agoMerge pull request #27367 from bluca/mkosi_resolve
Daan De Meyer [Mon, 24 Apr 2023 11:03:58 +0000 (13:03 +0200)] 
Merge pull request #27367 from bluca/mkosi_resolve

mkosi: add tmpfiles to handle locale/resolve.conf in Debian

2 years agoMerge pull request #27357 from bluca/example_logcontrol
Zbigniew Jędrzejewski-Szmek [Mon, 24 Apr 2023 10:24:36 +0000 (12:24 +0200)] 
Merge pull request #27357 from bluca/example_logcontrol

man: add working example to LogControl1 manpage

2 years agostub: add comment on measurement of io.systemd.stub.kernel-cmdline-extra
Luca Boccassi [Sun, 23 Apr 2023 17:33:24 +0000 (18:33 +0100)] 
stub: add comment on measurement of io.systemd.stub.kernel-cmdline-extra

2 years agomkosi: add tmpfiles to create debian/ubuntu /etc/default/locale link 27367/head
Luca Boccassi [Mon, 24 Apr 2023 09:47:29 +0000 (10:47 +0100)] 
mkosi: add tmpfiles to create debian/ubuntu /etc/default/locale link

2 years agomkosi: move debian/ubuntu ignore preset to config directory
Luca Boccassi [Mon, 24 Apr 2023 09:46:39 +0000 (10:46 +0100)] 
mkosi: move debian/ubuntu ignore preset to config directory

2 years agomkosi: move debian/ubuntu common conf under common directory
Luca Boccassi [Sun, 23 Apr 2023 11:54:20 +0000 (12:54 +0100)] 
mkosi: move debian/ubuntu common conf under common directory

2 years agomkosi: delete /etc/resolv.conf to let tmpfiles handle it
Luca Boccassi [Sun, 23 Apr 2023 12:02:06 +0000 (13:02 +0100)] 
mkosi: delete /etc/resolv.conf to let tmpfiles handle it

In case the distribution creates or ships resolv.conf, delete it and let tmpfiles handle it

2 years agomkosi: Update to latest
Daan De Meyer [Sun, 23 Apr 2023 12:53:11 +0000 (14:53 +0200)] 
mkosi: Update to latest

Let's use the new support for matching against any distribution in
a list of distributions to start sharing most things between the
ubuntu/debian configs and centos/fedora configs.

2 years agotestsuite-04: remove unnecessary conditional
Zbigniew Jędrzejewski-Szmek [Tue, 4 Apr 2023 09:01:33 +0000 (11:01 +0200)] 
testsuite-04: remove unnecessary conditional

2 years agotestsuite-04: remove redirection, drop whitespace after redirection op
Zbigniew Jędrzejewski-Szmek [Tue, 4 Apr 2023 08:58:34 +0000 (10:58 +0200)] 
testsuite-04: remove redirection, drop whitespace after redirection op

2 years agorun: expand variables also with --scope 27113/head
Zbigniew Jędrzejewski-Szmek [Tue, 4 Apr 2023 19:18:33 +0000 (21:18 +0200)] 
run: expand variables also with --scope

This makes syntax be the same for commands which are started by the manager and
those which are spawned directly (when --scope is used).

Before:
$ systemd-run -q -t echo '$TERM'
xterm-256color

$ systemd-run -q --scope echo '$TERM'
$TERM

Now:
$ systemd-run -q --scope echo '$TERM'
xterm-256color

Previous behaviour can be restored via --expand-environment=no:
$ systemd-run -q --scope --expand-environment=no echo '$TERM'
$TERM

Fixes #22948.

At some level, this is a compat break. Fortunately --scope is not very widely
used, so I think we can get away with this. Having different syntax depending
on whether --scope was used or not was bad UX.

A NEWS entry will be required.

2 years agoman/systemd-run: add examples explaining how variable expansion is performed
Zbigniew Jędrzejewski-Szmek [Mon, 3 Apr 2023 06:26:56 +0000 (08:26 +0200)] 
man/systemd-run: add examples explaining how variable expansion is performed

2 years agorun: add --expand-environment=no to disable server-side envvar expansion
Zbigniew Jędrzejewski-Szmek [Sun, 2 Apr 2023 21:17:58 +0000 (23:17 +0200)] 
run: add --expand-environment=no to disable server-side envvar expansion

This uses StartExecEx to get the equivalent of ExecStart=:. StartExecEx was
added in b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb, so this will not work with
older systemds.

A hint is emitted if we get an error indicating lack of support. PID1 returns
SD_BUS_ERROR_PROPERTY_READ_ONLY, but I'm checking for
SD_BUS_ERROR_UNKNOWN_PROPERTY too for safety.

2 years agorun: split out creation of unit creation messages
Zbigniew Jędrzejewski-Szmek [Sun, 2 Apr 2023 20:27:58 +0000 (22:27 +0200)] 
run: split out creation of unit creation messages

Just refactoring, in preparation for future changes.
(Though I think it'd be reasonable to do anyway, those functions were
awfully long.)

'git diff' displays this badly. The middle part of start_transient_service()
is moved to make_transient_service_unit(), and the middle part of
start_transient_trigger() is moved to make_transient_trigger_unit().

2 years agorun: simplify returning of status
Zbigniew Jędrzejewski-Szmek [Sun, 2 Apr 2023 19:50:19 +0000 (21:50 +0200)] 
run: simplify returning of status

start_transient_service() would return two ints: one normally and one via
*retval. We can just return one int and propagate it directly, because we
use DEFINE_MAIN_FUNCTION_WITH_POSITIVE_FAILURE().

2 years agocore: fix writing of ExecStartEx and friends
Zbigniew Jędrzejewski-Szmek [Mon, 3 Apr 2023 11:56:18 +0000 (13:56 +0200)] 
core: fix writing of ExecStartEx and friends

The property name is called ExecStartEx, but we have to write it as ExecStart=
in the unit file. :(
Bug introduced in b3d593673c5b8b0b7d781fd26ab2062ca6e7dbdb when ex-properties
were initially added.

In addition, we cannot escape $ as $$, because when ":" is used, we wouldn't
unescape $$ back to $.

2 years agocore/unit: add UNIT_ESCAPE_EXEC_SYNTAX
Zbigniew Jędrzejewski-Szmek [Mon, 3 Apr 2023 12:45:46 +0000 (14:45 +0200)] 
core/unit: add UNIT_ESCAPE_EXEC_SYNTAX

Unfortunately we can't escape $ when ':' is used to prohibit variable expansion:
  ExecStart=:echo $$
is not the same as
  ExecStart=:echo $

This just adds the functionality and the unittests, without using it anywhere
for real yet.

2 years agocore/unit: rename UNIT_ESCAPE_EXEC_SYNTAX → *_ENV
Zbigniew Jędrzejewski-Szmek [Mon, 3 Apr 2023 12:50:12 +0000 (14:50 +0200)] 
core/unit: rename UNIT_ESCAPE_EXEC_SYNTAX → *_ENV

In preparation for future changes.

2 years agocore/unit: fix shell-escaping of strings
Zbigniew Jędrzejewski-Szmek [Mon, 3 Apr 2023 10:43:53 +0000 (12:43 +0200)] 
core/unit: fix shell-escaping of strings

Our escaping of '$' is '$$', not '\$'. We would write unit files that
were not valid:
  $ systemd-run --user bash -c 'echo $$; sleep 1000'
  Running as unit: run-r1c7c45b5b69f487c86ae205e12100808.service
  $ systemctl cat --user run-r1c7c45b5b69f487c86ae205e12100808
  # /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service
  ...
  ExecStart="/usr/bin/bash" "-c" "echo \$\$\; sleep 1000"

  $ systemd-analyze verify /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service
  /run/user/1000/systemd/transient/run-r1c7c45b5b69f487c86ae205e12100808.service:7:
    Ignoring unknown escape sequences: "echo \$\$\; sleep 1000"

Similarly, ';' cannot be escaped as '\;'. Only a handful of characters
listed in "Supported escapes" is allowed.

Escaping of "'" can be done, but it's not useful because we use double quotes
around the string anyway whenever we do escaping.

unit_write_setting() is called all over the place. In a great majority of
places we write either fixed strings or something that we generate ourselves,
so no escaping or quoting is needed. (And it's not allowed, e.g.
'Type="oneshot"' would not work.)  But if we forgot to add escaping or quoting
for a free-style string, it would probably allow writing a unit file that would
be read completely wrong. I looked over various places where
unit_write_setting() is called, and I couldn't find any place where
quoting/escaping was forgotten. But trying to figure out the full
ramifications of this change is not easy.

2 years agobasic/logarithm: add popcount() wrapper
Zbigniew Jędrzejewski-Szmek [Mon, 3 Apr 2023 12:32:39 +0000 (14:32 +0200)] 
basic/logarithm: add popcount() wrapper

__builtin_popcount() is a bit of a mouthful, so let's provide a helper.
Using _Generic has the advantage that if a type other then the ones on
the list is given, compilation will fail. This is nice, because if by any
change we pass a wider type, it is rejected immediately instead of being
truncated.

log.h is also needed. It is included transitively, but let's include it
directly.

macro.h is *not* needed.

2 years agoa colloquial abbreviation 'btw' in TEMPORARY_DIRECTORIES.md (#27365)
07416 [Sun, 23 Apr 2023 09:48:17 +0000 (12:48 +0300)] 
a colloquial abbreviation 'btw' in TEMPORARY_DIRECTORIES.md (#27365)

* Update TEMPORARY_DIRECTORIES.md

2 years agoman: clarify sd_bus_default 27357/head
Luca Boccassi [Sat, 22 Apr 2023 11:47:20 +0000 (12:47 +0100)] 
man: clarify sd_bus_default

It picks the bus based on the cgroup slice.

2 years agoman: add working example to LogControl1 manpage
Luca Boccassi [Fri, 21 Apr 2023 22:35:08 +0000 (23:35 +0100)] 
man: add working example to LogControl1 manpage

Add fully working and documented example that can be copied and pasted

2 years agosulogin-shell: Start initrd.target on exit in the initrd
Daan De Meyer [Fri, 21 Apr 2023 11:01:24 +0000 (13:01 +0200)] 
sulogin-shell: Start initrd.target on exit in the initrd

sulogin is documented to continue booting up on exit. To do that
in the initrd, we need to start initrd.target and not default.target.

2 years agoMerge pull request #27352 from poettering/devnum-more
Lennart Poettering [Fri, 21 Apr 2023 14:45:51 +0000 (16:45 +0200)] 
Merge pull request #27352 from poettering/devnum-more

devnum-util: port more things over

2 years agotest: use _cleanup_ for temp. files
David Tardon [Fri, 21 Apr 2023 14:25:31 +0000 (16:25 +0200)] 
test: use _cleanup_ for temp. files

2 years agotest-fdset: use _cleanup_
David Tardon [Fri, 21 Apr 2023 14:18:43 +0000 (16:18 +0200)] 
test-fdset: use _cleanup_

2 years agotest: shorten a bit
David Tardon [Fri, 27 Jan 2023 08:47:24 +0000 (09:47 +0100)] 
test: shorten a bit

2 years agomkosi: Use authselect minimal if authselect is installed
Daan De Meyer [Thu, 20 Apr 2023 08:13:37 +0000 (10:13 +0200)] 
mkosi: Use authselect minimal if authselect is installed

We dropped this logic from mkosi itself, so let's configure it in
our postinst script instead. We also enable the with-homed feature
if we can find it. It doesn't exist for the minimal profile yet,
but might be added in the future.

2 years agomkosi: remove ?priority(required) from debian pkg list
Luca Boccassi [Thu, 20 Apr 2023 22:48:58 +0000 (23:48 +0100)] 
mkosi: remove ?priority(required) from debian pkg list

Requires apt 2.3.10 which is not available in stable, and also doesn't
seem necessary, same packages are installed anyway
Add tzdata manually, as that doesn't seem to be pulled in via the CI.

2 years agotre-wide: use FORMAT_DEVNUM() a bit more 27352/head
Lennart Poettering [Fri, 21 Apr 2023 10:39:28 +0000 (12:39 +0200)] 
tre-wide: use FORMAT_DEVNUM() a bit more

2 years agotree-wide: convert more cases do DEVNUM_FORMAT_STR()/DEVNUM_FORMAT_VAL()
Lennart Poettering [Fri, 21 Apr 2023 10:34:37 +0000 (12:34 +0200)] 
tree-wide: convert more cases do DEVNUM_FORMAT_STR()/DEVNUM_FORMAT_VAL()

Let's use our nice macros a bit more.

(Not comprehensive)

2 years agoMerge pull request #27349 from mrc0mmand/codespell
Luca Boccassi [Thu, 20 Apr 2023 21:02:17 +0000 (22:02 +0100)] 
Merge pull request #27349 from mrc0mmand/codespell

tree-wide: code spelling fixes

2 years agoREADME: add a Weblate badge 27349/head
Frantisek Sumsal [Thu, 20 Apr 2023 20:06:28 +0000 (22:06 +0200)] 
README: add a Weblate badge

2 years agotree-wide: code spelling fixes
Frantisek Sumsal [Thu, 20 Apr 2023 19:54:59 +0000 (21:54 +0200)] 
tree-wide: code spelling fixes

As reported by Fossies.

2 years agodetect-virt: add message at debug level
Zbigniew Jędrzejewski-Szmek [Thu, 20 Apr 2023 15:42:57 +0000 (17:42 +0200)] 
detect-virt: add message at debug level

Normal users do not have permissions to access /proc/1/root, so
'systemd-detect-virt -r' fails, but the output, even at debug level
is cryptic:

$ SYSTEMD_LOG_LEVEL=debug build/systemd-detect-virt -r
Failed to check for chroot() environment: Permission denied

Let's make this a bit easier to figure out:

$ SYSTEMD_LOG_LEVEL=debug build/systemd-detect-virt -r
Cannot stat /proc/1/root: Permission denied
Failed to check for chroot() environment: Permission denied

I looked over other users of files_same(), and I think in general the message
at debug level is OK for them too.

2 years agoApply known iocost solutions to block devices
Gustavo Noronha Silva [Mon, 2 May 2022 17:02:23 +0000 (14:02 -0300)] 
Apply known iocost solutions to block devices

Meta's resource control demo project[0] includes a benchmark tool that can
be used to calculate the best iocost solutions for a given SSD.

  [0]: https://github.com/facebookexperimental/resctl-demo

A project[1] has now been started to create a publicly available database
of results that can be used to apply them automatically.

  [1]: https://github.com/iocost-benchmark/iocost-benchmarks

This change adds a new tool that gets triggered by a udev rule for any
block device and queries the hwdb for known solutions. The format for
the hwdb file that is currently generated by the github action looks like
this:

  # This file was auto-generated on Tue, 23 Aug 2022 13:03:57 +0000.
  # From the following commit:
  # https://github.com/iocost-benchmark/iocost-benchmarks/commit/ca82acfe93c40f21d3b513c055779f43f1126f88
  #
  # Match key format:
  # block:<devpath>:name:<model name>:

  # 12 points, MOF=[1.346,1.346], aMOF=[1.249,1.249]
  block:*:name:HFS256GD9TNG-62A0A:fwver:*:
    IOCOST_SOLUTIONS=isolation isolated-bandwidth bandwidth naive
    IOCOST_MODEL_ISOLATION=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_ISOLATION=rpct=0.00 rlat=8807 wpct=0.00 wlat=59023 min=100.00 max=100.00
    IOCOST_MODEL_ISOLATED_BANDWIDTH=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_ISOLATED_BANDWIDTH=rpct=0.00 rlat=8807 wpct=0.00 wlat=59023 min=100.00 max=100.00
    IOCOST_MODEL_BANDWIDTH=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_BANDWIDTH=rpct=0.00 rlat=8807 wpct=0.00 wlat=59023 min=100.00 max=100.00
    IOCOST_MODEL_NAIVE=rbps=1091439492 rseqiops=52286 rrandiops=63784 wbps=192329466 wseqiops=12309 wrandiops=16119
    IOCOST_QOS_NAIVE=rpct=99.00 rlat=8807 wpct=99.00 wlat=59023 min=75.00 max=100.00

The IOCOST_SOLUTIONS key lists the solutions available for that device
in the preferred order for higher isolation, which is a reasonable
default for most client systems. This can be overriden to choose better
defaults for custom use cases, like the various data center workloads.

The tool can also be used to query the known solutions for a specific
device or to apply a non-default solution (say, isolation or bandwidth).

Co-authored-by: Santosh Mahto <santosh.mahto@collabora.com>
2 years agoMerge pull request #27327 from DaanDeMeyer/hotplug
Lennart Poettering [Thu, 20 Apr 2023 14:34:12 +0000 (16:34 +0200)] 
Merge pull request #27327 from DaanDeMeyer/hotplug

kmod-setup: Add early loading for virtio_console

2 years agokmod-setup: Add early loading for virtio_console 27327/head
Daan De Meyer [Tue, 18 Apr 2023 11:20:37 +0000 (13:20 +0200)] 
kmod-setup: Add early loading for virtio_console

getty-generator enables serial-getty@.service for virtualizer consoles
that it can find in /sys/class/tty. To make sure this works for
virtio consoles, let's make sure we load the module is loaded early
so that the /sys/class/tty/hvc0 exists before we run getty-generator.

2 years agocore: Parse logging environment earlier
Daan De Meyer [Tue, 18 Apr 2023 11:15:20 +0000 (13:15 +0200)] 
core: Parse logging environment earlier

Let's make sure we parse the logging environment ASAP so that the
options apply to more code. e.g. to allow debugging kmod-setup.c
for example.

2 years agokmod-setup: Introduce match_modalias_recurse_dir_cb()
Daan De Meyer [Tue, 18 Apr 2023 08:47:13 +0000 (10:47 +0200)] 
kmod-setup: Introduce match_modalias_recurse_dir_cb()

Let's make the logic around matching a modalias a bit more generic.

2 years agostring-util: Add startswith_strv()
Daan De Meyer [Tue, 18 Apr 2023 11:11:45 +0000 (13:11 +0200)] 
string-util: Add startswith_strv()

This is the function version of STARTSWITH_SET(). We also move
STARTSWITH_SET() to string-util.h as it fits more there than in
strv.h and reimplement it using startswith_strv().

2 years agomkosi: Disable kmsg ratelimiting
Daan De Meyer [Thu, 20 Apr 2023 08:33:10 +0000 (10:33 +0200)] 
mkosi: Disable kmsg ratelimiting

2 years agolog: Log when kmsg is being ratelimited
Daan De Meyer [Thu, 20 Apr 2023 08:43:21 +0000 (10:43 +0200)] 
log: Log when kmsg is being ratelimited

Let's avoid confusing developers and users when log messages suddenly
stop getting logged to kmsg because of ratelimiting by logging an
additional message if we start ratelimiting log messages to kmsg.

2 years agolog: Add knob to disable kmsg ratelimiting
Daan De Meyer [Thu, 20 Apr 2023 08:31:37 +0000 (10:31 +0200)] 
log: Add knob to disable kmsg ratelimiting

This allows us to disable kmsg ratelimiting in the integration tests
and mkosi for easier debugging.

2 years agodissect: let's check for crypto_LUKS before fstype allowlist check
Lennart Poettering [Thu, 20 Apr 2023 09:14:50 +0000 (11:14 +0200)] 
dissect: let's check for crypto_LUKS before fstype allowlist check

When trying to mount a partition that is encrypted without the
encryption first having been set up we want to return a
recognizable error (EUNATCH). This was broken by
80ce8580f5aa6b03fa13a0b3b30207bc9b5c5fe0 which added an allowlist check
for permissible file systems first. Let's reverse the check order, so
that we get EUNATCH again, as before. (And leave EIDRM as error for the
failed allowlist check).