Commit graph

39021 commits

Author SHA1 Message Date
Frantisek Sumsal bf24eafcd2
Merge pull request #23584 from yuwata/test-login
test: import logind test from debian/ubuntu test suite
2022-06-10 14:50:35 +00:00
Frantisek Sumsal a359237fb7
Merge pull request #23690 from yuwata/test-sd-device
test: several tweaks for test-sd-device
2022-06-10 14:50:01 +00:00
Jan Janssen 8494bd1ced boot: Use memcpy/memset provided by firmware
These are significantly faster and safe us from rolling our own
optimized versions.
2022-06-10 15:54:06 +02:00
Jan Janssen 2b0af8e76a boot: Mark memcmp/memcpy/memset aliases as used
The compiler may emit calls to these but also optimize the function away
somehow, breaking at link stage. Marking them as used prevents this.
2022-06-10 15:54:02 +02:00
Jan Janssen f23b2a04e6 efi-string: Remove one more |= for bool
This one was missed in #23589.
2022-06-10 14:14:57 +02:00
James Hilliard 76abad4d47 meson: add experimental bpf-gcc compiler support
Not fully working but should make it easier to clean up remaining
issues.
2022-06-10 14:01:19 +02:00
Jan Janssen 153381952b boot: Use parse_number16 for boot counter parsing 2022-06-10 11:50:13 +02:00
Jan Janssen 1621ab4600 boot: Drop use of Atoi 2022-06-10 11:50:13 +02:00
Jan Janssen 72bd3458e5 boot: Add parse_number8/16 2022-06-10 11:50:13 +02:00
Yu Watanabe 3284dd9159 test: exclude network interfaces
After https://github.com/systemd/systemd-centos-ci/pull/492 is merged,
the networkd test may be running when test-sd-device is invoked.
Let's exclude net subsystem.
2022-06-10 18:44:21 +09:00
Yu Watanabe f9e090b16d test: always exclude devices named loop*
Not only block subsystem, but also misc has device named "loop*", and
the test always said that the following device is newly found:
---
/* test_sd_device_enumerator_filter_subsystem */
New device found: subsystem:misc syspath:/sys/devices/virtual/misc/loop-control
1 new devices are found in re-scan
---
2022-06-10 15:36:21 +09:00
Yu Watanabe da5fb1877d boot/efi-string: check the end of haystack before testing remaining pattern
Fixes buffer-overflow reported at https://github.com/systemd/systemd/pull/23589#issuecomment-1151820341.
2022-06-10 12:05:38 +09:00
Yu Watanabe c07eb49aff devnode-acl: use set_put_strdup_full() and set_ensure_consume() 2022-06-10 10:47:25 +09:00
Yu Watanabe 47484dd955 dns-domain: simplify code a bit 2022-06-10 09:49:07 +09:00
Yu Watanabe 8d896617b4 dns-domain: use dns_name_concat()
`dns_name_normalize()` is an alias of `dns_name_concat()`.
For consistency with `dns_name_is_valid_ldh()`, let's use
`dns_name_concat()`.
2022-06-10 09:42:33 +09:00
Yu Watanabe 8bf796eeac
Merge pull request #23589 from medhefgo/efi-clang
boot: Drop use of several gnu-efi functions
2022-06-10 08:54:48 +09:00
i-do-cpp 67225a96e5 fix: sd_id128_get_invocation now works for user services 2022-06-10 08:28:37 +09:00
Yu Watanabe 74223cbe14 tree-wide: fix typo 2022-06-10 08:26:08 +09:00
Frantisek Sumsal 894dad2975 test: account for ADDR_NO_RANDOMIZE if it's set
On ppc64le sanitizers disable ASLR (i.e. by setting ADDR_NO_RANDOMIZE),
which opinionated_personality() doesn't return. Let's tweak the current
personality ourselves in such cases.

See: 78f7a6eaa6

Resolves: #23666
2022-06-10 05:34:01 +09:00
Yu Watanabe 677ec2d609
Merge pull request #23348 from medhefgo/log-shutdown-blockers
shutdown: Log processes that block umount
2022-06-10 05:33:37 +09:00
Luca Boccassi 9c3e2a2a97
Merge pull request #23658 from keszybz/gcc-warnings-2
Fixes for NULL-pointer arguments based on gcc warnings
2022-06-09 17:48:09 +01:00
James Hilliard 9b948bc062 bpf: use __always_inline macro in restrict-ifaces.bpf.c
This appears to be more reliable at inlining with some compilers.
2022-06-09 17:45:11 +01:00
Jan Janssen df48b430a4 shutdown: Lazy unmount /oldroot/{dev,proc,sys}
These should not prevent us from cleaning up the remainders of /oldroot
if something in the kernel is blocking these from being unmounted.
2022-06-09 17:02:50 +02:00
Jan Janssen 20596876e3 shutdown: Log processes that block umount 2022-06-09 17:00:46 +02:00
Jan Janssen 5125b67742 shutdown: Rename umount_log_level and make it a bool
This was already effectively a bool because only ever two states were
valid. To make the meaning of it more clear, also rename it to last_try.
2022-06-09 16:50:54 +02:00
Zbigniew Jędrzejewski-Szmek c4da8e90fa systemctl: simplify code a bit
gcc insists that bus may be used unitialized here, but I don't see any
possibility of that.
2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek c90821aa49 shared/bus-util: rename variables to follow newer style 2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek 73e910926e shared/bus-util: simplification 2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek 482dac9431 test-udev-util: do not pass NULL to printf, style fixes 2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek fa1aa468b9 test-process-util: do not pass NULL to printf, simplify tests
We don't need to fork to test that the function returns -EINVAL
on null input. So let's simplify things a bit.
2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek e9edf285db test-dns-domain: a few more "NULL in printf %s"s 2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek d10cee5e90 test-fstab-util: one more "NULL in printf %s" 2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek 8b98cfb7dd various: indentation 2022-06-09 13:25:17 +02:00
Zbigniew Jędrzejewski-Szmek a78af10ae7
Merge pull request #23654 from keszybz/gcc-warnings
Fixes for NULL-pointer arguments based on gcc warnings
2022-06-09 12:55:47 +02:00
Jan Janssen 55233913c8 boot: Drop use of DuplicateDevicePath 2022-06-09 12:50:13 +02:00
Jan Janssen e17fd5538f boot: Don't copy device path
BS->LocateDevicePath only advances the passed device path pointer.
It does not actually modify it, so there is no need to make a copy.
2022-06-09 12:50:13 +02:00
Jan Janssen b05d69ed72 boot: Drop use of LibLocateHandle 2022-06-09 12:50:13 +02:00
Jan Janssen b04f818417 boot: Drop use of UnpackDevicePath
Device paths are a packed data structure and the UEFI spec is clear that
members may be misaligned.

In this case all accesses are aligned except for the signature. We can
simply memcpy it instead of making a whole (aligned) copy of the device
path.
2022-06-09 12:50:13 +02:00
Jan Janssen 79a2b916a0 boot: Drop use of FileDevicePath 2022-06-09 12:50:13 +02:00
Jan Janssen 0af26643d0 boot: Use xmalloc
This drops the unused xnew0 and xallocate_zero_pool as there is only two
users of it. _cleanup_freepool_ will be phased out once the types in the
declarations are changed/renamed.
2022-06-09 12:50:13 +02:00
Jan Janssen 9148312fab boot: Add xmalloc 2022-06-09 12:50:13 +02:00
Jan Janssen 5594ebee99 boot: Drop use of DevicePathFromHandle 2022-06-09 12:50:13 +02:00
Jan Janssen 6a261332bc boot: Drop use of LibLocateProtocol 2022-06-09 12:50:13 +02:00
Jan Janssen f747ca3ec3 boot: Drop use of LibOpenRoot 2022-06-09 12:50:13 +02:00
Jan Janssen 7ebce8145e boot: Drop use of LibGetSystemConfigurationTable 2022-06-09 12:50:13 +02:00
Jan Janssen 23742af522 boot: Drop use of MetaiMatch
A future commit will add support for unicode collation protocol that
allows case folding and comparing strings with locale awareness. But it
only operates on whole strings, so fnmatch cannot use those without a
heavy cost. Instead we just case fold the patterns instead (the IDs we
try to match are already lower case).
2022-06-09 12:50:13 +02:00
Jan Janssen 0e8ecba96e boot: Add efi_fnmatch
Unlike MetaiMatch from the UEFI spec/EDK2 this implementation is
intended to be compatible with POSIX fnmatch.
2022-06-09 12:50:08 +02:00
Zbigniew Jędrzejewski-Szmek 2299b1cae3 Resolve conflicts between #23616 and the recent NFT additions 2022-06-09 10:06:30 +02:00
Yu Watanabe 377157e6bd
Merge pull request #23616 from keszybz/in-addr-to-string-formatting
Add macros that allocate a fixed buffer for in_addr_to_string(), in_addr_prefix+to_string()
2022-06-09 15:21:57 +09:00
Zbigniew Jędrzejewski-Szmek e0d537950b test-load-fragment: don't print NULLs 2022-06-09 07:53:06 +02:00
Zbigniew Jędrzejewski-Szmek 817d19402f test-bus-address: silence gcc warning about NULL arg to strcmp()
The code was overly complicated… We know what value we expect, we can test it
directly.
2022-06-09 07:53:06 +02:00
Zbigniew Jędrzejewski-Szmek 1b3502b072 test-mountpoint-util: fix NULL arg to %s 2022-06-09 07:53:06 +02:00
Zbigniew Jędrzejewski-Szmek abcdc02cd0 sd-journal: inline variable declarations 2022-06-09 07:53:06 +02:00
Zbigniew Jędrzejewski-Szmek 70f50a4731 sd-journal: use _cleanup_ 2022-06-09 07:53:06 +02:00
Daan De Meyer a22f518676 meson: Add nspawn-locale meson option
https://github.com/systemd/systemd/pull/23192 caused breakage in
Arch Linux's build tooling. Let's give users an opt-out aside from
reverting the patch. It's hardly any maintenance work on our side
and gives users an easy way to revert the locale change if needed.

