Commit Graph

31008 Commits

Author SHA1 Message Date
Yu Watanabe 377a9545e9 tree-wide: fix typos found by Fossies codespell report 2020-10-24 13:29:31 +02:00
Yu Watanabe 5a8775bb39 Revert "sd-dhcp-client: use asynchronous_close()"
This effectively reverts the commit 22fc2420b2.

The function `asynchronous_close()` confuses valgrind. Before this commit,
valgrind may report the following:

```
HEAP SUMMARY:
    in use at exit: 384 bytes in 1 blocks
  total heap usage: 4,787 allocs, 4,786 frees, 1,379,191 bytes allocated

384 bytes in 1 blocks are possibly lost in loss record 1 of 1
   at 0x483CAE9: calloc (vg_replace_malloc.c:760)
   by 0x401456A: _dl_allocate_tls (in /usr/lib64/ld-2.31.so)
   by 0x4BD212E: pthread_create@@GLIBC_2.2.5 (in /usr/lib64/libpthread-2.31.so)
   by 0x499B662: asynchronous_job (async.c:47)
   by 0x499B7DC: asynchronous_close (async.c:102)
   by 0x4CFA8B: client_initialize (sd-dhcp-client.c:696)
   by 0x4CFC5E: client_stop (sd-dhcp-client.c:725)
   by 0x4D4589: sd_dhcp_client_stop (sd-dhcp-client.c:2134)
   by 0x493C2F: link_stop_clients (networkd-link.c:620)
   by 0x4126DB: manager_free (networkd-manager.c:867)
   by 0x40D193: manager_freep (networkd-manager.h:97)
   by 0x40DAFC: run (networkd.c:20)

LEAK SUMMARY:
   definitely lost: 0 bytes in 0 blocks
   indirectly lost: 0 bytes in 0 blocks
     possibly lost: 384 bytes in 1 blocks
   still reachable: 0 bytes in 0 blocks
        suppressed: 0 bytes in 0 blocks

For lists of detected and suppressed errors, rerun with: -s
ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```
2020-10-24 13:27:37 +02:00
Zbigniew Jędrzejewski-Szmek ff461576de Revert "basic/env-util: (mostly) follow POSIX for what variable names are allowed"
This reverts commit b45c068dd8.

I think the idea was generally sound, but didn't take into account the
limitations of show-environment and how it is used. People expect to be able to
eval systemctl show-environment output in bash, and no escaping syntax is
defined for environment *names* (we only do escaping for *values*). We could
skip such problematic variables in 'systemctl show-environment', and only allow
them to be inherited directly. But this would be confusing and ugly.

The original motivation for this change was that various import operations
would fail. a4ccce22d9 changed systemctl to filter
invalid variables in import-environment.
https://gitlab.gnome.org/GNOME/gnome-session/-/issues/71 does a similar change
in GNOME. So those problematic variables should not cause failures, but just
be silently ignored.

Finally, the environment block is becoming a dumping ground. In my gnome
session 'systemctl show-environment --user' includes stuff like PWD, FPATH
(from zsh), SHLVL=0 (no idea what that is). This is not directly related to
variable names (since all those are allowed under the stricter rules too), but
I think we should start pushing people away from running import-environment and
towards importing only select variables.

https://github.com/systemd/systemd/pull/17188#issuecomment-708676511
2020-10-23 15:07:07 +02:00
Zbigniew Jędrzejewski-Szmek 451ae5a11a basic/env-util: make function shorter 2020-10-23 13:49:05 +02:00
Lennart Poettering 17d99f95c2
Merge pull request #16859 from poettering/loop-eagain
loop: handle EAGAIN on LOOP_SET_STATUS64
2020-10-23 13:15:04 +02:00
Zbigniew Jędrzejewski-Szmek 15a6c4bf8b
Merge pull request #17417 from anitazha/more_systoomd
More systemd-oomd tweaks
2020-10-23 13:06:51 +02:00
Zbigniew Jędrzejewski-Szmek 943142a97d
Merge pull request #17185 from yuwata/ethtool-update
ethtool: add several link modes
2020-10-23 08:22:09 +02:00
Yu Watanabe 9c914c0401
Merge pull request #17357 from yuwata/network-dhcp6-pd-announce-17353
network: add an option to control announcement of delegated prefix
2020-10-23 12:57:58 +09:00
Dan Streetman e16e4b3bed network: move set-MAC and set-nomaster operations out of link_up()
These should not be bundled into the link_up() operation, as that is
not (currently) called during interface configuration if the interface
already is IFF_UP, which is unrelated to the need to change the mac
to a user-defined value, or set 'nomaster' on the interface.

