1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 02:21:44 +03:00
Commit Graph

50522 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
af46237ea1 man: split the description of sd_bus_error_set()
It was one giant all of text in pseudo-random order. Let's split it into
paragraphs talk about one subject each.

And unfortunately, the description of what happens when the error is not
set was not correct. In general, various functions treat 0/NULL as
not-an-error, and return 0.
2021-03-31 18:24:53 +02:00
Zbigniew Jędrzejewski-Szmek
b9c19bc384 sd-bus: add asserts showing that sd_bus_error_setf() returns negative
(when name is specified).
2021-03-31 18:24:44 +02:00
Zbigniew Jędrzejewski-Szmek
c7e964c944 sd-bus: add assert to tell the compiler that the error code is positive
I was hoping it would help with the following gcc warning:
[35/657] Compiling C object src/shared/libsystemd-shared-248.a.p/bus-message-util.c.o
../src/shared/bus-message-util.c: In function ‘bus_message_read_dns_servers’:
../src/shared/bus-message-util.c:165:21: warning: ‘family’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  165 |                 r = in_addr_full_new(family, &a, port, 0, server_name, dns + n);
      |                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/shared/bus-message-util.c:165:21: warning: ‘port’ may be used uninitialized in this function [-Wmaybe-uninitialized]
../src/shared/bus-message-util.c:165:21: warning: ‘server_name’ may be used uninitialized in this function [-Wmaybe-uninitialized]

It actually doesn't, but the compiler has a point here: the code is specified
in sd_bus_error_map[], and it has no way of knowning that we want it to be a
positive value.

I think this should be an assert, because if this assumption fails, a
programming error has occured, something that'd want to catch.
2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
55e2cfc938 basic/fileio: silence gcc's maybe-unitialized warning
[11/657] Compiling C object src/basic/libbasic.a.p/fileio.c.o
../src/basic/fileio.c: In function ‘write_string_stream_ts’:
../src/basic/fileio.c:167:21: warning: ‘fd’ may be used uninitialized in this function [-Wmaybe-uninitialized]
  167 |                 if (futimens(fd, twice) < 0)
      |                     ^~~~~~~~~~~~~~~~~~~
2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
befab2c40c basic/socket-util: add hint to silence gcc's maybe-unitialized warning
[59/1551] Compiling C object src/basic/libbasic.a.p/socket-util.c.o
../src/basic/socket-util.c: In function ‘socket_get_mtu’:
../src/basic/socket-util.c:1393:16: warning: ‘mtu’ may be used uninitialized in this function [-Wmaybe-uninitialized]
 1393 |         *ret = (size_t) mtu;
      |                ^~~~~~~~~~~~
2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
adf6d848df resolved: drop unnecessary {} 2021-03-31 18:22:53 +02:00
Zbigniew Jędrzejewski-Szmek
75d2f0a0c4 nss-resolve: define variables in the body
Same motivation as in the parent commit: let's define variables later, ideally
right when they are first initialized, so it's easier to figure out that they
are properly initialized.

error_id and r_tuple* were previously initialized, but I don't see why they
would need to be.

No functional change intended.
2021-03-31 17:19:03 +02:00
Zbigniew Jędrzejewski-Szmek
77fac974fe nss-resolve: fix parsing of io.systemd.Resolve.ResolveAddress reply
Since the switch to varlink in 0c73f4f075, the
code wasn't functional. The JSON_VARIANT_UNSIGNED/JSON_VARIANT_STRING mismatch
meant that we'd reject any reply. Once past that, the code would use
unitialized 'c' and 'n' variables, so it's lucky we never got that far ;)

With -Wmaybe-unitialized, gcc would warn.

I think that declaring the huge list of local variables with very short names
at the top of the function was making it harder to understand what is going on
in the function. So let's rename the variables a bit, and initialize them upon
declaration if possible.

