systemd/.git
3 years agosd-dhcp6-client: constify several arguments
Yu Watanabe [Fri, 24 Sep 2021 04:34:14 +0000 (13:34 +0900)]
sd-dhcp6-client: constify several arguments

(cherry picked from commit 3f8227bf830cc2b87ea9bce5394a71c186d12956)

3 years agosd-dhcp6-client: fix buffer size calculation in dhcp6_option_parse_ip6addrs()
Yu Watanabe [Thu, 23 Sep 2021 16:24:52 +0000 (01:24 +0900)]
sd-dhcp6-client: fix buffer size calculation in dhcp6_option_parse_ip6addrs()

GREEDY_REALLOC() takes number of elements, not buffer size.

This also rename dhcp6_option_parse_ip6addrs() to
dhcp6_option_parse_addresses().

(cherry picked from commit ad3c84204c76e03a0b9b761563f6cd8907515014)

3 years agotest: add tests for reading unaligned data
Yu Watanabe [Mon, 27 Sep 2021 15:48:59 +0000 (00:48 +0900)]
test: add tests for reading unaligned data

(cherry picked from commit e620104956dff64244c0e73e86c3138c0b13b875)

3 years agosd-dhcp6-client: modernize dhcp6_option_parse()
Yu Watanabe [Thu, 23 Sep 2021 05:58:28 +0000 (14:58 +0900)]
sd-dhcp6-client: modernize dhcp6_option_parse()

- merge dhcp6_option_parse() with option_parse_hdr().
- do not assign/update any values on error.
- use assert() instead of assert_return(), as the assertions cannot
  be triggered by a library user.

(cherry picked from commit b89a3758e92894162e3c2dcb594a55acff3274d5)

3 years agosd-dhcp6-client: constify one argument
Yu Watanabe [Thu, 23 Sep 2021 05:57:29 +0000 (14:57 +0900)]
sd-dhcp6-client: constify one argument

(cherry picked from commit dc95e21d33708e807d3e5872af428383aac3f9b7)

3 years agotests: add test case for UMask=+BindPaths= combination
Lennart Poettering [Fri, 12 Nov 2021 12:41:59 +0000 (13:41 +0100)]
tests: add test case for UMask=+BindPaths= combination

Inspired by the test case described in #19899

(cherry picked from commit 875afa02fabe1dad5aa3d1e9bff89d493a369fd0)

3 years agonamespace: make tmp dir handling code independent of umask too
Lennart Poettering [Fri, 12 Nov 2021 10:16:02 +0000 (11:16 +0100)]
namespace: make tmp dir handling code independent of umask too

Let's make all code in namespace.c robust towards weird umask. This
doesn't matter too much given that the parent dirs we deal here almost
certainly exist anyway, but let's clean this up anyway and make it fully
clean.

(cherry picked from commit 30443439274cc223583c6c57f7d9041e440e346f)

3 years agonamespace: make whole namespace_setup() work regardless of configured umask
Lennart Poettering [Fri, 12 Nov 2021 10:11:27 +0000 (11:11 +0100)]
namespace: make whole namespace_setup() work regardless of configured umask

Let's reset the umask during the whole namespace_setup() logic, so that
all our mkdir() + mknod() are not subjected to whatever umask might
currently be set.

This mostly moves the umask save/restore logic out of
mount_private_dev() and into the stack frame of namespace_setup() that
is further out.

Fixes #19899

(cherry picked from commit cdf42f9bd40ff21a67d58b948efea055d56ad398)

3 years agonamespace: rebreak a few comments
Lennart Poettering [Fri, 12 Nov 2021 10:09:40 +0000 (11:09 +0100)]
namespace: rebreak a few comments

(cherry picked from commit d73020f2420aa3f220481016829aaa2602abf081)

3 years agoumask-util: add helper that resets umask until end of current code block
Lennart Poettering [Fri, 12 Nov 2021 10:06:46 +0000 (11:06 +0100)]
umask-util: add helper that resets umask until end of current code block

(cherry picked from commit 52f05ef21d7790f37bc3cd6e54fb9a4bcb16efa5)

4 years agounit_is_bound_by_inactive: fix return pointer check
Dominique Martinet [Wed, 24 Nov 2021 13:27:22 +0000 (22:27 +0900)]
unit_is_bound_by_inactive: fix return pointer check

*ret_culprit should be set if ret_culprit has been passed a non-null value,
checking the previous *ret_culprit value does not make sense.

This would cause the culprit to not properly be assigned, leading to
pid1 crash when a unit could not be stopped.

Fixes: #21476

(cherry picked from commit 3da361064bf550d1818c7cd800a514326058e5f2)

4 years agobinfmt: fix exit value v249.7
Zbigniew Jędrzejewski-Szmek [Wed, 10 Nov 2021 12:58:32 +0000 (13:58 +0100)]
binfmt: fix exit value

Positive values are mapped to 0 by DEFINE_MAIN_FUNCTION(), so e.g.
systemd-binfmt --foobar would "succeed".

(cherry picked from commit 52707598d5c0dbbc8a967e4874b0b08ee2486772)