Additionally, there is no need to re-set the mac or re-assert nomaster
every time the interface is brought up; those should be only part of
normal initial interface configuration.

Fixes: #17391
2020-10-23 12:09:31 +09:00
Anita Zhang 532855bead oomd: make start up swap check more robust 2020-10-22 17:04:26 -07:00
Lennart Poettering 3ec554ad17
Merge pull request #17418 from poettering/news-247-more
more v247 preps
2020-10-22 18:20:47 +02:00
Lennart Poettering f93ba37530 test: add heavy load loopback block device test 2020-10-22 15:10:03 +02:00
Lennart Poettering b202ec2068 loop-util: wait a random time before trying again
Let's try to make collisions when multiple clients want to use the same
device less likely, by sleeping a random time on collision.

The loop device allocation protocol is inherently collision prone:
first, a program asks which is the next free loop device, then it tries
to acquire it, in a separate, unsynchronized setp. If many peers do this
all at the same time, they'll likely all collide when trying to
acquire the device, so that they need to ask for a free device again and
again.

Let's make this a little less prone to collisions, reducing the number
of failing attempts: whenever we notice a collision we'll now wait
short and randomized time, making it more likely another peer succeeds.

(This also adds a similar logic when retrying LOOP_SET_STATUS64, but
with a slightly altered calculation, since there we definitely want to
wait a bit, under all cases)
2020-10-22 14:58:28 +02:00
Lennart Poettering 786e3a52a2 dissect: retrigger devices if we missed uevents
On systems that have a udev before
a7fdc6cbd3 uevents would sometimes be
eaten because of device node collisions that caused the ruleset to fail.
Let's add an (ugly) work-around for this, so that we can even work with
such an older udev.
2020-10-22 14:58:28 +02:00
Lennart Poettering 9e3d90671e udev-util: use absolute rather than relative timeout when waiting for devices
This makes it easier to accurately wait for a overall deadline.
2020-10-22 14:58:28 +02:00
Lennart Poettering 021bf17528 loop-util: if a loopback device we want to use still has partitions, do something about it
On current kernels (5.8 for example) under some conditions I don't fully
grok it might happen that a detached loopback block device still has
partition block devices around. Accessing these partition block devices
results in EIO errors (that also fill up dmesg). These devices cannot be
claned up with LOOP_CLR_FD (since the main device already is officially
detached), nor with LOOP_CTL_DELETE (returns EBUSY as long as the
partitions still exist). This is a kernel bug. But it appears to apply
to all recent kernels. I cannot really pin down what triggers this,
suffice to say our heavy-duty test can trigger it.

Either way, let's do something about it: when we notice this state we'll
attach an empty file to it, which is guaranteed to have to part table.
This makes the partitions go away. After closing/reoping the device we
hence are good to go again. ugly workaround, but I think OK enough to
use.

The net result is: with this commit, we'll guarantee that by the time we
attach a file to the loopback device we have zero kernel partitions
associated with it. Thus if we then wait for the kernel partitions we
need to appear we should have entirely reliable behaviour even if
loopback devices by the name are heavily recycled and udev events reach
us very late.

Fixes: #16858
2020-10-22 14:58:27 +02:00
Lennart Poettering 4ba86848c9 dissect-image: rework how we wait for partitions
Previously, we'd just wait for the first moment where the kernel exposes
the same numbre of partitions as libblkid tells us. After that point we
enumerate kernel partitions and look for matching libblkid partitions.

With this change we'll instead enumerate with libblkid only, and then
wait for each kernel partition to show up with the exact parameters we
expect them to show up. Once that happens we are happy.