Of course, by default we still pick C.UTF-8 if the option is not
specified.
2022-06-09 13:08:27 +09:00
Nick Rosbrook c76b8751b3 nspawn: use udev_available() 2022-06-08 18:32:37 -04:00
Nick Rosbrook bfe2e67f25 libsystemd-network: use udev_available() 2022-06-08 18:32:37 -04:00
Topi Miettinen 46c3b1ff88 core: firewall integration with DynamicUserNFTSet=
New directive `DynamicUserNFTSet=` provides a method for integrating
configuration of dynamic users into firewall rules with NFT sets.

Example:
```
table inet filter {
        set u {
                typeof meta skuid
        }

        chain service_output {
                meta skuid != @u drop
                accept
        }
}
```

```
/etc/systemd/system/dunft.service
[Service]
DynamicUser=yes
DynamicUserNFTSet=inet:filter:u
ExecStart=/bin/sleep 1000

[Install]
WantedBy=multi-user.target
```

```
$ sudo nft list set inet filter u
table inet filter {
        set u {
                typeof meta skuid
                elements = { 64864 }
        }
}
$ ps -n --format user,group,pid,command -p `pgrep sleep`
    USER    GROUP     PID COMMAND
   64864    64864   55158 /bin/sleep 1000
```
2022-06-08 16:12:25 +00:00
Topi Miettinen c0548df0a2 core: firewall integration with ControlGroupNFTSet=
New directive `ControlGroupNFTSet=` provides a method for integrating services
into firewall rules with NFT sets.

Example:

```
table inet filter {
...
        set timesyncd {
                type cgroupsv2
        }

        chain ntp_output {
                socket cgroupv2 != @timesyncd counter drop
                accept
        }
...
}
```

/etc/systemd/system/systemd-timesyncd.service.d/override.conf
```
[Service]
ControlGroupNFTSet=inet:filter:timesyncd
```

```
$ sudo nft list set inet filter timesyncd
table inet filter {
        set timesyncd {
                type cgroupsv2
                elements = { "system.slice/systemd-timesyncd.service" }
        }
}
```
2022-06-08 16:12:25 +00:00
Topi Miettinen ab51fd9dbd network: firewall integration with NFT sets
New directives `NFTSet=`, `IPv4NFTSet=` and `IPv6NFTSet=` provide a method for
integrating configuration of dynamic networks into firewall rules with NFT
sets.

/etc/systemd/network/eth.network
```
[DHCPv4]
...
NFTSet=netdev:filter:eth_ipv4_address
```

```
table netdev filter {
        set eth_ipv4_address {
                type ipv4_addr
                flags interval
        }
        chain eth_ingress {
                type filter hook ingress device "eth0" priority filter; policy drop;
                ip saddr != @eth_ipv4_address drop
                accept
        }
}
```
```
sudo nft list set netdev filter eth_ipv4_address
table netdev filter {
        set eth_ipv4_address {
                type ipv4_addr
                flags interval
                elements = { 10.0.0.0/24 }
        }
}
```
2022-06-08 16:12:25 +00:00
Luca Boccassi e8f1b50f27
Merge pull request #23641 from keszybz/janitorials
Janitorial cleanups
2022-06-08 17:08:13 +01:00
Daan De Meyer 647475c7df basic: Propagate SIGBUS signal info when re-raising signals
raise() won't propagate the siginfo information of the signal that's
re-raised. rt_sigqueueinfo() allows us to provide the original siginfo
struct which makes sure it is propagated to the next signal handler
(or to the coredump).
2022-06-07 19:10:34 +01:00
Zbigniew Jędrzejewski-Szmek 0d7e34e3e6 basic/socket-util: align tables 2022-06-07 15:18:46 +02:00
Zbigniew Jędrzejewski-Szmek 76973becae activate: reduce scope of iterator variables 2022-06-07 15:18:46 +02:00
Zbigniew Jędrzejewski-Szmek 09f4d843ee core: wrap some long comments 2022-06-07 15:18:46 +02:00
Zbigniew Jędrzejewski-Szmek 066a6f0768 shared/condition: reduce scope of variables 2022-06-07 15:18:38 +02:00
Zbigniew Jędrzejewski-Szmek da60e5b5c7 bootctl: inline iterator variable 2022-06-07 15:17:06 +02:00
Daan De Meyer db6f9b02a7
Merge pull request #23645 from DaanDeMeyer/journalctl-static-destructor
journalctl: Use STATIC_DESTRUCTOR_REGISTER()
2022-06-07 12:28:37 +01:00
Zbigniew Jędrzejewski-Szmek 85b0ff8abf sd-journal: fix NULL arg to %s in error messages and hashmap lookup
The lookup "works", but is not useful. It was introduced in
9c66f52813.