4 years agoChange gendered terms to be gender-neutral (#21325)
Emily Gonyer [Fri, 12 Nov 2021 15:09:56 +0000 (10:09 -0500)]
Change gendered terms to be gender-neutral (#21325)

Some typos are also fixed.

(cherry picked from commit be7148ebed5d73c4a76bc6089ebe2e82d8fa33e0)

4 years agoman: add missing Firmware= setting
Yu Watanabe [Wed, 10 Nov 2021 01:56:42 +0000 (10:56 +0900)]
man: add missing Firmware= setting

(cherry picked from commit 33132db90318094268adcf48e5e37abab1c707f1)

4 years agodocs: Clarify systemctl show manual
Paulo Neves [Tue, 9 Nov 2021 14:06:01 +0000 (15:06 +0100)]
docs: Clarify systemctl show manual

The manual incorrectly asserted that the properties in systemctl show
matched the the options in systemd-system.conf, which is not always true.

Add clarification on the equivalence of the properties in systemctl show
and systemd-system.conf

Fixed #21230

(cherry picked from commit c809e38732afcb3efc429fc5086f9c48e45ae635)

4 years agosd-event: don't destroy inotify data structures from inotify event handler
Lennart Poettering [Mon, 8 Nov 2021 23:11:38 +0000 (00:11 +0100)]
sd-event: don't destroy inotify data structures from inotify event handler

This fixes a bad memory access when we destroy an inotify source handler
from the handler itself, and thus destroy the associated inotify_data
structures.

Fixes: #20177
(cherry picked from commit 53baf2efa420cab6c4b1904c9a0c46a0c4ec80a1)

4 years agotree-wide: use sd_event_source_disable_unref() where we can
Lennart Poettering [Mon, 8 Nov 2021 22:07:51 +0000 (23:07 +0100)]
tree-wide: use sd_event_source_disable_unref() where we can

(cherry picked from commit 4f538d7b221de5707c1ff422e6e34be795535397)

4 years agologind: downgrade message about /run/utmp missing to LOG_DEBUG
Lennart Poettering [Mon, 8 Nov 2021 22:08:13 +0000 (23:08 +0100)]
logind: downgrade message about /run/utmp missing to LOG_DEBUG

This isn't really anything to really complain about, let's debug log
about this, and continue quietly as if utmp was empty.

(cherry picked from commit 9830d716147c4e35026457027af95f303e690ae9)

4 years agouser-record: fix display of access mode
Lennart Poettering [Fri, 5 Nov 2021 15:36:32 +0000 (16:36 +0100)]
user-record: fix display of access mode

(cherry picked from commit 7cdd5c0d4c2213b791d8d22e7dd466a39e9c5db0)

4 years agobasic/mountpoint-util: detect erofs as a read-only FS
Luca Boccassi [Thu, 4 Nov 2021 20:29:43 +0000 (20:29 +0000)]
basic/mountpoint-util: detect erofs as a read-only FS

(cherry picked from commit fac2c3e97d80fb356eb50abb429bdb5ed36afcf1)

4 years agoci: pin the debian systemd repo to a specific revision
Frantisek Sumsal [Sun, 14 Nov 2021 11:28:21 +0000 (12:28 +0100)]
ci: pin the debian systemd repo to a specific revision

to work around missing systemd/systemd#20056 in pre-v250 stable
branches.

v249-stable-only

4 years agotest-oomd-util: skip tests if cgroup memory controller is not available
Yu Watanabe [Sat, 11 Sep 2021 11:37:50 +0000 (20:37 +0900)]
test-oomd-util: skip tests if cgroup memory controller is not available

Fixes #20593 and #20655.

(cherry picked from commit 8b2e22579a6549ab8423858819703fc142862bcb)

4 years agoci: run the unit_tests and mkosi jobs on stable branches as well
Frantisek Sumsal [Fri, 12 Nov 2021 16:37:15 +0000 (17:37 +0100)]
ci: run the unit_tests and mkosi jobs on stable branches as well

To provide more coverage for the systemd-stable repo.

See: https://github.com/systemd/systemd-stable/issues/24
(cherry picked from commit c76a83858996148fea36d1018b4707ce5334363b)

4 years agoci: take CIFuzz's matrix into consideration
Frantisek Sumsal [Wed, 10 Nov 2021 19:15:41 +0000 (20:15 +0100)]
ci: take CIFuzz's matrix into consideration

Otherwise the jobs will try to cancel each other out.

Follow-up to 3884837610168e6fb69fc2d5709f6c017a30beb9.

(cherry picked from commit 8b212f3596d03f8e1025cd151d17f9a82433844a)

4 years agoci: cancel previous jobs on ref update
Frantisek Sumsal [Wed, 10 Nov 2021 15:45:12 +0000 (16:45 +0100)]
ci: cancel previous jobs on ref update

Let's save the environment (and reduce the number of jobs in GH Actions
queues) by cancelling old jobs on a ref update (force push).

See: https://docs.github.com/en/actions/learn-github-actions/workflow-syntax-for-github-actions#concurrency
(cherry picked from commit 3884837610168e6fb69fc2d5709f6c017a30beb9)

4 years agoci: fix indentation
Frantisek Sumsal [Wed, 10 Nov 2021 15:42:07 +0000 (16:42 +0100)]
ci: fix indentation

(cherry picked from commit 46573ee1319ee8ae5b292a0a737740eca1a68184)

4 years agoMerge pull request #142 from ojab/cherry-pick-21298
Luca Boccassi [Thu, 11 Nov 2021 23:50:06 +0000 (23:50 +0000)]
Merge pull request #142 from ojab/cherry-pick-21298

Fix rawhide build & `systemd-run --user --scope`

4 years agotest: use kbd-mode-map we ship in one more test case
Yu Watanabe [Wed, 10 Nov 2021 23:55:10 +0000 (08:55 +0900)]
test: use kbd-mode-map we ship in one more test case

Follow-up for be0cc2ce6c947aafadb3f42dba405269f670b31c.

Fixes https://github.com/systemd/systemd/pull/19670#issuecomment-965817823.

(cherry picked from commit a914901d38e01b90e21883b6a2ca1bec21997201)

4 years agoopenssl-util: use EVP API to get RSA bits
Lennart Poettering [Wed, 29 Sep 2021 13:03:44 +0000 (15:03 +0200)]
openssl-util: use EVP API to get RSA bits

(cherry picked from commit 7f12adc3000c08a370f74bd16c654506c8a99e92)

4 years agocreds-util: switch to OpenSSL 3.0 APIs
Lennart Poettering [Wed, 29 Sep 2021 07:47:08 +0000 (09:47 +0200)]
creds-util: switch to OpenSSL 3.0 APIs

Let's switch from the low-level SHA256 APIs to EVP APIs. The former are
deprecated on OpenSSL 3.0, the latter are supported both by old
OpenSSL and by OpenSSL 3.0, hence are the better choice.

Fixes: #20775
(cherry picked from commit 18f568b8e64b48f6aee204cc6384b4796cd27eb0)

4 years agoscope: count successful cgroup additions when delegating via D-Bus
Jonas Witschel [Wed, 10 Nov 2021 21:46:35 +0000 (22:46 +0100)]
scope: count successful cgroup additions when delegating via D-Bus

Since commit 8d3e4ac7cd37200d1431411a4b98925a24b7d9b3 ("scope: refuse
activation of scopes if no PIDs to add are left") all "systemd-run --scope
--user" calls fail because cgroup attachments delegated to the system instance
are not counted towards successful additions. Fix this by incrementing the
return value in case unit_attach_pid_to_cgroup_via_bus() succeeds, similar to
what happens when cg_attach() succeeds directly.

Note that this can *not* distinguish the case when
unit_attach_pid_to_cgroup_via_bus() has been run successfully, but all
processes to attach are gone in the meantime, unlike the checks that commit
8d3e4ac7cd37200d1431411a4b98925a24b7d9b3 adds for the system instance. This is
because even though unit_attach_pid_to_cgroup_via_bus() leads to an internal
unit_attach_pids_to_cgroup() call, the return value over D-Bus does not include
the number of successfully attached processes and is always NULL on success.

Fixes: #21297

(cherry picked from commit c65417a01121301fdf7f8514ee7663d287af3a72)

4 years agoprocess-util: wait for processes we killed even if killing failed v249.6
Lennart Poettering [Wed, 3 Nov 2021 14:54:28 +0000 (15:54 +0100)]
process-util: wait for processes we killed even if killing failed

The processes might be zombies in which case killing will fail, but
reaping them still matters.

(cherry picked from commit 2c1612100daae9cef1b71c06ae4c4ec5f9378f09)

4 years agotest-keymap-util: always use kbd-model-map we ship
Franck Bui [Wed, 19 May 2021 12:14:58 +0000 (14:14 +0200)]
test-keymap-util: always use kbd-model-map we ship

This test makes assumptions on the availability of some mappings contained in
kbd-model-map and therefore strongly relies on the version shipped by
upstream. IOW the test is likely to fail if it's installed on a system with a
more comprehensive kbd-model-map.

This patch makes the upstream kbd-model-map file available via a symlink in
test/testdata/test-keymap-util dir and makes sure that this specific version is
always used by test-keymap-util regardless of whether the test is installed and
run on a different system or directly run (optionally via meson) from the
project working dir.

(cherry picked from commit be0cc2ce6c947aafadb3f42dba405269f670b31c)

4 years agoman: document cryptenroll limitations
Lennart Poettering [Tue, 2 Nov 2021 12:37:27 +0000 (13:37 +0100)]
man: document cryptenroll limitations

Let's document this for now. We should be able to lift these limitations
sooner or later, at which point we can drop this documentation again.

These two limitations are a pitfall that people should be aware of,
before going FIDO2-only.

See: #20230 #19208
(cherry picked from commit 0bada3f8b72e07bc8926b28957681abb5622039a)

4 years agocore: ignore failure on setting smack process label when allowed
Yu Watanabe [Mon, 1 Nov 2021 04:48:32 +0000 (13:48 +0900)]
core: ignore failure on setting smack process label when allowed

(cherry picked from commit 29ff62473b119c0e1d3467148eddcdccc2c9b732)

4 years agoexecute: respect selinux_context_ignore
Topi Miettinen [Sat, 30 Oct 2021 16:58:41 +0000 (19:58 +0300)]
execute: respect selinux_context_ignore

When `SELinuxContext=` parameter is prefixed with `-`, the documentation states
that any errors determining or changing context should be ignored, but this
doesn't actually happen and the service may fail with `229/SELINUX_CONTEXT`.

Fix by adding checks to `context->selinux_context_ignore`.

Closes: #21057
(cherry picked from commit 2ad2925de5f258d128ec8cdb07f10f3c52fa4fcf)

4 years agosystemctl: only fall back to local cgroup display if we talk to local systemd
Lennart Poettering [Thu, 28 Oct 2021 14:47:40 +0000 (16:47 +0200)]
systemctl: only fall back to local cgroup display if we talk to local systemd

Otherwise we likely show rubbish because even in local containers we
nowadays have cgroup namespacing, hence we likely can't access the
cgroup tree from the host at the same place as inside the container.

(cherry picked from commit 35ac0260db7b896604d156e9638ad15700083508)

4 years agohomework,repart: turn on cryptsetup logging before we have a context
Lennart Poettering [Thu, 28 Oct 2021 17:06:52 +0000 (19:06 +0200)]
homework,repart: turn on cryptsetup logging before we have a context

Otherwise we'll miss the log message from allocation of the context. We
already made this change in most of our tools that interface with
libcryptsetup, but we forgot two.

As suggested:

https://github.com/systemd/systemd/pull/21135#discussion_r738287504
(cherry picked from commit 30f194001ff647280ad49b68597c223e57ad7f6e)

4 years agoscope: refuse activation of scopes if no PIDs to add are left
Lennart Poettering [Wed, 27 Oct 2021 21:17:50 +0000 (23:17 +0200)]
scope: refuse activation of scopes if no PIDs to add are left

If all processes we are supposed to add are gone by the time we are
ready to do so, let's fail.

THis is heavily based on Cunlong Li's work, who thankfully tracked this
down.

Replaces: #20577
(cherry picked from commit 8d3e4ac7cd37200d1431411a4b98925a24b7d9b3)

4 years agocore: normalize 'r' variable handling in unit_attach_pids_to_cgroup() a bit
Lennart Poettering [Wed, 27 Oct 2021 21:08:58 +0000 (23:08 +0200)]
core: normalize 'r' variable handling in unit_attach_pids_to_cgroup() a bit

The 'r' variable is our "go-to" variable for error return codes, all
across our codebase. In unit_attach_pids_to_cgroup() it was so far used
in a strange way for most of the function: instead of directly storing
the error codes of functions we call we'd store it in a local variable
'q' instead, and propagate it to 'r' only  in some cases finally we'd
return the ultimate result of 'r'.

Let's normalize this a bit: let's always store error return values in
'r', and then use 'ret' as the variable to sometimes propagate errors
to, and then return that.

This also allows us to get rid of one local variable.

No actual codeflow changes, just some renaming of variables that allows
us to remove one.

(cherry picked from commit db4229d12f48663400802171b336c7cadbbe04ef)

4 years agoman: document that daemons can close fds they receive via sd_listen_fds() if they...
Lennart Poettering [Thu, 28 Oct 2021 09:05:22 +0000 (11:05 +0200)]
man: document that daemons can close fds they receive via sd_listen_fds() if they like

Fixes: #18872
(cherry picked from commit c896eb7ad65f4dbe968fdf01fa51e9ef4d2d11ed)

4 years agoman: document how nss-resolve and systemd-resolved communicate
Lennart Poettering [Thu, 28 Oct 2021 08:53:55 +0000 (10:53 +0200)]
man: document how nss-resolve and systemd-resolved communicate

Fixes: #20925
(cherry picked from commit 1d697549887d68953058049fcd833fa93a74402a)

4 years agoman: clarify the situation of unit templates regarding "systemctl list-units" + ...
Lennart Poettering [Thu, 28 Oct 2021 08:45:02 +0000 (10:45 +0200)]
man: clarify the situation of unit templates regarding "systemctl list-units" + "systemctl list-unit-files"

Fixes: #21075
(cherry picked from commit 7ea5e82f6ac78704f1554be9040b84bac75c2ec1)

4 years agosystemctl: small fixes for MountImages pretty printing
Luca Boccassi [Wed, 27 Oct 2021 10:17:02 +0000 (11:17 +0100)]
systemctl: small fixes for MountImages pretty printing

(cherry picked from commit 8ec6108c0bdb5ab2e05bc20ab41ad6653805fd00)

4 years agosystemctl: pretty-print ExtensionImages property
Luca Boccassi [Tue, 26 Oct 2021 21:55:30 +0000 (22:55 +0100)]
systemctl: pretty-print ExtensionImages property

Complex type, so without explicit support 'systemctl show' just prints [unprintable]

(cherry picked from commit 60c16c5cf3458199646cbda9dfe7763b6ba8b62f)

4 years agotest: do not use alloca() in function call
Yu Watanabe [Sat, 23 Oct 2021 15:16:57 +0000 (00:16 +0900)]
test: do not use alloca() in function call

(cherry picked from commit 4150584e63562616e16242f7b1016c0e642fb59e)

4 years agohwdb: Allow console users access to media* nodes
Bastien Nocera [Tue, 26 Oct 2021 09:57:30 +0000 (11:57 +0200)]
hwdb: Allow console users access to media* nodes

Newer webcams and video devices have controls only available through
/dev/media* nodes. Make sure they're accessible in the same way as
/dev/video* nodes.

Closes: #21054
(cherry picked from commit 63fbfc598f9f6d3ce34cc00a7687089dab24daff)

4 years agochange indicator used for later versions of VirtualBox (#21127)
Greg Zuro [Wed, 27 Oct 2021 04:02:37 +0000 (21:02 -0700)]
change indicator used for later versions of VirtualBox (#21127)

Detection of VirtualBox is accomplished in the existing code by *either* `innotek GmbH`
or `Oracle Corporation` existing in any of:

- /sys/class/dmi/id/product_name
- /sys/class/dmi/id/sys_vendor
- /sys/class/dmi/id/board_vendor
- /sys/class/dmi/id/bios_vendor

With Oracle's physical servers, both `/sys/class/dmi/id/sys_vendor` and
`/sys/class/dmi/id/board_vendor` contain `Oracle Corporation`, so those
servers are detected as `oracle` (VirtualBox).

VirtualBox has the following values in the latest versions:

- /sys/class/dmi/id/product_name: `VirtualBox`
- /sys/class/dmi/id/sys_vendor: `innotek GmbH`
- /sys/class/dmi/id/board_vendor: `Oracle Corporation`
- /sys/class/dmi/id/bios_vendor: `innotek GmbH`

Presumably the existing check for `innotek GmbH` is meant to detect
older versions of VirtualBox, while changing the second checked value
from `Oracle Corporation` to `VirtualBox` will reliably detect later and future
versions.

(cherry picked from commit cfee6b955154c30be31ffcf0e3b7b89374a52fff)

4 years agojson: do something remotely reasonable when we see NaN/infinity
Lennart Poettering [Tue, 26 Oct 2021 13:45:49 +0000 (15:45 +0200)]
json: do something remotely reasonable when we see NaN/infinity

JSON doesn't have NaN/infinity/-infinity concepts in the spec.
Implementations vary what they do with it. JSON5 + Python simply
generate special words "NAN" and "Inifinity" from it. Others generate
"null" for it.

At this point we never actually want to output this, so let's be
conservative and generate RFC compliant JSON, i.e. convert to null.

One day should JSON5 actually become a thing we can revisit this, but in
that case we should implement things via a flag, and only optinally
process nan/infinity/-infinity.

This patch is extremely simple: whenever accepting a
nan/infinity/-infinity from outside it converts it to NULL. I.e. we
convert on input, not output.

(cherry picked from commit 8f1daefce6e952f2fad9510e5101b5fc675d363f)

4 years agostat-util: specify O_DIRECTORY when reopening dir in dir_is_empty_at()
Lennart Poettering [Thu, 21 Oct 2021 16:07:06 +0000 (18:07 +0200)]
stat-util: specify O_DIRECTORY when reopening dir in dir_is_empty_at()

That way we can fail earlier if the specified fd is not actually a
directory.

(Also, it's not exactly according to standards to open things without
either O_RDONLY/O_RDWR...)

(cherry picked from commit b9d06522631a22d242374dc44a74c3b6459e3cb3)

4 years agoudev: do not try to rename interface if it is already up
Yu Watanabe [Sun, 24 Oct 2021 11:43:34 +0000 (20:43 +0900)]
udev: do not try to rename interface if it is already up

See dev_change_name() in kernel's net/core/dev.c.

Fixes #21105.

(cherry picked from commit 6681eb021a0b56ef0dc849e3b358a515ece16482)

4 years agovarlink: disconnect varlink link in one more case
Lennart Poettering [Thu, 21 Oct 2021 15:29:48 +0000 (17:29 +0200)]
varlink: disconnect varlink link in one more case

Previously we'd possibly see POLLHUP on a varlink link, and continue to
run epoll on it even though we have nothing to read nor write anymore.

Let's fix that, and once we know that there's nothing to write anymore
(or we saw a write error already) we'll disconnect after POLLHUP.

Fixes: #20062
(cherry picked from commit 7c26a631ad8bf91016db156b7d299ca68fd7866e)

4 years agonetwork: route: fix possible overflow in conversion usec_t -> uint32_t
Yu Watanabe [Fri, 15 Oct 2021 01:06:25 +0000 (10:06 +0900)]
network: route: fix possible overflow in conversion usec_t -> uint32_t

(cherry picked from commit ff43dddab7260c9220eaea2a545514772c0e581f)

4 years agoutmp: remove /dev from line
Vincent Bernat [Mon, 18 Oct 2021 18:58:43 +0000 (20:58 +0200)]
utmp: remove /dev from line

utmp(5) says `ut_line` is the device name minus the leading "/dev/". Therefore,
remove it. Without that, when using UtmpMode=user, we get `/dev/tty` in the
output of `last`/`w`.

(cherry picked from commit 33331d116db2eaf1189ea56ee4b36540179ac3dd)

4 years agomeson: use partial_dependency() to get include directory
Alexander Kanavin [Mon, 18 Oct 2021 08:13:07 +0000 (10:13 +0200)]
meson: use partial_dependency() to get include directory

Getting the variable directly from pkg-config (without
adding the sysroot prefix) is prone to host contamination
when building in sysroots as the compiler starts looking for the
headers on the host in addition to the sysroot.

Signed-off-by: Alexander Kanavin <alex@linutronix.de>
(cherry picked from commit bfa0ade9f208c5426655a8c09f633eb0984b4b01)

4 years agohomed,shutdown: call valgrind magic after LOOP_GET_STATUS64
Lennart Poettering [Fri, 15 Oct 2021 15:58:13 +0000 (17:58 +0200)]
homed,shutdown: call valgrind magic after LOOP_GET_STATUS64

valgrind doesn't understand LOOP_GET_STATUS64. We already work around
this in various placed, via VALGRIND_MAKE_MEM_DEFINE(), but we forgot
three places. Let's fix that.

(cherry picked from commit 48f462547d63e1d03bee612e1c77073263e71293)

4 years agouserdb: fix type to pass to connect()
Yu Watanabe [Fri, 15 Oct 2021 20:04:26 +0000 (05:04 +0900)]
userdb: fix type to pass to connect()

Fixes https://github.com/systemd/systemd/pull/20613#issuecomment-944621275.

(cherry picked from commit c14e57356f1e82c35bf3a3e8aaeac134b545801b)

4 years agodm-verity: Remove usage of integrity
Tony Asleson [Wed, 13 Oct 2021 19:18:12 +0000 (14:18 -0500)]
dm-verity: Remove usage of integrity

There is a difference between dm-verity and dm-integrity.  Remove
usage of integrity from verity documentation in man pages and
target files.

(cherry picked from commit 9a2a6ec4e31abe4b58b140767a82200f79c8645f)

4 years agohomework: don't bother with BLKRRPART on images that aren't block devices
Lennart Poettering [Fri, 15 Oct 2021 09:23:00 +0000 (11:23 +0200)]
homework: don't bother with BLKRRPART on images that aren't block devices

We currently call this ioctl even if we are backed by a regular file,
which is actually the common case. While this doesn't really hurt, it
does result in very confusing logs.

(cherry picked from commit 6a1301d8c97dc650e4355bb7c193f5821b3383a8)

4 years agosd-device-monitor: update log message to clarify the error will be ignored
Yu Watanabe [Wed, 13 Oct 2021 03:57:40 +0000 (12:57 +0900)]
sd-device-monitor: update log message to clarify the error will be ignored

(cherry picked from commit 6b652c03a47aa28898dffd408543c06670e3450d)

4 years agohomework: fix incorrect error variable use
Lennart Poettering [Thu, 14 Oct 2021 13:40:59 +0000 (15:40 +0200)]
homework: fix incorrect error variable use

(cherry picked from commit 82fb0911fc0aa2aaf39428ef36e78898ece2b4ea)

4 years agovirt: Support detection for ARM64 Hyper-V guests
Boqun Feng [Wed, 13 Oct 2021 03:32:09 +0000 (11:32 +0800)]
virt: Support detection for ARM64 Hyper-V guests

The detection of Microsoft Hyper-V VMs is done by cpuid currently,
however there is no cpuid on ARM64. And since ARM64 is now a supported
architecture for Microsoft Hyper-V guests[1], then use DMI tables to
detect a Hyper-V guest, which is more generic and works for ARM64.

[1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=7aff79e297ee1aa0126924921fd87a4ae59d2467

(cherry picked from commit 506bbc8569014253ea8614b680ccbc4fc2513a87)

4 years agocoredump: fix filename in journal when not compressed
xdavidwu [Fri, 5 Nov 2021 14:37:06 +0000 (22:37 +0800)]
coredump: fix filename in journal when not compressed

Since 587f2a5e564cf434c2e0a653f52b8f73e86092d8, filename for
not-compressed coredump is missing from save_external_coredump, making
it write COREDUMP_FILENAME= (empty) in journal, making `coredumpctl`
report it missing but it is actually saved.
This fixes it.

(cherry picked from commit 0cfb0971f0fcd345cae76f6837d9801b6cbde407)

4 years agosd-boot: Rework console input handling
Jan Janssen [Wed, 11 Aug 2021 12:59:46 +0000 (14:59 +0200)]
sd-boot: Rework console input handling

Fixes: #15847
Probably fixes: #19191

(cherry picked from commit e98d271e57f3d0356e444b6ea2d48836ee2769b0)

4 years agosd-boot: Unify error handling
Jan Janssen [Wed, 11 Aug 2021 12:59:46 +0000 (14:59 +0200)]
sd-boot: Unify error handling

log_error_stall() and log_error_status_stall() will ensure the user has
a chance to catch an error message by stalling and also forcing a
lightred/black color on it. Also, convert several Print() calls to it
since they are actually error messages.

(cherry picked from commit 8aba0eec499b762657f528988c2f093ac490620d)

4 years agosd-dhcp6-client: ignore IAs whose IAID do not match client's IAID
Yu Watanabe [Wed, 22 Sep 2021 07:35:56 +0000 (10:35 +0300)]
sd-dhcp6-client: ignore IAs whose IAID do not match client's IAID

But do not refuse whole message.

(cherry picked from commit 469fd57f181e2a8d93f01662418ca998e1239ea5)

4 years agoRevert "core: Check unit start rate limiting earlier"
Yu Watanabe [Mon, 18 Oct 2021 05:11:53 +0000 (14:11 +0900)]
Revert "core: Check unit start rate limiting earlier"

This reverts commit ed8fbbf1745c6a2dc0b8cd560ac8a3353f72e979.

This was causing problems during boot, see
https://bodhi.fedoraproject.org/updates/FEDORA-2021-a1a52487e6,
https://bugzilla.redhat.com/show_bug.cgi?id=2013386.
https://github.com/systemd/systemd/issues/21025

4 years agocoredumpctl: stop truncating information about coredump
Zbigniew Jędrzejewski-Szmek [Tue, 12 Oct 2021 17:46:25 +0000 (19:46 +0200)]
coredumpctl: stop truncating information about coredump

With the changes to limit that print 'Found module …' over and over, we were
hitting the journal field message limit, effectively truncating the info output.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1998488.

(cherry picked from commit 384c6207669eb0d92aa0043dbc01957c6c7ff41e)

4 years agolocaled: use PROJECT_FILE rather than __FILE__ for logging v249.5
Lennart Poettering [Mon, 11 Oct 2021 11:56:22 +0000 (13:56 +0200)]
localed: use PROJECT_FILE rather than __FILE__ for logging

All our log.h code uses PROJECT_FILE for this, let's hence use it here
too.

(cherry picked from commit 11c8b1f1031d368358286f4bb26abebd73cd2868)

4 years agoether-addr-util: make hw_addr_to_string() return valid string even if hardware addres...
Yu Watanabe [Wed, 15 Sep 2021 13:59:52 +0000 (22:59 +0900)]
ether-addr-util: make hw_addr_to_string() return valid string even if hardware address is null

Previously, when the length of the hardware address is zero, then the
buffer was not nul-terminated.

This also replaces sprintf() with hexchar().

(cherry picked from commit 914ac555cd40f9c09e655a737214bfb7de21b8d9)

4 years agocoredump: Don't log an error if D-Bus isn't running
Daan De Meyer [Wed, 6 Oct 2021 12:20:36 +0000 (13:20 +0100)]
coredump: Don't log an error if D-Bus isn't running

coredumpctl could be used in a chroot where D-Bus isn't running. If
that's the case, we shouldn't consider it an error if we can't connect
to the D-Bus daemon so let's reduce the severity of the error we log
when we can't connect to D-Bus because the socket doesn't exist.

(cherry picked from commit 414bd2e786f9912f51b82e5fe4a1126179a5652a)

4 years agocore/service: also check path in exec commands
Yu Watanabe [Tue, 5 Oct 2021 15:19:41 +0000 (00:19 +0900)]
core/service: also check path in exec commands

(cherry picked from commit 8688a389cabdff61efe187bb85cc1776de03c460)

4 years agocore: fix SIGABRT on empty exec command argv
Henri Chain [Tue, 5 Oct 2021 11:10:31 +0000 (13:10 +0200)]
core: fix SIGABRT on empty exec command argv

This verifies that the argv part of any exec_command parameters that
are sent through dbus is not empty at deserialization time.

There is an additional check in service.c service_verify() that again
checks if all exec_commands are correctly populated, after the service
has been loaded, whether through dbus or otherwise.

Fixes #20933.

(cherry picked from commit 29500cf8c47e6eb0518d171d62aa8213020c9152)

4 years agouser-record: disable two pbkdf fields that don't apply for pkbdf2
Lennart Poettering [Tue, 5 Oct 2021 16:24:05 +0000 (18:24 +0200)]
user-record: disable two pbkdf fields that don't apply for pkbdf2

Fixes: #20830
(cherry picked from commit 8b4f88d13681c6dec839de06c668d32374d44724)

4 years agobasic/env-util: correctly parse extended vars after non-extended vars (#20941)
Andrew Soutar [Wed, 6 Oct 2021 02:55:27 +0000 (22:55 -0400)]
basic/env-util: correctly parse extended vars after non-extended vars (#20941)

(cherry picked from commit 5ef97a712236f0ddddec52665c0aea7d4e6d3c13)

4 years agorepart: use right error variable
Lennart Poettering [Tue, 5 Oct 2021 12:10:27 +0000 (14:10 +0200)]
repart: use right error variable

(cherry picked from commit 8ac04a65477b59c9143b635c0c0daa5152d9b466)

4 years agosleep: don't skip resume device with low priority/available space
Egor [Sun, 3 Oct 2021 00:42:50 +0000 (03:42 +0300)]
sleep: don't skip resume device with low priority/available space

this fixes hibernation when there's a higher priority swap preceding
the resume swap in /proc/swaps.

fixes #19486

(cherry picked from commit 936a7cb66a0b423e75ceef87f02537067ad17002)

4 years agomount-util: fix fd_is_mount_point() when both the parent and directory are network fs
Franck Bui [Thu, 30 Sep 2021 12:05:36 +0000 (14:05 +0200)]
mount-util: fix fd_is_mount_point() when both the parent and directory are network fs

The second call to name_to_handle_at_loop() didn't check for the specific
errors that can happen when the parent dir is mounted by nfs and instead of
falling back like it's done for the child dir, fd_is_mount_point() failed in
this case.

(cherry picked from commit 964ccab8286a7e75d7e9107f574f5cb23752bd5d)

4 years agotest: Add failing/non-failing syscall filter test setting architecture
Benjamin Berg [Fri, 24 Sep 2021 11:35:34 +0000 (13:35 +0200)]
test: Add failing/non-failing syscall filter test setting architecture

This adds a high level test verifying that syscall filtering in
combination with a simple architecture filter for the "native"
architecture works fine.

(cherry picked from commit e975a94559900f47a3a5cc333682992616877a67)

4 years agotest: Check that "native" architecture is always filtered
Benjamin Berg [Fri, 17 Sep 2021 12:00:39 +0000 (14:00 +0200)]
test: Check that "native" architecture is always filtered

(cherry picked from commit 08bf703cc1511817cdf67543c3b166dc8831ba8c)

4 years agoseccomp: Always install filters for native architecture
Benjamin Berg [Fri, 17 Sep 2021 11:05:32 +0000 (13:05 +0200)]
seccomp: Always install filters for native architecture

The commit 6597686865ff ("seccomp: don't install filters for archs that
can't use syscalls") introduced a regression where filters may not be
installed for the "native" architecture. This means that setting
SystemCallArchitectures=native for a unit effectively disables the
SystemCallFilter= and SystemCallLog= options.

Conceptually, we have two filter stages:
 1. architecture used for syscall (SystemCallArchitectures=)
 2. syscall + architecture combination (SystemCallFilter=)

The above commit tried to optimize the filter generation by skipping the
second level filtering when it is not required.

However, systemd will never fully block the "native" architecture using
the first level filter. This makes the code a lot simpler, as systemd
can execve() the target binary using its own architecture. And, it
should be perfectly fine as the "native" architecture will always be the
one with the most restrictive seccomp filtering.

Said differently, the bug arises because (on x86_64):
 1. x86_64 is permitted by libseccomp already
 2. native != x86_64
 3. the loop wants to block x86_64 because the permitted set only
    contains "native" (i.e. "native" != "x86_64")
 4. x86_64 is marked as blocked in seccomp_local_archs

Thereby we have an inconsistency, where it is marked as blocked in the
seccomp_local_archs array but it is allowed by libseccomp. i.e. we will
skip generating filter stage 2 without having stage 1 in place.

The fix is simple, we just skip the native architecture when looping
seccomp_local_archs. This way the inconsistency cannot happen.

(cherry picked from commit f833df38488ea40fc3d601ccefd64cfa3fce8bb4)

4 years agonetworkd-test: fix resolved_domain_restricted_dns
Michael Biebl [Thu, 30 Sep 2021 23:00:28 +0000 (01:00 +0200)]
networkd-test: fix resolved_domain_restricted_dns

megasearch.net was meant to be a non-existing bogus domain, and had been
for a long time. But it seems some domain grabber recently registered
it, and it's an actual thing now:

  $ host megasearch.net
  megasearch.net has address 207.148.248.143

This causes the test to fail randomly.

Use search.example.com instead which yields

  $ host search.example.com
  Host search.example.com not found: 3(NXDOMAIN)

Fixes: #18357
(cherry picked from commit 528dd6a42389fcf4aa490c0fa0d858772e930d13)

4 years agocore/mount: add implicit unit dependencies even if when mount unit is generated from...
Yu Watanabe [Sun, 29 Aug 2021 12:20:43 +0000 (21:20 +0900)]
core/mount: add implicit unit dependencies even if when mount unit is generated from /proc/self/mountinfo

Hopefully fixes #20566.

(cherry picked from commit aebff2e7ce209fc2d75b894a3ae8b80f6f36ec11)

4 years agohwdb: sensors: Fix some modalias matches no longer working with newer kernels
Hans de Goede [Tue, 31 Aug 2021 13:49:33 +0000 (15:49 +0200)]
hwdb: sensors: Fix some modalias matches no longer working with newer kernels

Kernels >= 5.8 have added new fields to the dmi/id/modalias file in the
middle of the modalias (instead of adding them at the end).

Specifically new ":br<value>:" and (optional) ":efr<value>:" fields have
been added between the ":bd<value>:" and ":svn<value>:" fields.

Note the 5.13.0 and 5.14.0 kernels also added a new ":sku<value>:" field
between the ":pvr<value>:" and ":rvn<value>:" fields, this has been fixed
in later 5.13.y and 5.14.y releases, by moving the sku field to the end:
https://lore.kernel.org/lkml/20210831130508.14511-1-hdegoede@redhat.com/

Unfortunately the same cannot be done for the new br and efr fields since
those have been added more then a year ago and hwdb even already has some
newer entries relying on the new br field being there (and thus not working
with older kernels).

Fix the issue with the br and efr fields through the following changes:

1. Replace any matches on ":br<value>" from newer entries with an '*'
2. Replace "bd<value>:svn<value>" matches with: "bd<value>:*svn<value>"
   inserting an '*' where newer kernels will have the new br + efr fields

This makes these matches working with old as well as new kernels.

Link: https://github.com/systemd/systemd/issues/20550
Link: https://github.com/systemd/systemd/pull/20562
(cherry picked from commit f81351554285f1d4869fe842659b72797edfc899)

4 years agobasic/unit-file: don't filter out names starting with dot
Anita Zhang [Wed, 29 Sep 2021 06:52:39 +0000 (23:52 -0700)]
basic/unit-file: don't filter out names starting with dot

Fixes #20859
Reverts 3796bdc55d6ba499d1049f749072218879e619a7

(cherry picked from commit 14bb72953458caace048b55ead7ea06a592b864f)

4 years agocore: drop "const" from NeedsDaemonReload unit dbus property
Lennart Poettering [Wed, 29 Sep 2021 08:30:17 +0000 (10:30 +0200)]
core: drop "const" from NeedsDaemonReload unit dbus property

It's not "const", it can change any time if people change the fs, and we
don#t send out notifications for it. Hence don't claim it was const.
(Otherwise clients might cache it, but they should not)

Prompted-by: #20792
(cherry picked from commit e30a3ba16a5da4b46cd6c8bc363dbccb791fc45e)

4 years agoresolvconf-compat: make "-u" operation a NOP
Lennart Poettering [Wed, 29 Sep 2021 08:48:24 +0000 (10:48 +0200)]
resolvconf-compat: make "-u" operation a NOP

According to the various man pages of "resolvconf" the -u switch is for:

"-u Just run the update scripts (if updating is enabled)."

"-u Force resolvconf to update all its subscribers. resolvconf does not
    update the subscribers when adding a resolv.conf that matches what
    it already has for that interface."

We have no "subscribers", we ourselves are the only "subscriber" we
support. Hence it's probably better to ignore such a request and make it
a NOP, then to fail.

Fixes: #20748
(cherry picked from commit bee07a399572e0d60600c040a84099ecb418ed33)

4 years agoAdd remaining supported schemes as options for default-net-naming-scheme
dann frazier [Mon, 27 Sep 2021 17:00:53 +0000 (11:00 -0600)]
Add remaining supported schemes as options for default-net-naming-scheme

(cherry picked from commit aa0a23ec8629aa033a098ab55e9d97ccd9fbf39c)

4 years agoresolved: suppress writing DNS server info into /etc/resolv.conf for non-standard...
Lennart Poettering [Mon, 27 Sep 2021 12:28:16 +0000 (14:28 +0200)]
resolved: suppress writing DNS server info into /etc/resolv.conf for non-standard UDP ports

glibc doesn't support this, hence don#t generate it.

Fixes: #20836
(cherry picked from commit a50dadf2fd7413bbfc26af7e2ad2900b3e06af82)

4 years agoman: fix a reference in timedatectl man page
Anssi Hannula [Fri, 24 Sep 2021 12:26:21 +0000 (15:26 +0300)]
man: fix a reference in timedatectl man page

timedatectl(1) says the synchronization service list generation is
described "below", but in reality it is documented in
systemd-timedated.service(8).

Fix the sentence to reference the correct man page.

(cherry picked from commit 9376b2aab3692d26de60a93e396f84fa2799b80b)

4 years agolibsystemd-network: disable event sources before unref them
Yu Watanabe [Fri, 24 Sep 2021 08:26:35 +0000 (17:26 +0900)]
libsystemd-network: disable event sources before unref them

Fixes #20825.

(cherry picked from commit eb2f750242d6c4c0963887dbd561d8bafa318685)

4 years agonetwork: disable event sources before unref them
Yu Watanabe [Fri, 24 Sep 2021 08:26:10 +0000 (17:26 +0900)]
network: disable event sources before unref them

(cherry picked from commit d105befc976ad704d3b17b3a5ee1b659a5f624d4)

4 years agobootctl: Fix update not adding EFI entry if Boot IDs are non-consecutive
Anssi Hannula [Thu, 23 Sep 2021 09:08:05 +0000 (12:08 +0300)]
bootctl: Fix update not adding EFI entry if Boot IDs are non-consecutive

"bootctl update" tries to add sd-boot to the EFI boot loader list if it
is not already there. To do so, it uses find_slot() which finds the
proper BootXXXX slot ID to use and also returns 1 if an existing sd-boot
entry was found at this ID or 0 if it is a new unused ID. In "update"
case install_variables() only writes the entry in case 0 (no existing
entry).

However, find_slot() erroneously returns 1 if it finds a gap in the Boot
IDs (i.e. when not resorting to max(ids) + 1). This causes
"bootctl update" to not add a missing systemd-boot boot entry if the
existing BootXXXX entry IDs are not consecutive.

Fix that by returning 0 in find_slot() when an empty gap ID is selected
to make it match the behavior when selecting an empty non-gap ID.

(cherry picked from commit 26d54e1263dcb58daa6578595cc6ab1037315593)

4 years agotest-fileio: test read_virtual_file() with more files from /proc
Lennart Poettering [Thu, 16 Sep 2021 09:31:52 +0000 (11:31 +0200)]
test-fileio: test read_virtual_file() with more files from /proc

i.e. let's pick some files we know are too large, or where struct stat's
.st_size is zero even though non-empty, and test read_virtual_file()
with that, to ensure things are handled sensibly. Goal is to ensure all
three major codepaths in read_virtual_file() are tested.

Prompted-by: #20743
(cherry picked from commit f3b751220bb842ce22a4f607d817f481f0961d40)

4 years agofileio: fix truncated read handling in read_virtual_file()
Lennart Poettering [Thu, 16 Sep 2021 10:20:09 +0000 (12:20 +0200)]
fileio: fix truncated read handling in read_virtual_file()

We mishandled the case where the size we read from the file actually
matched the maximum size fully. In that case we cannot really make a
determination whether the file was fully read or only partially. In that
case let's do another loop, so that we operate with a buffer, and
we can detect the EOF (which will be signalled to us via a short read).

(cherry picked from commit 00bd9a4a82ed57bc0c7f158da4564fc1eab808b4)

4 years agofileio: start with 4k buffer for procfs
Anita Zhang [Tue, 14 Sep 2021 23:33:10 +0000 (16:33 -0700)]
fileio: start with 4k buffer for procfs

There's a very gradual increase of anonymous memory in systemd-journald that
blames to 2ac67221bb6270f0fbe7cbd0076653832cd49de2.

systemd-journald makes many calls to read /proc/PID/cmdline and
/proc/PID/status, both of which tend to be well under 4K. However the
combination of allocating 4M read buffers, then using `realloc()` to
shrink the buffer in `read_virtual_file()` appears to be creating
fragmentation in the heap (when combined with the other allocations
systemd-journald is doing).

To help mitigate this, try reading /proc with a 4K buffer as
`read_virtual_file()` did before 2ac67221bb6270f0fbe7cbd0076653832cd49de2.
If it isn't big enough then try again with the larger buffers.

(cherry picked from commit 5aaa55d841249f057fd69e50cf12a52e9781a6ce)

4 years agofileio: set O_NOCTTY when reading virtual files
Lennart Poettering [Tue, 14 Sep 2021 21:11:55 +0000 (23:11 +0200)]
fileio: set O_NOCTTY when reading virtual files

Better be safe than sorry, maybe someone points this call to a TTY one
day, and we'd rather not make it our controlling TTY in that case.

(cherry picked from commit be991d7678c35aa037ef79672c0c70781eebed9c)

4 years agofileio: lower maximum virtual file buffer size by one byte
Lennart Poettering [Tue, 14 Sep 2021 21:03:37 +0000 (23:03 +0200)]
fileio: lower maximum virtual file buffer size by one byte

When reading virtual files (i.e. procfs, sysfs, …) we currently put a
limit of 4M-1 on that. We have to pick something, and we have to read
these files in a single read() (since the kernel generally doesn't
support continuation read()s for them). 4M-1 is actually the maximum
size the kernel allows for reads from files in /proc/sys/, all larger
reads will result in an ENOMEM error (which is really weird, but the
kernel does what the kernel does). Hence 4M-1 sounds like a smart
choice.

However, we made one mistake here: in order to be able to detect EOFs
properly we actually read one byte more than we actually intend to
return: if that extra byte can be read, then we know the file is
actually larger than our limit and we can generate an EFBIG error from
that. However, if it cannot be read then we know EOF was hit, and we are
good. So ultimately after all we issued a single 4M read, which the
kernel then responds with ENOMEM to.  And that means read_virtual_file()
actually doesn't work properly right now on /proc/sys/. Let's fix that.

The fix is simple, lower the limit of the the buffer we intend to return
by one, i.e. 4M-2. That way, the read() we'll issue is exactly as large
as the limit the kernel allows, and we still get safely detect EOF from
it.

(cherry picked from commit 7ab7547a40d456d34120b2f44b26385ac1338ebd)

4 years agowatchdog: pass right error code to log function so that %m works
Lennart Poettering [Wed, 15 Sep 2021 13:43:42 +0000 (15:43 +0200)]
watchdog: pass right error code to log function so that %m works

(cherry picked from commit a4588af942af976c55f72869340c24d5017db278)

4 years agosd-journal: Ignore data threshold if set to zero in sd_journal_enumerate_fields()
Daan De Meyer [Wed, 15 Sep 2021 12:05:46 +0000 (13:05 +0100)]
sd-journal: Ignore data threshold if set to zero in sd_journal_enumerate_fields()

According to the documentation, Setting the data threshold to zero disables the
data threshold alltogether. Let's make sure we actually implement this behaviour
in sd_journal_enumerate_fields() by only applying the data threshold if it exceeds
zero.

(cherry picked from commit adbd80f51088058d55e703abe0ac11476cfe0ba4)