Care is taken to use the udev device notification messages only as hint
to recheck what the kernel actually says. That's because we are
otherwise subject to a race: we might see udev events from an earlier
use of a loopback device. After all these devices are heavily recycled.
Under the assumption that we'll get udev events for *at least* all
partitions we care about (but possibly more) we can fix the race
entirely with one more fix coming in a later commit: if we make sure
that a loopback block device has zero kernel partitions when we take
possession of it, it doesn't matter anymore if we get spurious udev
events from a previous use. All we have to do is notice when the devices
we need all popped up.
2020-10-22 14:58:27 +02:00
Lennart Poettering 6c544d14d9 dissect-image: wait for udev device to be initialized early
If we allocate the sd_device early we can already use it as path when
looking at whole-device fs images.
2020-10-22 14:58:27 +02:00
Lennart Poettering 95c5009248 loop-util: LOOP_CLR_FD is async, don't retry to reuse a device right after issuing it
When we fall back to classic LOOP_SET_FD logic in case LOOP_CONFIGURE
didn't work we issue LOOP_CLR_FD first. But that call turns out to be
potentially async in the kernel: if something else (let's say
udev/blkid) is accessing the device the ioctl just sets the autoclear
flag and exits. Hence quite often the LOOP_SET_FD will subsequently
fail. Let's avoid the trouble, and immediately exit with EBUSY if
LOOP_CONFIGURE fails, and but remember that LOOP_CONFIGURE is not
available so that on the next iteration we go directly for LOOP_SET_FD
instead.
2020-10-22 14:58:27 +02:00
Lennart Poettering 738f29cb53 loop-util: handle EAGAIN on LOOP_SET_STATUS64
Since
5db470e229 (i.e. kernel 5.0)
changing the .lo_offset field via LOOP_SET_STATUS64 might result in
EAGAIN. Let's handle that.

Fixes: #16858
2020-10-22 14:58:27 +02:00
Lennart Poettering e1da60e430
Merge pull request #17324 from keszybz/resolvectl-compat-output
resolvectl compat output
2020-10-22 14:57:41 +02:00
Hans Ulrich Niedermann e1e8c60af7 test-env-util: Verify that \r is disallowed in env var values
This adds tests to make sure that basic/env-util considers environment
variables containing \r characters invalid, and that it removes such
variables during environment cleanup in strv_env_clean*().

test-env-util has not verified this behaviour before.

As \r characters can be used to hide information, disallowing them
helps with systemd's security barrier role, even when the \r
character comes as part of a DOS style (\r\n) line ending.

Prompted-by: https://github.com/systemd/systemd/issues/17378
2020-10-22 14:57:02 +02:00
Lennart Poettering d975310342
Merge pull request #16632 from keszybz/test-path-yet-again
Tighten handling of spawned services in tests that may fail
2020-10-22 14:56:46 +02:00
Lennart Poettering 0d18259e0a clock-util: trivial clean-ups 2020-10-22 14:26:23 +02:00
Lennart Poettering 66ad93e86d net_id: fix newly added naming scheme name
v246 is long released. Hence the new scheme should be named v247.

(Interesting, how we pretty systematically for the last releases changed
the scheme only every second release)
2020-10-22 14:26:23 +02:00
Lennart Poettering 44f88e7050
Merge pull request #17415 from keszybz/logind-resolved-docs
A bunch of updates to logind and resolved man pages
2020-10-22 13:44:17 +02:00
Zbigniew Jędrzejewski-Szmek 7d1e1afe28 resolvectl: wrap the extended status string too 2020-10-22 13:20:40 +02:00
Zbigniew Jędrzejewski-Szmek f08a64c5e1 resolvect: use wrapping for various lists
dump_list() is used for DNS servers, DNS domains, fallback DNS servers.
2020-10-22 13:20:40 +02:00
Zbigniew Jędrzejewski-Szmek b0e3d79989 format-table: add TABLE_STRV_WRAPPED
The idea is that we have strvs like list of server names or addresses, where
the majority of strings is rather short, but some are long and there can
potentially be many strings. So formattting them either all on one line or all
in separate lines leads to output that is either hard to read or uses way too
many rows. We want to wrap them, but relying on the pager to do the wrapping is
not nice. Normal text has a lot of redundancy, so when the pager wraps a line
in the middle of a word the read can understand what is going on without any
trouble. But for a high-density zero-redundancy text like an IP address it is
much nicer to wrap between words. This also makes c&p easier.