And printf will NULL args is invalid was introduced in
5d1ce25728 when support for fds was initally
added :(
2022-06-07 11:22:15 +02:00
Zbigniew Jędrzejewski-Szmek 9908091b96 sd-hwdb: fix NULL arg to %s in error messages
gcc warns about $subject, and it is obviously correct. path may or
may not be set.
2022-06-07 11:22:15 +02:00
Zbigniew Jędrzejewski-Szmek 6c279977e3 basic/unit-file: make sure we don't call streq() on NULL
add_names is called in two places, with fragment_basename=NULL in one of them.
gcc warns that it can be NULL.

Fixes #23646.
2022-06-07 11:22:08 +02:00
Michael Biebl 5fb225615b meson: install libsystemd-shared into rootpkglibdir
Introduce rootpkglibdir for installing libsystemd-{shared,core}.so.
The benefit over using rootlibexecdir is that this path can be
multiarch aware, i.e. this path can be architecture qualified.

This is something we'd like to make use of in Debian/Ubuntu to make
libsystemd-shared co-installable, e.g. for i386 the path would be
/usr/lib/i386-linux-gnu/systemd/libsystemd-shared-*.so and for amd64
/usr/lib/x86_64-linux-gnu/systemd/libsystemd-shared-*.so.
This will allow for example to install and run systemd-boot/i386 on an
amd64 host. It also simplifies/enables cross-building/bootstrapping.

For more infos about Multi-Arch see https://wiki.debian.org/Multiarch.

See also https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=990547
2022-06-07 10:04:43 +02:00
Topi Miettinen 3cf63830ac networkd: NetLabel integration
New directive `NetLabel=` provides a method for integrating dynamic network
configuration into Linux NetLabel subsystem rules, used by Linux security
modules (LSMs) for network access control. The option expects a whitespace
separated list of NetLabel labels. The labels must conform to lexical
restrictions of LSM labels. When an interface is configured with IP addresses,
the addresses and subnetwork masks will be appended to the NetLabel Fallback
Peer Labeling rules. They will be removed when the interface is
deconfigured. Failures to manage the labels will be ignored.

Example:
```
[DHCP]
NetLabel=system_u:object_r:localnet_peer_t:s0
```

With the above rules for interface `eth0`, when the interface is configured with
an IPv4 address of 10.0.0.0/8, `systemd-networkd` performs the equivalent of
`netlabelctl` operation

```
$ sudo netlabelctl unlbl add interface eth0 address:10.0.0.0/8 label:system_u:object_r:localnet_peer_t:s0
```

Result:
```
$ sudo netlabelctl -p unlbl list
...
 interface: eth0
   address: 10.0.0.0/8
    label: "system_u:object_r:localnet_peer_t:s0"
...
```
2022-06-06 18:24:10 +00:00
Shreenidhi Shedi 41abd7f6df execute: fix resource leak
CID#1431998
2022-06-06 16:34:37 +02:00
Daan De Meyer 2e64b27aeb journalctl: Use STATIC_DESTRUCTOR_REGISTER() 2022-06-06 16:04:53 +02:00
Daan De Meyer e30c1d01b6 shared: Rename pcre2-dlopen.h/c to pcre2-util.h/c
We already store the dlopen() stuff for other libraries in util headers
as well so let's do the same for pcre2. We also move the definition of
some trivial cleanup functions from journalctl.c to pcre2-util.h
2022-06-06 16:01:20 +02:00
Zbigniew Jędrzejewski-Szmek 369151c9c7
Merge pull request #23621 from evverx/clang-release
ci: build systemd with clang with -Dmode=release --optimization=2
2022-06-06 12:17:48 +02:00
Zbigniew Jędrzejewski-Szmek 89eb3d7c95 various: use CONST_MAX for array allocation
IIUC, with MAX() we get a VLA and the size is "decided" at runtime,
even though the result is always the same, but with CONST_MAX() we
get a normal stack variable.
2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek 071e522eec tree-wide: convert inet_ntop() calls to anonymous-buffer macros 2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek c71384a9ee basic/in-addr-util: add IN_ADDR_PREFIX_TO_STRING 2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek 61af181344 basic/in-addr-util: drop check for prefix length in formatting function
The general rule should be to be strict when parsing data, but lenient
when printing it. Or in other words, we should verify data in verification
functions, but not when printing things. It doesn't make sense to refuse
to print a value that we are using internally.

We were tripping ourselves in some of the print functions:
we want to report than an address was configured with too-long prefix, but
the log line would use "n/a" if the prefix was too long. This is not useful.

Most of the time, the removal of the check doesn't make any difference,
because we verified the prefix length on input.
2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek dd6d433a4f libsystemd-network: minor simplification 2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek f69ea167eb resolved: use TAKE_PTR() in one more place 2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek 94a779628a networkctl: assume that we can always print local networking addresses
IN6_ADDR_TO_STRING(…) always returns something, so we can simplify the code a
lot. Also, let's not do step-wise concatenation, but instead handle everything
with one str_extendf() call.
2022-06-06 09:52:52 +02:00
Zbigniew Jędrzejewski-Szmek 84dbb3fd83 basic/in-addr-util: add IN_ADDR_TO_STRING
Since we don't need the error value, and the buffer is allocated with a fixed
size, the whole logic provided by in_addr_to_string() becomes unnecessary, so
it's enough to wrap inet_ntop() directly.

inet_ntop() can only fail with ENOSPC. But we specify a buffer that is supposed
to be large enough, so this should never fail. A bunch of tests of this are added.
This allows all the wrappers like strna(), strnull(), strempty() to be dropped.

The guard of 'if (DEBUG_LOGGING)' can be dropped from around log_debug(),
because log_debug() implements the check outside of the function call. But
log_link_debug() does not, so it we need it to avoid unnecessary evaluation of
the formatting.
2022-06-06 09:52:52 +02:00
Evgeny Vereshchagin 2cfb790391 Revert "Support -D_FORTIFY_SOURCE=3 by using __builtin_dynamic_object_size."
This reverts commit 0bd292567a.

It isn't guaranteed anywhere that __builtin_dynamic_object_size can
always deduce the size of every object passed to it so systemd
can end up using either malloc_usable_size or
__builtin_dynamic_object_size when pointers are passed around,
which in turn can lead to actual segfaults like the one mentioned in
https://github.com/systemd/systemd/issues/23619.

Apparently __builtin_object_size can return different results for
pointers referring to the same memory as well but somehow it hasn't
caused any issues yet. Looks like this whole
malloc_usable_size/FORTIFY_SOURCE stuff should be revisited.

Closes https://github.com/systemd/systemd/issues/23619 and
https://github.com/systemd/systemd/issues/23150.

Reopens https://github.com/systemd/systemd/issues/22801
2022-06-05 19:13:17 +00:00
Shreenidhi Shedi 5c95eb2888 manager: ignore return value of unit_watch_pid()
Also, explicitly ignore return value of service_set_main_pid() calls in
few places.

Fixes: CID#1474975
2022-06-05 22:58:01 +05:30
Shreenidhi Shedi 8d862fd39d machinectl: ignore return value of get_process_comm()
Fixes: CID#1469720
2022-06-05 22:58:01 +05:30
Shreenidhi Shedi a30c9e7176 polkit: explicitly ignore fd_wait_for_event()'s return value
Fixes: CID#1469718
2022-06-05 22:58:01 +05:30
Zbigniew Jędrzejewski-Szmek b547241728 shared/microhttp-util: silence gcc warning
../src/journal-remote/microhttpd-util.c: In function ‘check_permissions’:
../src/journal-remote/microhttpd-util.c:301:5: error: function might be candidate for attribute ‘noreturn’ [-Werror=suggest-attribute=noreturn]
  301 | int check_permissions(struct MHD_Connection *connection, int *code, char **hostname) {
      |     ^~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors

Fixes #23630.
2022-06-05 15:57:39 +00:00
Zbigniew Jędrzejewski-Szmek ea4f2d5fb7 core: suppress message about missing libbpf if in initrd()
It is quite likely that libbpf is not present in the initrd, and
there isn't much reason to use the bpf filters there.

https://bugzilla.redhat.com/show_bug.cgi?id=2084955#c25
2022-06-04 03:20:47 +09:00
Antonio Alvarez Feijoo d48cfc98eb cryptenroll: fix typo 2022-06-03 17:27:22 +02:00
Zbigniew Jędrzejewski-Szmek 3a2a0806f5
Merge pull request #23297 from medhefgo/trivial-auto-var-init
meson: Compile with -ftrivial-auto-var-init
2022-06-03 15:27:51 +02:00
Zbigniew Jędrzejewski-Szmek 38c87ca2ab sha256: fix compilation on efi-ia32
/usr/bin/gcc -c ../src/fundamental/sha256.c -o src/boot/efi/sha256.c.o -Wno-format-signedness -Wno-missing-field-initializers -Wno-unused-parameter -Wdate-time -Wendif-labels -Werror=format=2 -Werror=implicit-function-declaration -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wno-unused-result -fno-stack-protector -fno-strict-aliasing -fpic -fwide-exec-charset=UCS2 -Wall -Wextra -Wsign-compare -nostdlib -std=gnu99 -ffreestanding -fshort-wchar -fvisibility=hidden -isystem /usr/include/efi -isystem /usr/include/efi/ia32 -I /builddir/build/BUILD/systemd-stable-250.7/src/fundamental -DSD_BOOT -DGNU_EFI_USE_MS_ABI -include src/boot/efi/efi_config.h -include version.h -mno-sse -mno-mmx -flto -O2 -flto=auto
../src/fundamental/sha256.c: In function ‘sha256_finish_ctx’:
../src/fundamental/sha256.c:61:25: error: ‘false’ undeclared (first use in this function)
   61 | # define UNALIGNED_P(p) false
      |                         ^~~~~
../src/fundamental/sha256.c:136:21: note: in expansion of macro ‘UNALIGNED_P’
  136 |                 if (UNALIGNED_P(resbuf))
      |                     ^~~~~~~~~~~
../src/fundamental/sha256.c:32:1: note: ‘false’ is defined in header ‘<stdbool.h>’; did you forget to ‘#include <stdbool.h>’?
   31 | #include "sha256.h"
  +++ |+#include <stdbool.h>
   32 |
...
2022-06-03 19:09:54 +09:00
Yu Watanabe 311f57a402
Merge pull request #23583 from yuwata/boot-efi-string-follow-ups
boot: follow-ups for efi-string functions
2022-06-03 10:23:24 +09:00
Christian Hesse d6e2c2d34d shared/utmp-wtmp: fix build without utmp
Commit 1661833238 changed a function to
add an extra argument. The data types used when building without utmp
missed the change.
2022-06-03 05:00:50 +09:00
Yu Watanabe 0a11366280 login: fix typo
Follow-up for ea74f39c24.
2022-06-03 04:28:01 +09:00
Yu Watanabe 095e173a04 boot: use CMP() macro for safety 2022-06-03 04:20:46 +09:00
Yu Watanabe 42e785d096 boot: make several functions inline
Follow-ups for #23512.
2022-06-03 04:20:46 +09:00
Yu Watanabe a54e635d02 boot: fix typo 2022-06-03 04:20:46 +09:00
Zbigniew Jędrzejewski-Szmek e78bd91e55
Merge pull request #23596 from keszybz/bpf-messages-more
Silence messages from libbpf
2022-06-02 19:48:01 +02:00
Zbigniew Jędrzejewski-Szmek 4c989f89b6 core: rework variable initialization to avoid gcc warning
In file included from ../src/basic/siphash24.h:11,
                 from ../src/basic/hash-funcs.h:6,
                 from ../src/basic/hashmap.h:8,
                 from ../src/shared/fdset.h:6,
                 from ../src/shared/bpf-program.h:9,
                 from ../src/core/unit.h:11,
                 from ../src/core/all-units.h:4,
                 from ../src/core/manager.c:23:
../src/basic/time-util.h: In function 'manager_dispatch_jobs_in_progress':
../src/basic/time-util.h:140:38: error: 'x' may be used uninitialized [-Werror=maybe-uninitialized]
  140 | #define FORMAT_TIMESPAN(t, accuracy) format_timespan((char[FORMAT_TIMESPAN_MAX]){}, FORMAT_TIMESPAN_MAX, t, accuracy)
      |                                      ^~~~~~~~~~~~~~~
In function 'manager_print_jobs_in_progress',
    inlined from 'manager_dispatch_jobs_in_progress' at ../src/core/manager.c:3007:9:
../src/core/manager.c:219:18: note: 'x' was declared here
  219 |         uint64_t x;
      |                  ^
cc1: all warnings being treated as errors

For some reason this (false positive) warning starts appearing after
-ftrivial-auto-var-init is used.
2022-06-02 17:31:55 +02:00
Zbigniew Jędrzejewski-Szmek 6a9f3cef8c
Merge pull request #23576 from yuwata/network-erspan-version
network: support erspan version 0 and 2
2022-06-02 16:58:55 +02:00
Zbigniew Jędrzejewski-Szmek 7e5c7522e8
Merge pull request #23579 from yuwata/sha256-unaligned
sha256: use memcpy() to accept unaligned result buffer
2022-06-02 16:38:19 +02:00
Zbigniew Jędrzejewski-Szmek d7cf4ba6f3
Merge pull request #23582 from bnf/dns-proxy-stub-ifindex
resolved: define source address for proxy-only stub replies
2022-06-02 16:34:55 +02:00
Zbigniew Jędrzejewski-Szmek b1acbc08e2 core/bpf: prefix log messages from different bpf subsystems
When something goes awry, we would get identical log messages from all the
bpf subsystems. E.g. "Failed to load BPF object: %m" appeared 5 times in the
sources. But it is very important to know *which* object we failed to load.
This could be guessed, e.g. from surroudning messages or from filename/line
metadata, but when we get log messages in bug reports, this might not be
available. Let's make the messages distinguishable.

While at it, some messages were adjusted a bit. In particular, we shouldn't use
internal names like BPFProgram which have no meaning outside of the codebase.
2022-06-02 15:59:41 +02:00
Zbigniew Jędrzejewski-Szmek bb0b01ed20 core: define a helper function for basic bpf checks 2022-06-02 15:59:41 +02:00
Zbigniew Jędrzejewski-Szmek 62b045b45c test-socket-bind: fix comment 2022-06-02 10:48:31 +02:00
Zbigniew Jędrzejewski-Szmek b1fdcda876 tests: drop pointless checks for root
Testing the error paths is very important. If we are not root, we should
try and get a failure, which we should report nicely and mark the test
as skipped. After those checks are removed, this is what seems to happen.
This way we can see what will happen e.g. in the user manager when we try
to perform some bpf ops.
2022-06-02 10:48:31 +02:00
Zbigniew Jędrzejewski-Szmek 44005a5778 shared/bpf: install log callback and suppress most messages from libbpf
$ build/test-socket-bind
...
libbpf: load bpf program failed: Operation not permitted
libbpf: failed to load program 'sd_bind4'
libbpf: failed to load object 'socket_bind_bpf'
libbpf: failed to load BPF skeleton 'socket_bind_bpf': -1
Failed to load BPF object: Operation not permitted

Now all lines with "libbpf:" are at debug level and will be hidden by
default.

Partially fixes https://bugzilla.redhat.com/show_bug.cgi?id=2084955#c14
(i.e. the error that was exposed when the initial error was fixed.)
2022-06-02 10:48:31 +02:00
Zbigniew Jędrzejewski-Szmek 386b8026e5 meson: use files() for libcore_sources too
C.f. f1b98127ff.
2022-06-02 07:53:14 +02:00
Zbigniew Jędrzejewski-Szmek c6cb9d9074 userwork: use a better errno value
ESRCH is literally "No such process".
2022-06-02 07:53:14 +02:00
Zbigniew Jędrzejewski-Szmek 2e09b2235a various: add %m in messages
Sometimes we want to suppress strerror() message because the are providing
something better. But in those cases, it seems it was just forgotten.
2022-06-02 07:53:14 +02:00
Yu Watanabe 93d13a7dff test: fix indentation 2022-06-02 14:14:22 +09:00
Yu Watanabe 3bccc736c6 test: add test for sha256 2022-06-02 14:14:22 +09:00
Yu Watanabe c7a5eabeba sha256: use memcpy() when result buffer is unaligned
Fixes #23578.
2022-06-02 14:14:22 +09:00
Zbigniew Jędrzejewski-Szmek af72f975fe Move basic/recovery-key.* to shared/
No particular reason to have it in basic/. We should let homectl
and other users share the single copy through libsystemd-shared.
2022-06-02 13:09:09 +09:00
Zbigniew Jędrzejewski-Szmek 14c811ff4a
Merge pull request #23575 from keszybz/logind-wall-message-cleanup
Cleanup wall messages emitted by logind and systemctl
2022-06-01 16:26:29 +02:00
Zbigniew Jędrzejewski-Szmek d5254fa2f6
Merge pull request #23574 from keszybz/logind-pty-wall
Do not print logind wall message to local terminals
2022-06-01 16:26:03 +02:00
Benjamin Franzke de777ffae8 resolved: choose correct file descriptor for proxy stub replies
find_socket_fd() does not expect the sender address, but the
listen-address. This is in fact the destination of the DNS packet.
Matching via sender address caused a fallback to the default stub
listener in manager_dns_stub_fd() as the sender address can never
match the proxy stub listen address.

Note that manager_dns_stub_fd() is only used for the default
listener stub and the proxy stub, that means *extra* listeners
stubs (DNSStubListenerExtra=…) have not been affected as
`struct DnsStubListenerExtra` provides a direct link to the event
source.

By using the correct fd we ensure the correct socket options
(like TTL) are used and prevent issues like #23495 in case ifindex
could not be determined.
2022-06-01 15:08:33 +02:00
Li kunyu b278cf2efd src: The return value of server_vacuum () is not used and could be modified to void type 2022-06-01 09:32:22 +02:00
Christian Göttsche ea74f39c24 login: do not issue wall messages on local terminals for suspend and hibernate
Fixes: #23520

[zjs: I added the comment and tweaked the patch a bit.

The call to reset_scheduled_shutdown() is moved down a bit to allow the
callback to have access to information about the operation being cancelled.
This all happens within the same function, so there should be no observable
change in behaviour.]
2022-06-01 09:30:07 +02:00
Zbigniew Jędrzejewski-Szmek b622d2f789 shared/pager: print the name of the pager we'll try next in debug message
I had a strange failure where the pager was hanging on invocation (gdm crashed
and the kernel got into a strange state where it was hanging on some tasks).
Based on the logs from 'SYSTEMCTL_LOG_LEVEL=debug journalctl', I couldn't even
tell which pager binary we're executing. So let's shorten the function a bit and
provide a bit more detail.
2022-06-01 09:27:35 +02:00
Zbigniew Jędrzejewski-Szmek 5b69a7c540 man/systemctl: improve grammar in description of --check-inhibitors 2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek 1cc11a0951 systemctl: drop translation of method names to descriptions in error message
We had yet-another table of descriptive strings to use in error messages.
I started thinking how to synchronize them with the strings in logind, but
ultimately I think it's better to remove those altogether. Those strings
should almost never be used: normally if the call fails, logind will provide
an error message itself, which is probably more detailed than what we can
figure out on the client side. And the most important part that we want to
show here is what exactly we called, in particular RebootWithFlags vs. Reboot,
etc. By using the "descriptive strings" we were obfuscating this. So let's just
simplify our code and print the actual method name, since this is more useful
as an error statement that is googlable and unique.

While at it, let's print the correct method name ;)
2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek 346840b159 systemctl: make function static 2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek b280061314 logind: reduce scope of a few variables 2022-06-01 09:23:55 +02:00
Zbigniew Jędrzejewski-Szmek 3dbb9bc5eb logind: rework wall message about pending shutdown/halt/reboot/…
Those messages simply *feel* dated: "The system is going for suspend NOW!".
Let's say "The system will suspend|power off|hibernate|… now!" instead.
The exclamation mark is enough to show the urgency.

Also, the "the" seemed out of place. We're not talking about a specific reboot.
2022-06-01 09:23:05 +02:00
Yu Watanabe 9db25d01ef
Merge pull request #23531 from yuwata/sd-bus-drop-version-2
sd-bus: drop version 2 format support
2022-06-01 14:51:44 +09:00
Yu Watanabe cd25e17001
Merge pull request #23512 from medhefgo/efi-clang
boot: Add string functions
2022-06-01 06:16:48 +09:00
Benjamin Franzke dfa14e2859 resolved: define source address for proxy-only stub replies
DnsPacket.ifindex=1 (loopback) is normalized to 0 whenever a message is
received on the loopback iface, so for both listeners, 127.0.0.53 and
127.0.0.54, the ifindex will be set to 0 by manager_recv() for queries
that have a local origin.

Replies to such local messages need to set a proper ifindex in any
case, as the supplied source-address would otherwise be ignored in
manager_ipv4_send() (CMSG generation is skipped due to ifindex > 0 check).

Note that this change only forces `ifindex` to loopback if it was actually
normalized to `0` before (due to a loopback detection) in order to keep the
nat-to-127.0.0.54-from-another-interface usecase that was described in
a8d0906344 intact.
Also note that nat is not supported for the main stub 127.0.0.53 which is
why forcing LOOPBACK_IFINDEX was/is fine for that case.

Fixes #23495
2022-05-31 22:38:47 +02:00
Zbigniew Jędrzejewski-Szmek 51a2b575d7 logind: do not print wall messages to local pseudoterminals
Fixes #23520. Replaces #23555.

The problem started with cdf370626f and
90b1ec03b2 which together started printing the
wall message in more cases. The motivation for those change was reasonable, but
this clearly causes problems described in #23520: users are getting unexpected
wall messages. Xterm, urxvt, (anything using libutempter?), and tmux (in some
configurations), register local pty sessions in utmp.

So let's try to suppress the message for local pseudo-terminal logins. This
patch based on #23538, but instead of filtering just on /dev/pts, it uses the
.ut_addr_v6 to only filter out local entries.
2022-05-31 22:30:08 +02:00
Zbigniew Jędrzejewski-Szmek e31355bbc1 tests: add a helper that dumps /run/utmp in detail
utmpdump doesn't print all the details. Looking at the list if useful
when trying to tweak the wall filtering logic.

This doesn't do much, but at least it serves as a smoke test for the cleanup
functions.
2022-05-31 22:30:08 +02:00
Yu Watanabe 98406eda8a network/erspan: support erspan version 0 and 2
This also makes networkd accepts erspan index 0.

Closes #23570.
2022-06-01 04:02:48 +09:00
Yu Watanabe a452cfd77b sd-bus: drop constant argument for message_extend_fields() 2022-06-01 03:41:16 +09:00
Yu Watanabe 0dd4876815 sd-bus: drop D-Bus version 2 format support
It seems the format is used only by kdbus.
2022-06-01 03:41:15 +09:00
Yu Watanabe c0f664ca89 sd-bus: merge message_peek_fields() and buffer_peek() 2022-06-01 03:41:15 +09:00
Yu Watanabe 75c85c3b25 sd-bus: make several functions static
And drop 'bus_' prefix from them.
2022-06-01 03:41:15 +09:00
Yu Watanabe 590a738562 sd-bus: use UINT32_MAX 2022-06-01 03:41:15 +09:00
Yu Watanabe b7096bd690 sd-bus: drop unnecessary cast 2022-06-01 03:41:15 +09:00
Yu Watanabe 30da99bd30 sd-bus: drop redundant condition
By the previous commit, ALIGN8() is always equal to or greater than the
argument.
2022-06-01 03:41:15 +09:00
Yu Watanabe dc7be33266 sd-bus: use ALIGN8() 2022-06-01 03:41:15 +09:00
Yu Watanabe b4e7df4a47 boot: use ALIGN4() 2022-06-01 03:41:15 +09:00
Yu Watanabe 4c8d7caf1a macro: make ALIGN4() and ALIGN8() also return SIZE_MAX on overflow
This also drops unused ALIGN4_PTR(), ALIGN8_PTR(), and ALIGN_TO_PTR().
2022-06-01 03:40:20 +09:00
Yu Watanabe 394129f88b tree-wide: use ALIGN_PTR() 2022-06-01 03:12:33 +09:00
Yu Watanabe a0f0cf0a6b portable: fix command option in comment
Follow-up for edea370222.
2022-05-31 16:32:09 +02:00
Zbigniew Jędrzejewski-Szmek 978af07f66 logind: use consistent casing in message
The other strings use "sentence capitalization". Let's do the
same here.
2022-05-31 15:59:40 +02:00
Zbigniew Jędrzejewski-Szmek 3c98bdce55 logind: align tables 2022-05-31 15:59:29 +02:00
Zbigniew Jędrzejewski-Szmek 1661833238 shared/utmp-wtmp: pass information if entry is local to filter function
This just adds an unused parameter for future use. No change in
behaviour.
2022-05-31 15:54:16 +02:00
Zbigniew Jędrzejewski-Szmek b5cb2d2847 tty-ask-password-agent: drop unnecessary code for non-absolute paths
utmp_wall() always prepends /dev/, so we don't need to do this a second
time here.
2022-05-31 15:54:03 +02:00
Jan Janssen 7783ab5df1 boot: Use xstrdup8/16
Note that xstrdup is now safe to call with a NULL pointer and will
just return NULL in that case.
2022-05-31 15:15:01 +02:00
Jan Janssen 101f68ff33 boot: Add xstrdup8/16 2022-05-31 15:15:01 +02:00
Jan Janssen bbc1f2eac5 boot: Use memcmp/memcpy/memset 2022-05-31 15:15:01 +02:00
Jan Janssen f7967716e3 boot: Add memcmp/memcpy/memset 2022-05-31 15:14:56 +02:00
Jan Janssen 60c2af56d6 boot: Use strsize8/16 2022-05-31 15:14:56 +02:00
Jan Janssen 96dc0dd387 boot: Add strsize8/16 2022-05-31 15:14:54 +02:00
Jan Janssen fb67588c62 boot: Use strchr8/16 2022-05-31 15:13:58 +02:00
Jan Janssen 5d7e0e8341 boot: Add strchr8/16 2022-05-31 15:13:58 +02:00
Jan Janssen 08ed842b56 boot: Use strcpy8/16 2022-05-31 15:10:48 +02:00
Jan Janssen ef4d71ad7f boot: Add strcpy8/16 2022-05-31 15:10:48 +02:00
Jan Janssen fc178cf1f8 boot: Use strtolower8/16 2022-05-31 15:10:48 +02:00
Jan Janssen 98850528bf boot: Add strtolower8/16 2022-05-31 15:10:45 +02:00
Jan Janssen 3d5127c68f boot: Use strcmp16 for cpio sorting 2022-05-31 15:09:10 +02:00
Jan Janssen ec436bdf16 boot: Use strcmp8/16
This also replaces streq and similar functions for consistency. Note
that streq16 is null pointer safe, so streq_ptr can be safely replaced
too.
2022-05-31 15:09:10 +02:00
Jan Janssen 0d933d024a boot: Add strcmp8/16 2022-05-31 15:09:06 +02:00
Jan Janssen 5f49747255 boot: Use strlen8/16
The casts in this and the next few commits are curently necessary
because CHAR8 is defined as uint8_t in gnu-efi, while char is signed.
Once we switch from gnu-efi typedefs to stdint types, the casts
will be dropped.
2022-05-31 14:18:43 +02:00
Jan Janssen 9080ffd4cd boot: Add strlen8/16 2022-05-31 14:18:43 +02:00
Jan Janssen 11f9a32de0 boot: Use stddef.h offsetof 2022-05-31 14:18:43 +02:00
Frantisek Sumsal a52765a550 seccomp: fix a typo in error message 2022-05-31 18:29:40 +09:00
Yu Watanabe 71891fb2de
Merge pull request #23558 from msekletar/issue-20329-followup
Actually delay running of mount start jobs when /p/s/mountinfo is rate limited
2022-05-31 17:38:25 +09:00
Jason A. Donenfeld 87cb1ab676 Simplify random number selection
We currently have a convoluted and complex selection of which random
numbers to use. We can simplify this down to two functions that cover
all of our use cases:

1) Randomness for crypto: this one needs to wait until the RNG is
   initialized. So it uses getrandom(0). If that's not available, it
   polls on /dev/random, and then reads from /dev/urandom. This function
   returns whether or not it was successful, as before.

2) Randomness for other things: this one uses getrandom(GRND_INSECURE).
   If it's not available it uses getrandom(GRND_NONBLOCK). And if that
   would block, then it falls back to /dev/urandom. And if /dev/urandom
   isn't available, it uses the fallback code. It never fails and
   doesn't return a value.