$ build/test-nss-hosts resolve 1.1.1.1 1.0.0.1 10.38.5.41
======== resolve ========
_nss_resolve_gethostbyaddr2_r("1.1.1.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error) ttl=0
        "one.one.one.one"
        AF_INET 1.1.1.1

_nss_resolve_gethostbyaddr_r("1.1.1.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error)
        "one.one.one.one"
        AF_INET 1.1.1.1

_nss_resolve_gethostbyaddr2_r("1.0.0.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error) ttl=0
        "one.one.one.one"
        AF_INET 1.0.0.1

_nss_resolve_gethostbyaddr_r("1.0.0.1") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error)
        "one.one.one.one"
        AF_INET 1.0.0.1

_nss_resolve_gethostbyaddr2_r("10.38.5.41") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error) ttl=0
        "squid.redhat.com"
        alias "squid.corp.redhat.com"
        alias "squid2.corp.redhat.com"
        alias "squid3.corp.redhat.com"
        alias "squid4.corp.redhat.com"
        alias "squid5.corp.redhat.com"
        AF_INET 10.38.5.41

_nss_resolve_gethostbyaddr_r("10.38.5.41") → status=NSS_STATUS_SUCCESS
                   errno=999/--- h_errno=0/Resolver Error 0 (no error)
        "squid.redhat.com"
        alias "squid.corp.redhat.com"
        alias "squid2.corp.redhat.com"
        alias "squid3.corp.redhat.com"
        alias "squid4.corp.redhat.com"
        alias "squid5.corp.redhat.com"
        AF_INET 10.38.5.41

(I have 10.38.5.41 squid.redhat.com squid.corp.redhat.com squid2.corp.redhat.com squid3.corp.redhat.com squid4.corp.redhat.com squid5.corp.redhat.com
in /etc/hosts for testing.)
2021-03-31 16:28:14 +02:00
Luca Boccassi
907952bbc9 portabled: add --extension parameter for layered images support
Add an --extension parameter to portablectl, and new DBUS methods
to attach/detach/reattach/inspect.
Allows to append separate images on top of the root directory (os-release
will be searched in there) and mount the images using an overlay-like
setup (unit files will be searched in there) using the new ExtensionImages
service option.
2021-03-31 09:56:44 +01:00
Luca Boccassi
248b1e0aa4 gcrypt: do not ignore return values
Check the return code from gcrypt's functions. In some
cases just log, as it shoulnd't really happen.

Fixes various Coverity issues:

CID #1444702
CID #1444704
CID #1444706
CID #1444711
CID #1444712
CID #1444713
2021-03-31 10:51:35 +02:00
Zbigniew Jędrzejewski-Szmek
a59eb7d78f rpm: when disabling a unit, do not complain if systemd is not running
$ sudo dnf remove --installroot=/var/tmp/img1 systemd-networkd
...
  Running scriptlet: systemd-networkd-248~rc4-4.fc32.x86_64      1/1
Removed /etc/systemd/system/multi-user.target.wants/systemd-networkd.service.
Removed /etc/systemd/system/sockets.target.wants/systemd-networkd.socket.
Removed /etc/systemd/system/dbus-org.freedesktop.network1.service.
Removed /etc/systemd/system/network-online.target.wants/systemd-networkd-wait-online.service.
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

(Another option would be make --now do nothing if systemd is not running.
But I think that's not too good. 'disable --now' doing nothing would be OK,
since if systemd is not running, the service is not running either, so we are
in the desired state. But that argument doesn't work for 'enable --now'. And
accepting 'disable --now' but not 'enable --now' seems overly complex. So I
think it is better to make the scriptlet handle this case explicitly.)

Also, let's reindent the file to 4 spaces. Very deeply nested scriptlets are
harder to read, and the triggers file is indented to 4 spaces already.
2021-03-31 10:50:07 +02:00
Jan Janssen
a83ddc08d6 resolved.conf: Add hostnames for default DNS servers 2021-03-31 10:49:36 +02:00
Deepak Rawat
0d96caa5c0 logind: Add new flag for kexec reboot
Add new flag to allow kexec reboot if kernel is already loaded.
2021-03-31 10:48:48 +02:00
Zbigniew Jędrzejewski-Szmek
a93af34a40
Merge pull request #19109 from poettering/resolved-transaction-log-tweaks
resolved: minor tweaks to transaction logic and logging
2021-03-31 10:47:12 +02:00
Lennart Poettering
9a515f0a55 shared: add new IMAGE_VERSION=/IMAGE_ID= field to /etc/os-release
This specifes two new optional fields for /etc/os-release:
IMAGE_VERSION= and IMAGE_ID= that are supposed to identify the image of
the current booted system by name and version.

This is inspired by the versioning stuff in
https://github.com/systemd/mkosi/pull/683.

In environments where pre-built images are installed and updated as a
whole the existing os-release version/distro identifier are not
sufficient to describe the system's version, as they describe only the
distro an image is built from, but not the image itself, even if that
image is deployed many times on many systems, and even if that image
contains more resources than just the RPMs/DEBs.

In particular, "mkosi" is a tool for building disk images based on
distro RPMs with additional resources dropped in. The combination of all
of these together with their versions should also carry an identifier
and version, and that's what IMAGE_VERSION= and IMAGE_ID= is supposed to
be.
2021-03-31 10:46:22 +02:00
Zbigniew Jędrzejewski-Szmek
e872679629
Merge pull request #19064 from yuwata/resolve-fix-cache-19049
resolve: several trivial cleanups
2021-03-31 10:42:21 +02:00
gaoyi
f257a8fc13 udevd: don't kill worker in manager_kill_workers when it's running
If worker is running, kill worker may lead uevent unprocessed.
2021-03-31 10:41:44 +02:00
Zbigniew Jędrzejewski-Szmek
a2dc3adef2
Merge pull request #18990 from yuwata/network-dhcpv6-use-domains
network: also introduce UseDomains= for [DHCPv6] section
2021-03-31 10:38:37 +02:00
Lennart Poettering
16ede1d75a
Merge pull request #19101 from poettering/mount-util-fixes
Make recursive bind remounting handle failures gracefully
2021-03-31 10:37:49 +02:00
Lennart Poettering
27ec815eb4 dissect: make the --image= switch of our various tools honour Verity data
This adds simple Verity support to
mount_image_privately_interactively(): we dicover the verity metadata
and use it.
2021-03-31 10:36:14 +02:00
Zbigniew Jędrzejewski-Szmek
224e6c844d
Merge pull request #18989 from yuwata/ordered-set-put-strdup
ordered-set: make ordered_set_put_strdup() allocate OrderedSet object
2021-03-31 10:36:03 +02:00
Lennart Poettering
6020d00d7e repart: make sure CopyFiles= works with a / suffixed path
If we define a partition with CopyFiles=/efi/ this should just work.
However it previously didn't because basename() would return the
trailing slash.

Let's fix this by moving things to path_extract_{directory|filename}()
2021-03-31 10:35:45 +02:00
Lennart Poettering
e0b4bc239f machine-id-setup: support --image= mode 2021-03-31 10:35:31 +02:00
Lennart Poettering
f9d8325e69
Merge pull request #18971 from poettering/sysusers-creds
let's read LoadCredentials=/SetCredentials= style cred in sysusers/firstboot and when asking for passwords
2021-03-31 10:35:17 +02:00
Zbigniew Jędrzejewski-Szmek
4c31bfdf55
Merge pull request #18982 from keszybz/test-nss-users
Add a new test for user/group resolution in nss modules
2021-03-31 10:32:09 +02:00
Zbigniew Jędrzejewski-Szmek
b880ac2c15
Merge pull request #18958 from poettering/dissect-no-root
dissect-image: support images without rootfs but with /usr partition + support simple partition versioning via strverscmp() on part label
2021-03-31 10:31:32 +02:00
Luca Boccassi
834bab01f9 compress: support streaming lz4 without full input mmap
The advantage of stream compression is keeping a low memory profile,
but the lz4 stream compressor usage mmaps the whole file in memory.

Change it to read bits by bits, like the other stream compression
helpers.
2021-03-31 10:29:36 +02:00
Zbigniew Jędrzejewski-Szmek
bcceabcfc2
Merge pull request #18886 from anitazha/shutdownconsole
logging shutdown to /dev/console
2021-03-31 10:28:26 +02:00
Zbigniew Jędrzejewski-Szmek
87f9300d71
Merge pull request #18850 from yuwata/sd-device-monitor-cleanups
sd-device-monitor: trivial cleanups
2021-03-31 10:27:06 +02:00
Henri Chain
cb0e818f7c Introduce ExitType 2021-03-31 10:26:07 +02:00
Zbigniew Jędrzejewski-Szmek
82a335db83
Merge pull request #18777 from yuwata/network-set-ifname-to-engines
network: set ifname to dhcp4 client or friends
2021-03-31 10:25:23 +02:00
Lennart Poettering
938bdfc0fa
Merge pull request #19157 from keszybz/read-medium-sized-virtual-file
basic/fileio: fix reading of not-too-small virtual files
2021-03-30 22:59:02 +02:00
Lennart Poettering
9ca34cf5a4 NEWS: prep release date 2021-03-30 22:00:11 +02:00
Zbigniew Jędrzejewski-Szmek
bca895c4f4 test-fileio: test for read_full_virtual_file()
It was already called through other places, but indirectly.
Let's add some direct invocations.
2021-03-30 21:58:59 +02:00
Zbigniew Jędrzejewski-Szmek
2ac67221bb basic/fileio: fix reading of not-too-small virtual files
This code is trying to do two things: when reading a file with working
st.st_size, detect when the file size changes between the fstat() and our
allocation of the buffer based on the returned size, and the subsequent read().
When reading a file without st.st_size, read up to READ_FULL_BYTES_MAX.

But this second scenario was partially broken: we'd start with size = 4095, and
double the size up to three times, i.e. up to 32767. But we want to read up to
READ_FULL_BYTES_MAX.

So let's listentangle the two cases a bit: if a file returns non-zero st._size,
proceed as before. But if we don't know the size, let's immediately allocate
the buffer of maximum size of READ_FULL_BYTES_MAX. I think that allocating 4MB
and 1MB is going to take pretty much the same time as long as the memory is not
written to, so by allocating 1MB, 2MB, and 4MB, we wouldn't really be saving
anything internally, but wasting time on repeated reads, if the file is long
enough.

Also, don't do the seek if we know we're going to return an error immediately
after.

This should fix reading of any files in /proc, which all have size == 0. In
particular, various files read by coredump might be larger than 32767.

What about /sys? The file there return a fake value, usually 4096. So we'll
allocate a small buffer and read that.
2021-03-30 21:56:22 +02:00
Luca Boccassi
ae63987fac
Merge pull request #19149 from anitazha/oomdlogging
oomd: make it more clear when a kill happens
2021-03-30 19:01:01 +01:00
Luca Boccassi
c71bb61e8d
Merge pull request #19155 from keszybz/hwdb-contrib-v248
hwdb update + contrib list
2021-03-30 18:13:16 +01:00
Zbigniew Jędrzejewski-Szmek
f94a80ab59 oomd: fix iteration over candidates to kill 2021-03-30 14:45:22 +02:00
Anita Zhang
37a7e15968 oomd: make it more clear when a kill happens
Improve the logging to only print if systemd-oomd killed something. And
also print which cgroup was targeted.
Demote general swap above/pressure above messages to debug.

[zjs: fix some issuelets found in review]
2021-03-30 14:44:09 +02:00
Lennart Poettering
414f59dad7
Merge pull request #19131 from keszybz/resolvectl-warn-less
Suppress warnings in resolvectl about --type=
2021-03-30 13:29:55 +02:00
Zbigniew Jędrzejewski-Szmek
7960ba96d1 selinux: do not crash if policy becomes unavailable after reload
https://bugzilla.redhat.com/show_bug.cgi?id=1944171
This was in F33, systemd-246.13, but the logic in the code didn't change.

Thread 1 (Thread 0x7fb5f0341b80 (LWP 1974)):
№0  selabel_lookup_common (rec=0x0, translating=0, key=0x55f616ac4750 "/run/user/1000/systemd/units/invocation:systemd-tmpfiles-clean.service", type=40960) at label.c:167

'rec' is the handle that we passed.

№1  0x00007fb5f13ae87f in selabel_lookup_raw (rec=<optimized out>, con=con@entry=0x7fffef307380, key=key@entry=0x55f616ac4750 "/run/user/1000/systemd/units/invocation:systemd-tmpfiles-clean.service", type=type@entry=40960) at label.c:256
        lr = <optimized out>

'rec' is passed through as is to selabel_lookup_common().

№2  0x00007fb5f1561b2d in selinux_create_file_prepare_abspath (abspath=0x55f616ac4750 "/run/user/1000/systemd/units/invocation:systemd-tmpfiles-clean.service", mode=40960) at ../src/basic/selinux-util.c:368
        filecon = 0x0
        r = <optimized out>
        __PRETTY_FUNCTION__ = "selinux_create_file_prepare_abspath"
        __func__ = "selinux_create_file_prepare_abspath"

№3  0x00007fb5f1561ec3 in mac_selinux_create_file_prepare (path=<optimized out>, mode=40960) at ../src/basic/selinux-util.c:431
        r = 0
        abspath = 0x55f616ac4750 "/run/user/1000/systemd/units/invocation:systemd-tmpfiles-clean.service"
        __PRETTY_FUNCTION__ = "mac_selinux_create_file_prepare"

We checked label_hnd != NULL, but then we apparently called
avc_netlink_check_nb(), which reset label_hnd. Yay for global state!

№4  0x00007fb5f1549950 in symlink_atomic_label (from=0x55f6169d8b50 "69a8dcf7a7ac46b29306f2fddbed3edc", to=0x55f616ab8380 "/run/user/1000/systemd/units/invocation:systemd-tmpfiles-clean.service") at ../src/basic/label.c:55
        r = <optimized out>
        __PRETTY_FUNCTION__ = "symlink_atomic_label"

In the logs:

Mar 29 14:48:44 fedorapad.home systemd[1974]: selinux: avc:  received policyload notice (seqno=2)
Mar 29 14:48:44 fedorapad.home systemd[1974]: Failed to initialize SELinux labeling handle: No such file or directory
Mar 29 14:48:44 fedorapad.home systemd[1974]: selinux: avc:  received policyload notice (seqno=3)
Mar 29 14:48:44 fedorapad.home systemd[1974]: selinux: avc:  received setenforce notice (enforcing=0)
2021-03-30 13:24:12 +02:00
Zbigniew Jędrzejewski-Szmek
f8a6e1e523 hwdb: update fingerprint autosuspend rules 2021-03-30 13:17:59 +02:00
Zbigniew Jędrzejewski-Szmek
a22c7690d4 hwdb: update for v248
As usual, it seems to be additions and updates, no major removals.
2021-03-30 13:17:59 +02:00
Zbigniew Jędrzejewski-Szmek
8ce2255178 NEWS: update contributor list for v248 final 2021-03-30 13:17:59 +02:00
Zbigniew Jędrzejewski-Szmek
b242d2dec9 git-contrib: use non-breaking spaces in names
Some people have initials or abbreviated parts in the name and looks strange
when a line break occurs in the middle. Let's keep each name in one line.
2021-03-30 13:17:59 +02:00
Zbigniew Jędrzejewski-Szmek
75e53df7e3 mailmap: two more names 2021-03-30 13:17:58 +02:00
Luca Boccassi
063a43a1a7 Revert "fix wrong statement JOURNAL_FILE_FORMAT.md doc"
This reverts commit 119063d2b1.
2021-03-30 10:26:54 +02:00
Yangyang Shen
119063d2b1 fix wrong statement JOURNAL_FILE_FORMAT.md doc 2021-03-29 19:11:27 +02:00
Christian Hesse
46cfe8f50d units: make locale directory writable for systemd-localed
With 8f20232fcb systemd-localed supports
generating locales when required. This fails if the locale directory is
read-only, so make it writable.

Closes #19138
2021-03-29 12:33:36 +02:00
Fangrui Song
945317a4b6 sd-bus: set retain attribute on BUS_ERROR_MAP_ELF_REGISTER
LLD 13 and GNU ld 2.37 support -z start-stop-gc which allows garbage
collection of C identifier name sections despite the __start_/__stop_
references.  Simply set the retain attribute so that GCC 11 (if
configure-time binutils is 2.36 or newer)/Clang 13 will set the
SHF_GNU_RETAIN section attribute to prevent garbage collection.

Without the patch, there are linker errors like the following with -z
start-stop-gc.

```
ld: error: undefined symbol: __start_SYSTEMD_BUS_ERROR_MAP
>>> referenced by bus-error.c:93 (../src/libsystemd/sd-bus/bus-error.c:93)
>>>               sd-bus_bus-error.c.o:(bus_error_name_to_errno) in archive src/libsystemd/libsystemd_static.a
```
2021-03-29 12:31:42 +02:00