This adds a variant of TABLE_STRV which is wrapped on output (with line breaks
inserted between different strv entries).

The change table_print() is quite ugly. A second pass is added to re-calculate
column widths. Since column size is now "soft", i.e. it can adjust based on
available columns, we need to two passes:
- first we figure out how much space we want
- in the second pass we figure out what the actual wrapped columns
  widths will be.

To avoid unnessary work, the second pass is only done when we actually have
wrappable fields.

A test is added in test-format-table.
2020-10-22 13:20:40 +02:00
Zbigniew Jędrzejewski-Szmek 16e925c6bb test-path: relax test in "ci" and "release" modes 2020-10-22 13:16:26 +02:00
Zbigniew Jędrzejewski-Szmek 4eb0c875f8 tests: add helper function to autodetect CI environments
Sadly there is no standarized way to check if we're running in some
CI environment. So let's try to gather the heuristics in one helper function.
2020-10-22 13:16:26 +02:00
Zbigniew Jędrzejewski-Szmek 31619e2f61 resolved: add trailing newlines in generated file
Fixup for b3ffa2b5f3.
2020-10-22 11:55:35 +02:00
Zbigniew Jędrzejewski-Szmek 9c0780af5d resolved.conf: add empty DNSStubListenerExtra= 2020-10-22 11:55:35 +02:00
Lennart Poettering 349bbd8331
Merge pull request #13589 from williamvds/systemctl-edit-copy
systemctl: show original contents in comment when editing unit
2020-10-22 11:19:26 +02:00
Zbigniew Jędrzejewski-Szmek b8ee3493a5 meson: convert developer_mode boolean to an enum
I initially changed this to add a third state. But even with two values having
an explicit name instead of just 0/1 is mode descriptive.
2020-10-22 11:05:17 +02:00
Zbigniew Jędrzejewski-Szmek 67b2edb21f xdg-autostart-generator: use Type=exec
We check that the binary exists before writing the service file, but
let's also not consider the service started until the fork has happened.
This is still relatively new stuff, so we're can change the implementation
details like this.
2020-10-22 11:05:17 +02:00
Zbigniew Jędrzejewski-Szmek fcb7138ca7 test-path: do not fail the test if we fail to start a service because of cgroup setup
The test was failing because it couldn't start the service:

path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
path-modified.path: state = waiting; result = success
path-modified.service: state = failed; result = exit-code
Failed to connect to system bus: No such file or directory
-.slice: Failed to enable/disable controllers on cgroup /system.slice/kojid.service, ignoring: Permission denied
path-modified.service: Failed to create cgroup /system.slice/kojid.service/path-modified.service: Permission denied
path-modified.service: Failed to attach to cgroup /system.slice/kojid.service/path-modified.service: No such file or directory
path-modified.service: Failed at step CGROUP spawning /bin/true: No such file or directory
path-modified.service: Main process exited, code=exited, status=219/CGROUP
path-modified.service: Failed with result 'exit-code'.
Test timeout when testing path-modified.path

In fact any of the services that we try to start may fail, especially
considering that we're doing some rogue cgroup operations. See
https://github.com/systemd/systemd/pull/16603#issuecomment-679133641.
2020-10-22 11:05:17 +02:00
Zbigniew Jędrzejewski-Szmek 75edb0b0d6 test-path: more debugging information
Just to make it easier to grok what happens when test-path fails.
Change printf→log_info so that output is interleaved and not split in two
independent parts in log files.
2020-10-22 11:05:17 +02:00
Anita Zhang 018b6f4548 oomd: use ERRNO_IS_NOT_SUPPORTED and ERRNO_IS_PRIVILEGE 2020-10-21 22:37:30 -07:00
Lennart Poettering 66032ef489 macro: introduce POINTER_MAX as define for (void*) -1
Just add a safer, prettier way to write (void*) -1, that doesn't rely on
two's complement, but uses the correct underlying C constructs.
2020-10-22 08:33:20 +09:00
williamvds 85c5d313b5
systemctl: show original contents when editing unit
A comment indicates the start of the new contents of the override file,
and another indicates that lines following it will be discarded once
editing is finished.
The contents of the unit file and drop-ins are listed out after this
last marker.