These two cases match all the uses of randomness inside of systemd.

I would prefer to make both of these return void, and get rid of the
fallback code, and simply assert in the incredibly unlikely case that
/dev/urandom doesn't exist. But Luca disagrees, so this commit attempts
to instead keep case (1) returning a return value, which all the callers
already check, and fix the fallback code in (2) to be less bad than
before.

For the less bad fallback code for (2), we now use auxval and some
timestamps, together with various counters representing the invocation,
hash it all together and provide the output. Provided that AT_RANDOM is
secure, this construction is probably okay too, though notably it
doesn't have any forward secrecy. Fortunately, it's only used by
random_bytes() and not by crypto_random_bytes().
2022-05-31 09:20:52 +02:00
Zbigniew Jędrzejewski-Szmek fada4bdcaa
Merge pull request #23533 from yuwata/portable-remove-drop-in-configs
portable: remove drop-in configs
2022-05-31 08:52:30 +02:00
Yu Watanabe 4282f39430
Merge pull request #23564 from yuwata/core-unit-add-dep
core: fix notification about unit dependency change
2022-05-31 14:07:34 +09:00
msizanoen1 37f0289bf5 cgroup-util: Properly handle conditions where cgroup.threads is empty after SIGKILL but processes still remain
After sending a SIGKILL to a process, the process might disappear from
`cgroup.threads` but still show up in `cgroup.procs` and still remains in the
cgroup and cause migrating new processes to `Delegate=yes` cgroups to fail with
`-EBUSY`. This is especially likely for heavyweight processes that consume more
kernel CPU time to clean up.

Fix this by only returning 0 when both `cgroup.threads` and
`cgroup.procs` are empty.
2022-05-31 05:03:31 +09:00
Yu Watanabe 9a18321058
Merge pull request #23560 from mrc0mmand/coccinelle
A couple of tweaks suggested by Coccinelle
2022-05-31 05:02:57 +09:00
Yu Watanabe a8c5a4c6c2 core: make unit_add_two_dependencies() or friends return 1 on changed
Follow-up for f971def3c2.
2022-05-31 01:53:11 +09:00
Yu Watanabe ac17080c04 core/unit: fix notification about unit dependency change
This also makes unit_add_dependency() return 1 only when a dependency
is added.
2022-05-31 01:53:11 +09:00
Yu Watanabe 5473bc61af esp: fix typo
Follow-up for 13d7c841a2.
2022-05-31 01:17:34 +09:00
Frantisek Sumsal 81aa8d4130 journal: return & log in one statement 2022-05-30 18:12:58 +02:00
Frantisek Sumsal 4c7f7f4b22 analyze: use IN_SET() in one more place 2022-05-30 18:12:55 +02:00
Yu Watanabe edea370222 portable: remove drop-in configs even if the main unit file does not exist
When we run `portablectl detach --enable --runtime`, then it triggers
`DisableUnitFilesWithFlags` DBus method and the main unit file is
removed, but its drop-ins are not. Hence, portable_detach() failed to
list existing portable units.