Adds WRITE_STRING_FILE_TRUNCATE to set O_TRUNC when opening a file.

Thanks to cgzones for providing the required SELinux function calls.

Co-authored-by: Christian Göttsche <cgzones@googlemail.com>
2020-10-21 21:20:01 +01:00
Jonathan Lebon 6c5496c492 units: add initrd-cryptsetup.target
For encrypted block devices that we need to unlock from the initramfs,
we currently rely on dracut shipping `cryptsetup.target`. This works,
but doesn't cover the case where the encrypted block device requires
networking (i.e. the `remote-cryptsetup.target` version). That target
however is traditionally dynamically enabled.

Instead, let's rework things here by adding a `initrd-cryptsetup.target`
specifically for initramfs encrypted block device setup. This plays the
role of both `cryptsetup.target` and `remote-cryptsetup.target` in the
initramfs.

Then, adapt `systemd-cryptsetup-generator` to hook all generated
services to this new unit when running from the initrd. This is
analogous to `systemd-fstab-generator` hooking all mounts to
`initrd-fs.target`, regardless of whether they're network-backed or not.
2020-10-21 22:08:19 +02:00
williamvds 6797a74f78
Add WRITE_STRING_FILE_TRUNCATE to set O_TRUNC 2020-10-21 17:18:25 +01:00
williamvds 82443be506
Add strv_prepend
Inserts a copy of the value at the head of the list.
2020-10-21 17:14:37 +01:00
Lennart Poettering 69f30d4321
Merge pull request #17356 from yuwata/sd-xxx-stop
network: about sd_xxx_stop()
2020-10-21 18:07:38 +02:00
Lennart Poettering d9da267f71
Merge pull request #17400 from yuwata/network-route-counter-17396
network: about route message counter
2020-10-21 18:07:12 +02:00
Chandradeep Dey 842067e675 homed: remove PAM_USER_UNKNOWN test in pam_sm_acct_mgmt
Why this change
---------------
Assumption - PAM's auth stack is properly configured.

Currently account pam_systemd_home.so returns PAM_SUCCESS for non
systemd-homed users, and a variety of return values (including
PAM_SUCCESS) for homed users.

account pam_unix returns PAM_AUTHINFO_UNAVAIL for systemd-homed
users, and a variety of return values (including PAM_AUTHINFO_UNAVAIL)
for normal users.

No possible combination in the pam stack can let us preserve the
various return values of the modules. For example, the configuration
mentioned in the manpage causes account pam_unix to never be reached
since pam_systemd_home just returns a success for ordinary users. Users
with expired passwords are allowed to log in because a check cannot be
made.

More configuration examples and why they don't work are mentioned
in #16906 and the downstream discussion linked there.

After this change
-----------------
account pam_unix will continue to return wrong value for homed users.
But we can skip the module conditionally using the return value from
account pam_systemd_home. We can already do this with the auth and
password modules.
2020-10-21 16:47:10 +02:00
Arian van Putten 429495163c cgtop: Display cpu time in microseonds with --raw
this makes the CPU time easily parseable; which was the goal
of --raw in the first place.

This only triggers if --raw is combined with --cpu=time
2020-10-21 14:29:48 +02:00
Zbigniew Jędrzejewski-Szmek 9d7b11fdc8
Merge pull request #17395 from keszybz/hwdb-drop-quotes
hwdb: drop quotes from XKB_FIXED_*= properties
2020-10-21 11:34:39 +02:00
Lennart Poettering aa5502bb33
Merge pull request #16444 from oniko/luks-detached-header
Add support for detached LUKS header on kernel cmd line
2020-10-21 10:41:11 +02:00