This makes the loop for listing portable units also accept drop-in
directories. So, all remaining drop-in directories are correctly
removed.

Before:
```
testsuite-29.sh[600]: + portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
portablectl[1391]: (Matching unit files with prefixes 'minimal-app0'.)
portablectl[1391]: Queued /org/freedesktop/systemd1/job/1812 to call StopUnit on portable service minimal-app0-foo.service.
portablectl[1391]: Removed "/run/systemd/system.attached/minimal-app0-foo.service".
portablectl[1391]: Queued /org/freedesktop/systemd1/job/1813 to call StopUnit on portable service minimal-app0.service.
portablectl[1391]: Removed "/run/systemd/system.attached/minimal-app0.service".
portablectl[1391]: Got result done/Success for job minimal-app0-foo.service
portablectl[1391]: Got result done/Success for job minimal-app0.service
portablectl[1391]: DetachImage failed: No unit files associated with '/tmp/rootdir' found attached to the system. Image not attached?
```

After:
```
testsuite-29.sh[508]: + portablectl detach --now --runtime --enable /tmp/rootdir minimal-app0
portablectl[1076]: (Matching unit files with prefixes 'minimal-app0'.)
portablectl[1076]: Queued /org/freedesktop/systemd1/job/1946 to call StopUnit on portable service minimal-app0-foo.service.
portablectl[1076]: Removed "/run/systemd/system.attached/minimal-app0-foo.service".
portablectl[1076]: Queued /org/freedesktop/systemd1/job/1947 to call StopUnit on portable service minimal-app0.service.
portablectl[1076]: Removed "/run/systemd/system.attached/minimal-app0.service".
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0.service.d/10-profile.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0.service.d/20-portable.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0.service.d.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0-foo.service.d/10-profile.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0-foo.service.d/20-portable.conf.
portablectl[1076]: Removed /run/systemd/system.attached/minimal-app0-foo.service.d.
portablectl[1076]: Removed /run/portables/rootdir.
portablectl[1076]: Removed /run/systemd/system.attached.
```
2022-05-31 01:09:29 +09:00
Yu Watanabe 8288382049
Merge pull request #23354 from DaanDeMeyer/mount-implicit-device-dep-trace
core: Add trace logging to mount_add_device_dependencies()
2022-05-31 01:00:56 +09:00
Michal Sekletar b161bc394b unit: check for mount rate limiting before checking active state
Having this check as part of mount_can_start() is too late because
UNIT(u)->can_start() virtual method is called after checking the active
state of unit in unit_start().

We need to hold off running mount start jobs when /p/s/mountinfo monitor
is rate limited even when given mount unit is already active.

Fixes #20329
2022-05-30 13:22:16 +02:00
Zbigniew Jędrzejewski-Szmek 02ece2fcb1
Merge pull request #23529 from nabijaczleweli/dollar-asterisk
Don't linebreak after each initrd in kernel-install verbose mode
2022-05-30 10:27:14 +02:00
Jan Janssen 5476cb988c meson: Build header tests with -pedantic
By using __extension__, we can silence pedantic errors we cannot or
do not want to fix.

This in particular silences:
 - enum values being outside of int range
 - variadic macros
 - long long being C99
 - type of bit-field ‘type’ is a GCC extension
 - use of C99 bool in public header functions
2022-05-30 05:06:36 +09:00
Yu Watanabe 6a49fcdb3c portable: try to remove unit files even in a spurious state 2022-05-30 04:34:43 +09:00
Yu Watanabe 1b1e53d2a8 test: drop redundant log message 2022-05-30 04:17:54 +09:00
Yu Watanabe ba780ccd5f
Merge pull request #23542 from medhefgo/attributes
meson: Document why -Wimplicit-fallthrough is not used with clang
2022-05-30 04:07:41 +09:00
Evgeny Vereshchagin f232c83c72 tests: link tests using fabs against libm explicitly
Some compiler wrappers like honggfuzz pass -fno-builtin explicitly
and because of that the tests where fabs is used fail to compile
with something like
```
FAILED: test-bus-marshal
...
/usr/bin/ld: test-bus-marshal.p/src_libsystemd_sd-bus_test-bus-marshal.c.o: undefined reference to symbol 'fabs@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib64/libm.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
```

Fun fact: it took honggfuzz less than a minute to discover
https://github.com/advisories/GHSA-gmc7-pqv9-966m used by
systemd to compress/descompress some stuff.
2022-05-29 19:05:58 +00:00
Zbigniew Jędrzejewski-Szmek 67f8ba714a
Merge pull request #23548 from tpgxyz/lua2
rpm: adjust lua trigger for udevadm
2022-05-29 20:08:05 +02:00
Tomasz Paweł Gajc 744984aa2d rpm: adjust lua trigger for udevadm 2022-05-28 21:38:33 +02:00
Tomasz Paweł Gajc 7bde8293a4 rpm: use rpm.execute() instead of fork() and execp() for trigger scriplets 2022-05-28 21:29:00 +02:00
Jan Janssen c0f5d58c9a meson: Document why -Wimplicit-fallthrough is not used with clang
This changes the macro to ensure proper fallthrough attributes are
used with clang in case this option is added in the future.
2022-05-28 12:44:08 +02:00
Jan Janssen b41ebe3d18 macro: Move attribute defintions to macro-fundamental
This also sorts them.
2022-05-28 11:34:16 +02:00
Yu Watanabe 89b6a3f13e sd-bus: fix buffer overflow
Fixes #23486.
2022-05-28 10:06:14 +02:00
Luca Boccassi 5ad69b04bf
Merge pull request #23518 from enr0n/sd-hwdb-from-path
Implement --root option for systemd-hwdb query
2022-05-27 22:51:36 +01:00
Zbigniew Jędrzejewski-Szmek 94b84a0703 Use descriptive name for nobody
This matches the changes pushed to Fedora [1,2].

[1] https://fedoraproject.org/wiki/Changes/RenameNobodyUser
[2] https://pagure.io/setup/c/f6fdb5ffc87fc8f1acc211867fef4e3f0856edfc
2022-05-27 22:09:24 +01:00
Nick Rosbrook beff73f94e hwdb: implement --root option for systemd-hwdb query
Currently, the systemd-hwdb --root flag only has an effect for the
'update' verb. It would be useful to be able to use the --root option
for the 'query' verb too (e.g. for testing a hwdb.bin created with
systemd-hwdb update --root <path>).

Use sd_hwdb_new_from_path to initialize the hwdb if --root is passed to
systemd-hwdb query.

Note that this functionality was not added to 'udevadm hwdb' since that
command is deprecated.
2022-05-27 09:40:54 -04:00
Nick Rosbrook 60f0ba7556 sd-hwdb: add sd_hwdb_new_from_path
The existing sd_hwdb_new function always initializes the hwdb from the
first successful hwdb.bin it finds from hwdb_bin_paths. This means there
is currently no way to initialize a hwdb from an explicit path, which
would be useful for systemd-hwdb query.

Add sd_hwdb_new_from_path to allow a sd_hwdb to be initialized from a
custom path outside of hwdb_bin_paths.
2022-05-27 09:40:54 -04:00
Nick Rosbrook 9745b51c73 sd-hwdb: include sys/stat.h in hwdb-internal.h
Include this header to fix errors when including hwdb-internal.h:
  ../src/libsystemd/sd-hwdb/hwdb-internal.h:16:21: error: field ‘st’ has incomplete type
     16 |         struct stat st;
2022-05-27 09:40:54 -04:00
Luca Boccassi e1a8917ae1
Merge pull request #23504 from keszybz/bls-reordering
Refactor the BLS and add a description of version sorts
2022-05-27 14:36:10 +01:00
Luca Boccassi df90d255fe
Merge pull request #23527 from keszybz/esp-detect-xbootldr
Fix xbootldr detection, fail early in kernel-install
2022-05-27 11:46:46 +01:00
Yu Watanabe 6d3bb9e7d1
Merge pull request #23517 from mrc0mmand/cryptsetup-switchroot-transition
test: cover initrd->sysroot transition in TEST-24
2022-05-27 07:36:17 +09:00
наб 2f9f8b96d4
kernel-install: don't log each initrd on its own line in verbose mode 2022-05-26 23:18:34 +02:00
наб c60ca42571
kernel-install: actually ignore the last two arguments 2022-05-26 23:16:13 +02:00
Zbigniew Jędrzejewski-Szmek 13d7c841a2 shared/find-esp: enhance logging
If something doesn't match, let's print the non-matching value.
If we can't query something, say what.
And make the messages in the udev and blkid paths different, so
we tell which approach failed from a log.
2022-05-26 21:50:18 +02:00
Zbigniew Jędrzejewski-Szmek 4e12442554 shared/find-esp: fix inverted check for XBOOTLDR type 2022-05-26 21:49:38 +02:00
Zbigniew Jędrzejewski-Szmek 5aa285b437 kernel-install: if a plugin fails, return error immediately
Since the first version in 81516adcb7,
kernel-install would "gather" a return value by summing the exit codes
of the plugins… This makes no sense, because those are not additive values.

Let's just break off immediately. We now implement cleanup via trap, so if we
break, we should leave no garbage behind.
2022-05-26 21:46:58 +02:00
Yu Watanabe 4fc69e8a09 core/device: do not downgrade device state if it is already enumerated
On switching root, a device may have a persistent databse. In that case,
Device.enumerated_found may have DEVICE_FOUND_UDEV flag, and it is not
necessary to downgrade the Device.deserialized_found and
Device.deserialized_state. Otherwise, the state of the device unit may
be changed plugged -> dead -> plugged, if the device has not been mounted.

Fixes #23429.

[mwilck: cherry-picked from #23437]
2022-05-26 17:07:59 +02:00
Martin Wilck cf1ac0cfe4 core/device: device_coldplug(): don't set DEVICE_DEAD
dm-crypt device units generated by systemd-cryptsetup-generator
habe BindsTo= dependencies on their backend devices. The dm-crypt
devices have the db_persist flag set, and thus survive the udev db
cleanup while switching root. But backend devices usually don't survive.
These devices are neither mounted nor used for swap, thus they will
seen as DEVICE_NOT_FOUND after switching root.

The BindsTo dependency will cause systemd to schedule a stop
job for the dm-crypt device, breaking boot:

[   68.929457] krypton systemd[1]: systemd-cryptsetup@cr_root.service: Unit is stopped because bound to inactive unit dev-disk-by\x2duuid-3bf91f73\x2d1ee8\x2d4cfc\x2d9048\x2d93ba349b786d.device.
[   68.945660] krypton systemd[1]: systemd-cryptsetup@cr_root.service: Trying to enqueue job systemd-cryptsetup@cr_root.service/stop/replace
[   69.473459] krypton systemd[1]: systemd-cryptsetup@cr_root.service: Installed new job systemd-cryptsetup@cr_root.service/stop as 343

Avoid this by not setting the state of the backend devices to
DEVICE_DEAD.

Fixes the LUKS setup issue reported in #23429.
2022-05-26 15:06:41 +02:00
Zbigniew Jędrzejewski-Szmek a6e334649d systemctl: make show/status honour --state and --type
This makes the interface more flexible, by allowing the same filtering
for show and status as is done for list-units.

Fixes #23207.
2022-05-26 10:37:35 +09:00
Yu Watanabe c7a0c74c7f
Merge pull request #23513 from keszybz/bootctl-version-print
bootctl: print version comparison when updating
2022-05-26 10:30:16 +09:00
Zbigniew Jędrzejewski-Szmek 892fcb8955 bootctl: when comparing versions, show the result
In Fedora there was a mixup with versions (the version was prefixed with "v", and
"v251" < "250"). This makes this easier to debug.
2022-05-25 16:02:35 +02:00
Zbigniew Jędrzejewski-Szmek f90ee9ff66 basic: add helper function to print </==/> 2022-05-25 16:02:25 +02:00
Zbigniew Jędrzejewski-Szmek c20b2f2421 analyze: use '' instead of the empty string when showing versions
It looks like garbled output… I didn't use shell-escape, because the other
characters that are special for the shell that are used in versions should
not be escaped.
2022-05-25 16:01:14 +02:00
Zbigniew Jędrzejewski-Szmek 2367bdcfc9 docs/BLS: describe version comparisons
Fixes #23346.
2022-05-25 13:47:47 +02:00
Zbigniew Jędrzejewski-Szmek 46083ab321 basic/string-util: tweak strverscmp_improved() for some corner cases
So far we had the rule that '' == '', '0_' == '0', but '_' > ''. This means
that the general rule that strings are compared iteratively, and each
segment that compares equal can be dropped and the comparison resumes at
the following characters wasn't true in such cases. Similarly, '0~' < '0',
but after dropping the common segment, '~' > ''.

The special handling of empty strings is dropped, and '_' == '' and
'~' < ''.
2022-05-25 13:47:47 +02:00
Anita Zhang 7e46a5c093 test-seccomp: check for CAP_IPC_OWNER before calling shmat()
shmat() requires the CAP_IPC_OWNER capability. When running test-seccomp
in environments with root + CAP_SYS_ADMIN, but not CAP_IPC_OWNER,
memory_deny_write_execute_shmat would fail. This fixes it.
2022-05-25 08:03:23 +09:00
Zbigniew Jędrzejewski-Szmek 620ecc9c4b kernel-install: ignore extra args passed when invoked as installkernel
kernel's 'make install' invokes install.sh which calls /sbin/install-kernel.
Thus we are invoked as e.g.
  /sbin/installkernel 5.18.0 arch/x86/boot/bzImage System.map /boot
The last two arguments would be passed as "initrds".

Before , we would just quitely ignore
/boot, because it doesn't pass the 'test -f' test, and possibly try to do
something with System.map. 742561efbe tightened
the check, so we now throw an error.

It seems that the correct thing is to ignore those two arguments, because
our plugin syntax has no notion of System.map. And the installation directory
we can figure out ourselves better. Effectively, this makes things behave
like before, but less by accident.

Fixes #23490.
2022-05-24 23:31:43 +02:00
Zbigniew Jędrzejewski-Szmek 65df0ce39a Minor wording fixes
Some NEWS entries are tweaked a bit to address complaints about readability
from users.

"udev" is pronounced as /ˈjuːdɛv/, like in "user", hence "a" not "an".
2022-05-24 21:26:06 +02:00
Jan Janssen 2d5d72c62b boot: Fix bad CompareMem call 2022-05-24 16:53:36 +01:00
Daan De Meyer 794da5a1a5 portable: Fix memory leak in maybe_enable_disable()
Fixes #23481
2022-05-24 10:55:09 +09:00
Frantisek Sumsal 40bc68cf21
Merge pull request #23475 from nabijaczleweli/certified-lint.1-moment
Actually run shellcheck on CI
2022-05-23 19:16:22 +00:00
Daan De Meyer 75d7e04eb4 dissect-image: Explicitly remove partitions when done with image
When closing a loop device, the kernel will asynchronously remove
the probed partitions. This can lead to race conditions where we
try to reuse a partition device that still needs to be removed by
the kernel. To avoid such issues, let's explicitly try to remove
any partitions using BLKPG_DEL_PARTITION when we're done with an
image.

To make sure we don't try to remove partitions when we want them
to remain (e.g. systemd-dissect --mount), we add
dissected_image_relinquish() in a similar vein to loop_device_relinquish()
and decrypted_image_relinquish().
2022-05-23 18:15:16 +01:00
наб 35339eb88c
shellcheck-clean kernel-install again 2022-05-23 12:52:56 +02:00
Zbigniew Jędrzejewski-Szmek e133c79f9f
Merge pull request #23344 from medhefgo/boot-config-add
boot: Small config entry add changes
2022-05-23 09:26:19 +02:00
Zbigniew Jędrzejewski-Szmek 2f9b7186e3
Merge pull request #23414 from keszybz/analyze-vercmp
systemd-analyze compare-versions
2022-05-23 09:14:51 +02:00
Jan Janssen d17c93a72b test: Test STRLEN for C11 string literals 2022-05-22 20:21:04 +01:00
Daan De Meyer 08e86b15fc coredump: Fix format string type mismatch
Fixes #23471
2022-05-22 19:28:38 +02:00
Jan Janssen 9287b661c5 boot: Rename functions adding entries to match userspace 2022-05-22 12:48:10 +02:00
Jan Janssen 095a153d49 boot: Remove trivial config entry add helpers
These two functions have very limited use and are just fancy wrappers
around structured initializers.
2022-05-22 12:48:06 +02:00
Victor Westerhuis 87c7779599 Do not require a valid version when parsing sd-boot loader entries
This fixes #20820
2022-05-22 12:17:52 +02:00
Luca Boccassi a17ebc687b
Merge pull request #23465 from mrc0mmand/bump-actions-to-ubuntu-2204
ci: bump GH Actions to Ubuntu Jammy where applicable
2022-05-22 02:29:59 +01:00
Luca Boccassi ebd4571e31
Merge pull request #22550 from medhefgo/boot-mixed
boot: EFI mixed mode support
2022-05-21 22:38:56 +01:00
Frantisek Sumsal dfe7cfe4fb cryptsetup: fix build with -Db_ndebug=true
```
 ...
 ../src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-fido2.c:33:13: error: variable 'r' set but not used [-Werror,-Wunused-but-set-variable]
         int r;
             ^
 1 error generated.
 ...
 ../src/cryptsetup/cryptsetup-tokens/cryptsetup-token-systemd-pkcs11.c:34:13: error: variable 'r' set but not used [-Werror,-Wunused-but-set-variable]
         int r;
             ^
 1 error generated.
 ninja: build stopped: subcommand failed.
 + fatal ''\''meson compile'\'' failed with -Db_ndebug=true'
```
2022-05-21 23:27:24 +02:00
Yu Watanabe 7d3f2499b8
Merge pull request #23464 from bnf/update-wiki-links
tree-wide: replace obsolete wiki links with systemd.io/manpages
2022-05-21 23:48:58 +09:00
Jan Janssen 6e9165397f bootctl: Add EFI arch detection support 2022-05-21 15:11:13 +01:00
Jan Janssen c43a282c29 boot: Support booting in EFI mixed mode
The kernel provides a ".compat" PE section that contains a list of
compat entry points with their respective arches. This entry point
does all the heavy lifting to support running 64bit kernels when
the UEFI firmware is 32bit.

Note that the EFI handover protocol code in linux_x86.c does not
need any adjustments as it already correctly calls the 32bit handover
code.

Fixes: #17056
2022-05-21 15:11:13 +01:00
Jan Janssen 46ce6cf774 boot: Add LINUX_INITRD_MEDIA support to boot.c 2022-05-21 15:11:13 +01:00
Jan Janssen acdf7d157b boot: Keep initrds separate from cmdline options
This is in preparation for LINUX_INITRD_MEDIA support in boot.c. One
downside is that adding or changing the used initrds by command line
editing is not possible anymore.
2022-05-21 15:11:13 +01:00
Jan Janssen 5c330b3682 boot: Edit config entry options inline
An edited entry command line should not be saved globally as it
should be tied to that one entry only.
2022-05-21 15:11:13 +01:00
Jan Janssen 7b19627697 fundamental: Move some helpers into string-util-fundamental 2022-05-21 15:11:13 +01:00
Jan Janssen f386daa054 boot: Use cleanup handler to unload image
This also moves the message about failed image execution into
image_start() as we would otherwise show two error messages if
any of the preparatory steps failed.
2022-05-21 15:11:13 +01:00
Yu Watanabe 93a72170bd network: drop support for old kernels which cannot set prefix route with non-main route table
Not sure when the issue was fixed.
- kernel-3.10 on CentOS 7 has the issue,
- kernel-4.18 on CentOS 8 works fine.

Note, the workaround dropped by the commit is not incomplete:
with an old kernel which has the issue, all non-prefix routes are
configured on the specified route table, but the prefix route is
configured on the main table. That should not work for most cases,
hence, the workaround is mostly meaningless.
2022-05-21 15:09:53 +01:00
Luca Boccassi 0168b91603
Merge pull request #23339 from poettering/sockaddr-size-limit
tree-wide: add support for connecting to AF_UNIX sockets in the file system beyond the 108ch limit
2022-05-21 15:09:04 +01:00
Luca Boccassi 051c4e5419
Merge pull request #23342 from poettering/efi-monotonic-counter-random-seed
sd-boot: include GetNextMonotonicCount() in random seed calculations
2022-05-21 15:08:21 +01:00
Jan Janssen 7d4953de13 boot: Build with -flto=auto if available
Without this, we may get the following warning with gcc-12:
    lto-wrapper: warning: using serial compilation of 2 LTRANS jobs
2022-05-21 15:07:47 +01:00
Jan Janssen 351b30dae0 macro: Use C11 noreturn only
No need to provide a fallback as we compile with gnu11.
2022-05-21 15:01:47 +01:00
Yu Watanabe 1246d09705 networkctl: show error message provided through dbus
Prompted by #23416.
2022-05-21 15:01:09 +01:00
Luca Boccassi 6910d43af5
Merge pull request #23453 from keszybz/strv-parsing
Add strv methods with externally-supplied size argument and speed up parsing of /etc/hosts
2022-05-21 15:00:51 +01:00