systemd/.git
4 years agologind: fix bad error propagation
Lennart Poettering [Mon, 6 Aug 2018 16:21:37 +0000 (18:21 +0200)]
logind: fix bad error propagation

(cherry picked from commit cce08496e7353e3e9903b42695aba3f9d259b90a)

Related: #1642460

4 years agologind: correct bad clean-up path
Lennart Poettering [Mon, 6 Aug 2018 16:19:45 +0000 (18:19 +0200)]
logind: correct bad clean-up path

(cherry picked from commit d88ffeeeefda4c3447223fd36f8e30f23c931e48)

Related: #1642460

4 years agologind: save/restore User object's "stopping" field during restarts
Lennart Poettering [Mon, 6 Aug 2018 16:14:11 +0000 (18:14 +0200)]
logind: save/restore User object's "stopping" field during restarts

Whether we are stopping or not is highly relevant, hence don't forget it
across restarts.

(cherry picked from commit d865bc024bf28c17120d7322a81e9a99997a59f6)

Related: #1642460

4 years agologind: improve logging in manager_connect_console()
Lennart Poettering [Fri, 3 Aug 2018 18:21:27 +0000 (20:21 +0200)]
logind: improve logging in manager_connect_console()

let's make sure we log about every failure

Also, complain about systems where /dev/tty0 exists but
/sys/class/tty/tty0/active does not. Such systems (usually container
environments) are pretty broken as they mount something that is not a VC
to /dev/tty0 and they really shouldn't.

Systems should either have a VC or not, but not badly fake one by
mounting things wildly.

This just adds a warning message, as before we'll simply turn off VC
handling in this case.

(cherry picked from commit 0b6d55cae9b8adc507fbea95d1b2874729a77386)

Related: #1642460

4 years agounits: improve Description= string a bit
Lennart Poettering [Mon, 6 Aug 2018 16:15:07 +0000 (18:15 +0200)]
units: improve Description= string a bit

Let's not use the word "wrapper", as it's not clear what that is, and in
some way any unit file is a "wrapper"... let's simply say that it's
about the runtime directory.

(cherry picked from commit 14df094a51e87013d96ac697ae4f14593cbcad39)

Related: #1642460

4 years agounits: set StopWhenUnneeded= for the user slice units too
Lennart Poettering [Fri, 3 Aug 2018 18:19:38 +0000 (20:19 +0200)]
units: set StopWhenUnneeded= for the user slice units too

We'd like them to go away, just like the user-runtime-dir@.service when
they aren't needed anymore.

(cherry picked from commit 1007473b49b5aaeef0e53cd4a15f4ed8cf721926)

Related: #1642460

4 years agologind: turn of stdio locking when writing session files too
Lennart Poettering [Fri, 3 Aug 2018 18:18:55 +0000 (20:18 +0200)]
logind: turn of stdio locking when writing session files too

This just copies what we already do for user and seat files to session
files.

(cherry picked from commit 44176400138e18d9087e0864ca97041416a90d47)

Related: #1642460

4 years agologind: fix serialization/deserialization of user's "display session"
Lennart Poettering [Fri, 3 Aug 2018 17:04:35 +0000 (19:04 +0200)]
logind: fix serialization/deserialization of user's "display session"

Previously this was serialized as part of the user object. This didn't
work however, as we load users first, and sessions seconds and hence
referencing a session from the user load logic cannot work.

Fix this by storing an IS_DISPLAY property along with each session, and
make the session with this set display session when it is loaded.

(cherry picked from commit 1c8280fd47b6561d35b15b3b6d49bdeacf891bfd)

Related: #1642460

4 years agologind: rework Seat/Session/User object allocation and freeing a bit
Lennart Poettering [Fri, 3 Aug 2018 16:53:09 +0000 (18:53 +0200)]
logind: rework Seat/Session/User object allocation and freeing a bit

Let's update things a bit to follow current practices:

- User structure initialization rather than zero-initialized allocation

- Always propagate proper errors from allocation functions

- Use _cleanup_ for freeing objects when allocation fails half-way

- Make destructors return NULL

(cherry picked from commit 8c29a4570993105fecc12288596d2ee77c7f82b8)

Related: #1642460

4 years agoshared/seccomp-util: address family filtering is broken on ppc
Zbigniew Jędrzejewski-Szmek [Thu, 26 Nov 2020 10:23:54 +0000 (11:23 +0100)]
shared/seccomp-util: address family filtering is broken on ppc

This reverts the gist of da1921a5c396547261c8c7fcd94173346eb3b718 and
0d9fca76bb69e162265b2d25cb79f1890c0da31b (for ppc).

Quoting #17559:
> libseccomp 2.5 added socket syscall multiplexing on ppc64(el):
> https://github.com/seccomp/libseccomp/pull/229
>
> Like with i386, s390 and s390x this breaks socket argument filtering, so
> RestrictAddressFamilies doesn't work.
>
> This causes the unit test to fail:
> /* test_restrict_address_families */
> Operating on architecture: ppc
> Failed to install socket family rules for architecture ppc, skipping: Operation canceled
> Operating on architecture: ppc64
> Failed to add socket() rule for architecture ppc64, skipping: Invalid argument
> Operating on architecture: ppc64-le
> Failed to add socket() rule for architecture ppc64-le, skipping: Invalid argument
> Assertion 'fd < 0' failed at src/test/test-seccomp.c:424, function test_restrict_address_families(). Aborting.
>
> The socket filters can't be added so `socket(AF_UNIX, SOCK_DGRAM, 0);` still
> works, triggering the assertion.

Fixes #17559.

(cherry picked from commit d5923e38bc0e6cf9d7620ed5f1f8606fe7fe1168)

Resolves: #1982650

4 years agoSet default core ulimit to 0, but keep the hard limit ulimited
Frantisek Sumsal [Tue, 3 Aug 2021 09:52:36 +0000 (11:52 +0200)]
Set default core ulimit to 0, but keep the hard limit ulimited

so users can change it later.

Follow-up to 830bd662276ee117e65a4b3d541f77e8b172eafd.

rhel-only
Resolves: #1905582

4 years agoUpdate link to RHEL documentation
David Tardon [Thu, 15 Jul 2021 08:35:08 +0000 (10:35 +0200)]
Update link to RHEL documentation

RHEL-only

Resolves: #1982584

4 years agologind: simplify flags handling a bit
Lennart Poettering [Tue, 2 Feb 2021 14:27:30 +0000 (15:27 +0100)]
logind: simplify flags handling a bit

Let's split out the two codepaths a bit, and emphasize which ones it the
new-style and which the old-style codepath, and let's clearly convert
the params of the old-stye into the new style for further processing, so
that the old style path is brief and isolated.

No change in behaviour.

Follow-up for: 8885fed4e3a52cf1bf105e42043203c485ed9d92

(cherry picked from commit d3e99bc0c7f785dcf4e73cfed12f74002e73be5f)

Related: #1269726

4 years agologind: add …WithFlags methods to policy
Zbigniew Jędrzejewski-Szmek [Tue, 9 Mar 2021 08:03:58 +0000 (09:03 +0100)]
logind: add …WithFlags methods to policy

Without this, privilege escalation through polkit does not work, because all
methods fail with permission errors.

Forgotten in 8885fed4e3a52cf1bf105e42043203c485ed9d92.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1933335.

(cherry picked from commit 2280db756eaff795091871feee8e47d4f6989a58)

Related: #1269726

4 years agologind: Introduce RebootWithFlags and others
Deepak Rawat [Mon, 25 Jan 2021 17:14:08 +0000 (09:14 -0800)]
logind: Introduce RebootWithFlags and others

Add new systemd-logind WithFlags version for Reboot and others. These
methods add a unit64 parameter, with which can send additional control flags.

(cherry picked from commit 00971ea5164e2e7a5f2d7ffe12a566b62d282556)

Related: #1269726

4 years agoAdded option --check-inhibitors for non-tty usage
Felix Stupp [Thu, 29 Oct 2020 11:48:48 +0000 (12:48 +0100)]
Added option --check-inhibitors for non-tty usage

As described in #2680, systemctl did ignore inhibitors if it is not
attached to a tty to allow scripts to ignore inhibitors automatically.
This pull request preserves this behavior but allows scripts to
explicit check inhibitors if required.

The new parameter '--check-inhibitors=yes' enables this feature.
The old parameter '-i'/'--ignore-inhibitors' was deprecated in favor
of '--check-inhibitors=no', the default behaviour can be specified
with '--check-inhibitors=auto'.
The new parameter is also described in the documentations and shell
completions found here.

(cherry picked from commit b8ebe378b49a31549b8531d4b3177095ef385d55)

Related: #1269726

4 years agomeson: bump timeout for test-udev to 180s v239-49
Frantisek Sumsal [Fri, 18 Jan 2019 21:32:42 +0000 (22:32 +0100)]
meson: bump timeout for test-udev to 180s

On some (mainly virtual) machines the last test takes more than 30
seconds, which causes unnecessary fails, as the test itself is working
properly.

(cherry picked from commit bb0e960448fce037f5b82b1829863da8ccbe636b)

Related: #1934504

4 years agoci: add missing test dependencies
Frantisek Sumsal [Wed, 3 Mar 2021 12:14:02 +0000 (13:14 +0100)]
ci: add missing test dependencies

rhel-only
Related: #1934504

4 years agoci: run unit tests on CentOS 8 Stream as well
Frantisek Sumsal [Wed, 3 Mar 2021 11:49:20 +0000 (12:49 +0100)]
ci: run unit tests on CentOS 8 Stream as well

rhel-only
Related: #1934504

4 years agoci: drop forgotten Travis references
Frantisek Sumsal [Wed, 3 Mar 2021 11:33:38 +0000 (12:33 +0100)]
ci: drop forgotten Travis references

rhel-only
Related: #1934504

4 years agoci: run unit tests on z-stream branches as well
Frantisek Sumsal [Thu, 15 Jul 2021 10:27:33 +0000 (12:27 +0200)]
ci: run unit tests on z-stream branches as well

Resolves: #1970860
rhel-only

4 years agosd-event: always reshuffle time prioq on changing online/offline state
Yu Watanabe [Mon, 14 Jun 2021 17:13:59 +0000 (02:13 +0900)]
sd-event: always reshuffle time prioq on changing online/offline state

Before 81107b8419c39f726fd2805517a5b9faab204e59, the compare functions
for the latest or earliest prioq did not handle ratelimited flag.
So, it was ok to not reshuffle the time prioq when changing the flag.

But now, those two compare functions also compare the source is
ratelimited or not. So, it is necessary to reshuffle the time prioq
after changing the ratelimited flag.

Hopefully fixes #19903.

(cherry picked from commit 2115b9b6629eeba7bc9f42f757f38205febb1cb7)

Related: #1968528

4 years agosd-event: make event_source_time_prioq_reshuffle() accept all event source type
Yu Watanabe [Mon, 14 Jun 2021 17:03:02 +0000 (02:03 +0900)]
sd-event: make event_source_time_prioq_reshuffle() accept all event source type

But it does nothing for an event source which is neither a timer nor
ratelimited.

(cherry picked from commit 5c08c7ab23dbf02aaf4e4bbae8e08a195da230a4)

Related: #1968528

4 years agosd-event: use usec_add()
Yu Watanabe [Mon, 14 Jun 2021 16:01:48 +0000 (01:01 +0900)]
sd-event: use usec_add()

(cherry picked from commit a595fb5ca9c69c589e758e9ebe3b70ac90450ba3)

Related: #1968528

4 years agosd-event: use CMP() macro
Yu Watanabe [Mon, 14 Jun 2021 15:51:33 +0000 (00:51 +0900)]
sd-event: use CMP() macro

(cherry picked from commit 06e131477d82b83c5d516e66d6e413affd7c774a)

Related: #1968528

4 years agosd-event: drop unnecessary "else"
Yu Watanabe [Mon, 14 Jun 2021 15:44:04 +0000 (00:44 +0900)]
sd-event: drop unnecessary "else"

(cherry picked from commit 7e2bf71ca3638e36ee33215ceee386ba8013da6d)

Related: #1968528

4 years agosd-event: change ordering of pending/ratelimited events
Lennart Poettering [Tue, 8 Jun 2021 07:07:51 +0000 (00:07 -0700)]
sd-event: change ordering of pending/ratelimited events

Instead of ordering non-pending before pending we should order
"non-pending OR ratelimited" before "pending AND not-ratelimited".
This fixes a bug where ratelimited events were ordered at the end of the
priority queue and could be stuck there for an indeterminate amount of
time.

(cherry picked from commit 81107b8419c39f726fd2805517a5b9faab204e59)

Related: #1968528

4 years agobasic/unit-name: do not use strdupa() on a path
Zbigniew Jędrzejewski-Szmek [Wed, 23 Jun 2021 09:46:41 +0000 (11:46 +0200)]
basic/unit-name: do not use strdupa() on a path

The path may have unbounded length, for example through a fuse mount.

CVE-2021-33910: attacked controlled alloca() leads to crash in systemd and
ultimately a kernel panic. Systemd parses the content of /proc/self/mountinfo
and each mountpoint is passed to mount_setup_unit(), which calls
unit_name_path_escape() underneath. A local attacker who is able to mount a
filesystem with a very long path can crash systemd and the whole system.

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

The resulting string length is bounded by UNIT_NAME_MAX, which is 256. But we
can't easily check the length after simplification before doing the
simplification, which in turns uses a copy of the string we can write to.
So we can't reject paths that are too long before doing the duplication.
Hence the most obvious solution is to switch back to strdup(), as before
7410616cd9dbbec97cf98d75324da5cda2b2f7a2.

Resolves: #1974700

(cherry picked from commit 441e0115646d54f080e5c3bb0ba477c892861ab9)

4 years agoremove a left-over break
David Tardon [Fri, 25 Jun 2021 08:42:53 +0000 (10:42 +0200)]
remove a left-over break

By the "same logic as above...", we want to continue to fallback here,
but the break prohibits that.

This is a follow-up for ee1aa61c4710ae567a2b844e0f0bb8cb0456ab8c .

(cherry picked from commit 99df1cb6f50875db513a5b45f18191460a150f3d)

Related: #1970860

4 years agotest-mountpointutil-util: do not assert in test_mnt_id() v239-48
Zbigniew Jędrzejewski-Szmek [Mon, 14 Sep 2020 15:58:03 +0000 (17:58 +0200)]
test-mountpointutil-util: do not assert in test_mnt_id()

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

I *think* this a kernel bug: the mnt_id as listed in /proc/self/mountinfo is different
than the one we get from /proc/self/fdinfo/. This only matters when both statx and
name_to_handle_at are unavailable and we hit the fallback path that goes through fdinfo:

(gdb) !uname -r
5.6.19-200.fc31.ppc64le

(gdb) !cat /proc/self/mountinfo
697 664 253:0 /var/lib/mock/fedora-31-ppc64le/root / rw,relatime shared:298 master:1 - xfs /dev/mapper/fedora_rh--power--vm14-root rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota
698 697 253:0 /var/cache/mock/fedora-31-ppc64le/yum_cache /var/cache/yum rw,relatime shared:299 master:1 - xfs /dev/mapper/fedora_rh--power--vm14-root rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota
699 697 253:0 /var/cache/mock/fedora-31-ppc64le/dnf_cache /var/cache/dnf rw,relatime shared:300 master:1 - xfs /dev/mapper/fedora_rh--power--vm14-root rw,seclabel,attr2,inode64,logbufs=8,logbsize=32k,noquota
700 697 0:32 /mock-selinux-plugin.7me9bfpi /proc/filesystems rw,nosuid,nodev shared:301 master:18 - tmpfs tmpfs rw,seclabel <==========================================================
701 697 0:41 / /sys ro,nosuid,nodev,noexec,relatime shared:302 - sysfs sysfs ro,seclabel
702 701 0:21 / /sys/fs/selinux ro,nosuid,nodev,noexec,relatime shared:306 master:8 - selinuxfs selinuxfs rw
703 697 0:42 / /dev rw,nosuid shared:303 - tmpfs tmpfs rw,seclabel,mode=755
704 703 0:43 / /dev/shm rw,nosuid,nodev shared:304 - tmpfs tmpfs rw,seclabel
705 703 0:45 / /dev/pts rw,nosuid,noexec,relatime shared:307 - devpts devpts rw,seclabel,gid=5,mode=620,ptmxmode=666
706 703 0:6 /btrfs-control /dev/btrfs-control rw,nosuid shared:308 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
707 703 0:6 /loop-control /dev/loop-control rw,nosuid shared:309 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
708 703 0:6 /loop0 /dev/loop0 rw,nosuid shared:310 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
709 703 0:6 /loop1 /dev/loop1 rw,nosuid shared:311 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
710 703 0:6 /loop10 /dev/loop10 rw,nosuid shared:312 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
711 703 0:6 /loop11 /dev/loop11 rw,nosuid shared:313 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
712 703 0:6 /loop2 /dev/loop2 rw,nosuid shared:314 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
713 703 0:6 /loop3 /dev/loop3 rw,nosuid shared:315 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
714 703 0:6 /loop4 /dev/loop4 rw,nosuid shared:316 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
715 703 0:6 /loop5 /dev/loop5 rw,nosuid shared:317 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
716 703 0:6 /loop6 /dev/loop6 rw,nosuid shared:318 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
717 703 0:6 /loop7 /dev/loop7 rw,nosuid shared:319 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
718 703 0:6 /loop8 /dev/loop8 rw,nosuid shared:320 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
719 703 0:6 /loop9 /dev/loop9 rw,nosuid shared:321 master:9 - devtmpfs devtmpfs rw,seclabel,size=4107840k,nr_inodes=64185,mode=755
720 697 0:44 / /run rw,nosuid,nodev shared:305 - tmpfs tmpfs rw,seclabel,mode=755
721 720 0:25 /systemd/nspawn/propagate/9cc8a155d0244558b273f773d2b92142 /run/systemd/nspawn/incoming ro master:12 - tmpfs tmpfs rw,seclabel,mode=755
722 697 0:32 /mock-resolv.dvml91hp /etc/resolv.conf rw,nosuid,nodev shared:322 master:18 - tmpfs tmpfs rw,seclabel
725 697 0:47 / /proc rw,nosuid,nodev,noexec,relatime shared:323 - proc proc rw
603 725 0:47 /sys /proc/sys ro,nosuid,nodev,noexec,relatime shared:323 - proc proc rw
604 725 0:44 /systemd/inaccessible/reg /proc/kallsyms ro,nosuid,nodev,noexec shared:305 - tmpfs tmpfs rw,seclabel,mode=755
605 725 0:44 /systemd/inaccessible/reg /proc/kcore ro,nosuid,nodev,noexec shared:305 - tmpfs tmpfs rw,seclabel,mode=755
606 725 0:44 /systemd/inaccessible/reg /proc/keys ro,nosuid,nodev,noexec shared:305 - tmpfs tmpfs rw,seclabel,mode=755
607 725 0:44 /systemd/inaccessible/reg /proc/sysrq-trigger ro,nosuid,nodev,noexec shared:305 - tmpfs tmpfs rw,seclabel,mode=755
608 725 0:44 /systemd/inaccessible/reg /proc/timer_list ro,nosuid,nodev,noexec shared:305 - tmpfs tmpfs rw,seclabel,mode=755
609 725 0:47 /bus /proc/bus ro,nosuid,nodev,noexec,relatime shared:323 - proc proc rw
610 725 0:47 /fs /proc/fs ro,nosuid,nodev,noexec,relatime shared:323 - proc proc rw
611 725 0:47 /irq /proc/irq ro,nosuid,nodev,noexec,relatime shared:323 - proc proc rw
612 725 0:47 /scsi /proc/scsi ro,nosuid,nodev,noexec,relatime shared:323 - proc proc rw
613 703 0:46 / /dev/mqueue rw,nosuid,nodev,noexec,relatime shared:324 - mqueue mqueue rw,seclabel
614 701 0:26 / /sys/fs/cgroup rw,nosuid,nodev,noexec,relatime shared:325 - cgroup2 cgroup rw,seclabel,nsdelegate
615 603 0:44 /.#proc-sys-kernel-random-boot-id4fbdce67af46d1c2//deleted /proc/sys/kernel/random/boot_id ro,nosuid,nodev,noexec shared:305 - tmpfs tmpfs rw,seclabel,mode=755
616 725 0:44 /.#proc-sys-kernel-random-boot-id4fbdce67af46d1c2//deleted /proc/sys/kernel/random/boot_id rw,nosuid,nodev shared:305 - tmpfs tmpfs rw,seclabel,mode=755
617 725 0:44 /.#proc-kmsg5b7a8bcfe6717139//deleted /proc/kmsg rw,nosuid,nodev shared:305 - tmpfs tmpfs rw,seclabel,mode=755

The test process does
name_to_handle_at("/proc/filesystems") which returns -EOPNOTSUPP, and then
openat(AT_FDCWD, "/proc/filesystems") which returns 4, and then
read(open("/proc/self/fdinfo/4", ...)) which gives
"pos:\t0\nflags:\t012100000\nmnt_id:\t725\n"

and the "725" is clearly inconsistent with "700" in /proc/self/mountinfo.

We could either drop the fallback path (and fail name_to_handle_at() is not
avaliable) or ignore the error in the test. Not sure what is better. I think
this issue only occurs sometimes and with older kernels, so probably continuing
with the current flaky implementation is better than ripping out the fallback.

Another strace:
writev(2</dev/pts/0>, [{iov_base="mnt ids of /proc/sys is 603", iov_len=27}, {iov_base="\n", iov_len=1}], 2mnt ids of /proc/sys is 603
) = 28
name_to_handle_at(AT_FDCWD, "/", {handle_bytes=128 => 12, handle_type=129, f_handle=0x52748401000000008b93e20d}, [697], 0) = 0
writev(2</dev/pts/0>, [{iov_base="mnt ids of / is 697", iov_len=19}, {iov_base="\n", iov_len=1}], 2mnt ids of / is 697
) = 20
name_to_handle_at(AT_FDCWD, "/proc/kcore", {handle_bytes=128 => 12, handle_type=1, f_handle=0x92ddcfcd2e802d0100000000}, [605], 0) = 0
writev(2</dev/pts/0>, [{iov_base="mnt ids of /proc/kcore is 605", iov_len=29}, {iov_base="\n", iov_len=1}], 2mnt ids of /proc/kcore is 605
) = 30
name_to_handle_at(AT_FDCWD, "/dev", {handle_bytes=128 => 12, handle_type=1, f_handle=0x8ae269160c802d0100000000}, [703], 0) = 0
writev(2</dev/pts/0>, [{iov_base="mnt ids of /dev is 703", iov_len=22}, {iov_base="\n", iov_len=1}], 2mnt ids of /dev is 703
) = 23
name_to_handle_at(AT_FDCWD, "/proc/filesystems", {handle_bytes=128}, 0x7fffe36ddb84, 0) = -1 EOPNOTSUPP (Operation not supported)
openat(AT_FDCWD, "/proc/filesystems", O_RDONLY|O_NOFOLLOW|O_CLOEXEC|O_PATH) = 4</proc/filesystems>
openat(AT_FDCWD, "/proc/self/fdinfo/4", O_RDONLY|O_CLOEXEC) = 5</proc/20/fdinfo/4>
fstat(5</proc/20/fdinfo/4>, {st_mode=S_IFREG|0400, st_size=0, ...}) = 0
fstat(5</proc/20/fdinfo/4>, {st_mode=S_IFREG|0400, st_size=0, ...}) = 0
read(5</proc/20/fdinfo/4>, "pos:\t0\nflags:\t012100000\nmnt_id:\t725\n", 2048) = 36
read(5</proc/20/fdinfo/4>, "", 1024)    = 0
close(5</proc/20/fdinfo/4>)             = 0
close(4</proc/filesystems>)             = 0
writev(2</dev/pts/0>, [{iov_base="mnt ids of /proc/filesystems are 700, 725", iov_len=41}, {iov_base="\n", iov_len=1}], 2mnt ids of /proc/filesystems are 700, 725
) = 42
writev(2</dev/pts/0>, [{iov_base="the other path for mnt id 725 is /proc", iov_len=38}, {iov_base="\n", iov_len=1}], 2the other path for mnt id 725 is /proc
) = 39
writev(2</dev/pts/0>, [{iov_base="Assertion 'path_equal(p, t)' failed at src/test/test-mountpoint-util.c:94, function test_mnt_id(). Aborting.", iov_len=108}, {iov_base="\n", iov_len=1}], 2Assertion 'path_equal(p, t)' failed at src/test/test-mountpoint-util.c:94, function test_mnt_id(). Aborting.
) = 109
rt_sigprocmask(SIG_UNBLOCK, [ABRT], NULL, 8) = 0
rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
getpid()                                = 20
gettid()                                = 20
tgkill(20, 20, SIGABRT)                 = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0

Resolves: #1910425

4 years agoset core ulimit to 0 like on RHEL-7
David Tardon [Mon, 25 Jan 2021 15:19:56 +0000 (16:19 +0100)]
set core ulimit to 0 like on RHEL-7

RHEL-only

Resolves: #1905582

4 years agorc-local: order after network-online.target
David Tardon [Thu, 11 Mar 2021 14:48:23 +0000 (15:48 +0100)]
rc-local: order after network-online.target

I think this was the intent of commit 91b684c7300879a8d2006038f7d9185d92c3c3bf,
just network-online.target didn't exist back then.

RHEL-only

Resolves: #1934028

4 years agocore: Detect initial timer state from serialized data
Michal Koutný [Fri, 2 Nov 2018 19:56:08 +0000 (20:56 +0100)]
core: Detect initial timer state from serialized data

We keep a mark whether a single-shot timer was triggered in the caller's
variable initial. When such a timer elapses while we are
serializing/deserializing the inner state, we consider the timer
incorrectly as elapsed and don't trigger it later.

This patch exploits last_trigger timestamp that we already serialize,
hence we can eliminate the argument initial completely.

A reproducer for OnBootSec= timers:
        cat >repro.c <<EOD
        /*
         * Compile: gcc repro.c -o repro
         * Run: ./repro
         */
        #include <errno.h>
        #include <fcntl.h>
        #include <stdio.h>
        #include <stdlib.h>
        #include <sys/stat.h>
        #include <sys/types.h>
        #include <time.h>
        #include <unistd.h>

        int main(int argc, char *argv[]) {
         char command[1024];
         int pause;

         struct timespec now;

         while (1) {
         usleep(rand() % 200000); // prevent periodic repeats
                clock_gettime(CLOCK_MONOTONIC, &now);
         printf("%i\n", now.tv_sec);

         system("rm -f $PWD/mark");
         snprintf(command, 1024, "systemd-run --user --on-boot=%i --timer-property=AccuracySec=100ms "
         "touch $PWD/mark", now.tv_sec + 1);
         system(command);
         system("systemctl --user list-timers");
         pause = (1000000000 - now.tv_nsec)/1000 - 70000; // fiddle to hit the middle of reloading
         usleep(pause > 0 ? pause : 0);
         system("systemctl --user daemon-reload");
         sync();
         sleep(2);
         if (open("./mark", 0) < 0)
         if (errno == ENOENT) {
         printf("mark file does not exist\n");
         break;
         }
         }

         return 0;
        }
        EOD

(cherry picked from commit aa1f95d2647197eca84c33a0f10adaeada08467d)

Resolves: #1899402

4 years agocore: don't drop timer expired but not yet processed when system date is changed
Insun [Sun, 28 Oct 2018 12:26:13 +0000 (21:26 +0900)]
core: don't drop timer expired but not yet processed when system date is changed

There is difference between time set by the user and real elapsed time because of accuracy feature.
If you change the system date(or time) between these times, the timer drops.

You can easily reproduce it with the following command.
-----------------------------------------------------------
$ systemd-run --on-active=3s ls; sleep 3; date -s "`date`"
-----------------------------------------------------------

In the following command, the problem is rarely reproduced. But it exists.
---------------------------------------------------------------------------------------------
$ systemd-run --on-active=3s --timer-property=AccuracySec=1us ls ; sleep 1; date -s "`date`"
---------------------------------------------------------------------------------------------

Note : Global AccuracySec value.
----------------------------------------------------------------------
$ cat /etc/systemd/system.conf
DefaultTimerAccuracySec=1min
----------------------------------------------------------------------

(cherry picked from commit fee04d7f3ab810e99b97535ca5fda2f9517acda9)

Related: #1899402

4 years agosysctl: set kernel.core_pipe_limit=16
Lennart Poettering [Mon, 12 Oct 2020 14:31:42 +0000 (16:31 +0200)]
sysctl: set kernel.core_pipe_limit=16

We need to make sure that our coredump pattern handler manages to read
process metadata from /proc/$PID/ before the kernel reaps the crashed
process. By default the kernel will reap the process as soon as it can.
By setting kernel.core_pipe_limit to a non-zero the kernel will wait for
userspace to finish before reaping.

We'll set the value to 16, which allows 16 crashes to be
processed in parallel. This matches the MaxConnections= setting in
systemd-coredump.socket.

See: #17301

(This doesn't close 17301, since we probably should also gracefully
handle if /proc/$PID/ vanished already while our coredump handler runs,
just in case people loclly set the sysctl back to zero. i.e. we should
collect what we can and rather issue an incomplete log record than
none.)

(cherry picked from commit 2a9b9323cd844baae3229e9dba67e478bee70654)

Resolves: #1949729

4 years agoceph is a network filesystem
Jonas Jelten [Thu, 17 Oct 2019 10:10:13 +0000 (12:10 +0200)]
ceph is a network filesystem

(cherry picked from commit c4742de6d801b125abf3c4d1c710280f51d7c701)

Resolves: #1952013

4 years agotest-install-root: add test for unknown WantedBy= target
David Tardon [Wed, 31 Mar 2021 08:38:00 +0000 (10:38 +0200)]
test-install-root: add test for unknown WantedBy= target

(cherry picked from commit 8adbad370f522831dd9246fe272caf37ce748d4a)

Related: #1835351

4 years agoinstall: warn if WantedBy targets don't exist
Jan Synacek [Wed, 3 Jun 2020 08:33:21 +0000 (10:33 +0200)]
install: warn if WantedBy targets don't exist

Currently, if [Install] section contains WantedBy=target that doesn't exist,
systemd creates the symlinks anyway. That is just user-unfriendly.
Let's be nice and warn about installing non-existent targets.

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

Replaces: #15834
(cherry picked from commit 8ae27441c2dcf585f58242991302b09778d4d710)

Resolves: #1835351

4 years agotest-install-root: create referenced targets
David Tardon [Wed, 31 Mar 2021 08:08:31 +0000 (10:08 +0200)]
test-install-root: create referenced targets

(cherry picked from commit cd228002ccedb927b4531a4b7dd9ea7015fdb657)

Related: #1835351

4 years agomount-util: use UMOUNT_NOFOLLOW in recursive umounter
Lennart Poettering [Sat, 27 Jun 2020 09:13:01 +0000 (11:13 +0200)]
mount-util: use UMOUNT_NOFOLLOW in recursive umounter

When we only want to unmount mount points below some path then it is
against our interest to follow symlinks. Hence don't.

(cherry picked from commit 827ea5212507c3833b6ae14cdf65e446b36b5e05)

Related: #1885143

4 years agomount-util: bind_remount: avoid calling statvfs
Jakob Unterwurzacher [Mon, 30 Nov 2020 09:27:48 +0000 (10:27 +0100)]
mount-util: bind_remount: avoid calling statvfs

The commit
"util: Do not clear parent mount flags when setting up namespaces"
introduced a statvfs call read the flags of the original mount
and have them applied to the bind mount.

This has two problems:

(1) The mount flags returned by statvfs(2) do not match the flags
accepted by mount(2). For example, the value 4096 means ST_RELATIME
when returned by statvfs(2), but means MS_BIND when passed to mount(2).

(2) A call to statvfs blocks indefinitely when ran against a disconnected
network drive ( https://github.com/systemd/systemd/issues/12667 ).

We already use libmount to parse `/proc/self/mountinfo` but did not use the
mount flag information from there. This patch changes that to use the mount
flags parsed by libmount instead of calling statvfs. Only if getting the
flags through libmount fails we call statvfs.

Fixes https://github.com/systemd/systemd/issues/12667

(cherry picked from commit d34a40082db3ffca8de66bfa4df50951101bdae5)

Resolves: #1885143

4 years agoshared/mount-util: convert to libmount
Zbigniew Jędrzejewski-Szmek [Mon, 30 Nov 2020 09:37:06 +0000 (10:37 +0100)]
shared/mount-util: convert to libmount

It seems better to use just a single parsing algorithm for /proc/self/mountinfo.

Also, unify the naming of variables in all places that use mnt_table_next_fs().
It makes it easier to compare the different call sites.

(cherry picked from commit 13dcfe4661b467131c943620d0f44711798bfd54)

Related: #1885143

4 years agobasic/cap-list: parse/print numerical capabilities
Zbigniew Jędrzejewski-Szmek [Thu, 9 Jul 2020 21:15:47 +0000 (23:15 +0200)]
basic/cap-list: parse/print numerical capabilities

We would refuse to print capabilities which were didn't have a name
for. The kernel adds new capabilities from time to time, most recently
cap_bpf. 'systmectl show -p CapabilityBoundingSet ...' would fail with
"Failed to parse bus message: Invalid argument" because
capability_set_to_string_alloc() would fail with -EINVAL. So let's
print such capabilities in hexadecimal:

CapabilityBoundingSet=cap_chown cap_dac_override cap_dac_read_search
  cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap
  cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin
  cap_net_raw cap_ipc_lock cap_ipc_owner 0x10 0x11 0x12 0x13 0x14 0x15 0x16
  0x17 0x18 0x19 0x1a ...

For symmetry, also allow capabilities that we don't know to be specified.

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

(cherry picked from commit 417770f3033c426ca848b158d0bf057cd8ad1329)

Resolves: #1946943

4 years agobusctl: add a timestamp to the output of the busctl monitor command
d032747 [Tue, 15 Dec 2020 09:40:06 +0000 (10:40 +0100)]
busctl: add a timestamp to the output of the busctl monitor command

(cherry picked from commit 6fe2a70b9160e35fdeed9d37bd31727c2d46a8b2)

Resolves: #1909214

4 years agoman: document differences in clean exit status for Type=oneshot
David Tardon [Fri, 19 Mar 2021 09:05:47 +0000 (10:05 +0100)]
man: document differences in clean exit status for Type=oneshot

See commit 1f0958f640b87175cd547c1e69084cfe54a22e9d .

(cherry picked from commit f055cf77862bc580f3afbfaac161d1c060f39411)

Resolves: #1940078

4 years agobasic/virt: Detect PowerVM hypervisor
Michal Suchanek [Fri, 2 Oct 2020 09:05:23 +0000 (11:05 +0200)]
basic/virt: Detect PowerVM hypervisor

Currently systemd-detect-virt fails to detect running under PowerVM.

Add code to detect PowerVM based on code in util-linux.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
(cherry picked from commit 3224e38bb6b3287ca253cbafb460a150544d5818)

Resolves: #1937989

4 years agoshared/install: Preserve escape characters for escaped unit names
David Michael [Wed, 20 Mar 2019 15:14:32 +0000 (15:14 +0000)]
shared/install: Preserve escape characters for escaped unit names

Since switching to extract_first_word with no flags for parsing
unit names in 4c9565eea534cd233a913c8c21f7920dba229743, escape
characters will be stripped from escaped unit names such as
"mnt-persistent\x2dvolume.mount" resulting in the unit not being
configured as defined.  Preserve escape characters again for
compatibility with existing preset definitions.

(cherry picked from commit 82bd4da71e9cdd5a2e9266332f5a7399845e31f6)

Resolves: #1952686

4 years agouser-runtime-dir: downgrade a few log messages to LOG_DEBUG that we ignore
Lennart Poettering [Thu, 2 Aug 2018 18:56:34 +0000 (20:56 +0200)]
user-runtime-dir: downgrade a few log messages to LOG_DEBUG that we ignore

As the comments already say it might be quite likely that
$XDG_RUNTIME_DIR is not set up as mount, and we shouldn't complain about
that.

Moreover, let's make this idempotent, so that a runtime dir that is
already gone and is removed again doesn't cause failure.

(cherry picked from commit 3a13442bbf72e7ebdd0b4d60c2922ea7c5cc9496)

Related: #1946453

4 years agounits: make sure user-runtime-dir@.service is Type=oneshot
Lennart Poettering [Thu, 2 Aug 2018 18:57:56 +0000 (20:57 +0200)]
units: make sure user-runtime-dir@.service is Type=oneshot

We order user@.service after it, hence we need to properly know when it
finished starting up.

(cherry picked from commit d06e8fbce35c2b52ee1d09af4888876d5f2d7ae4)

Related: #1946453

4 years agounits: order user-runtime-dir@.service after systemd-user-sessions.service
Lennart Poettering [Fri, 3 Aug 2018 08:42:09 +0000 (10:42 +0200)]
units: order user-runtime-dir@.service after systemd-user-sessions.service

We use systemd-user-sessions.service as barrier when to allow login
sessions. With this patch user@.service is ordered after that too, so
that any login related code (which user-runtime-dir@.service is) is
guaranteed to run after the barrier, and never before.

(cherry picked from commit eb748aef4fbfd03b64938aa471bb8ceda1bc89a8)

Related: #1946453

4 years agounits: assign user-runtime-dir@.service to user-%i.slice
Lennart Poettering [Fri, 3 Aug 2018 08:45:31 +0000 (10:45 +0200)]
units: assign user-runtime-dir@.service to user-%i.slice

This service won't use much resources, but it's certainly nicer to see
it attached th the user's slice along with user@.service, so that
everything we run for a specific user is properly bound into one unit.

(cherry picked from commit 1193c11a04b3ecc29925904fbeb5d64834bce73e)

Related: #1946453

4 years agoinitrd: do a debug log if /etc/initrd-release doesn't take effect
Kairui Song [Wed, 13 Jan 2021 17:25:20 +0000 (01:25 +0800)]
initrd: do a debug log if /etc/initrd-release doesn't take effect

Signed-off-by: Kairui Song <kasong@redhat.com>
(cherry picked from commit 4a60d8cbcae574896a28f9f1f6204a1bddca8e99)

Related: #1959339

4 years agoinitrd: do a debug log if failed to detect rootfs type
Kairui Song [Wed, 13 Jan 2021 16:39:10 +0000 (00:39 +0800)]
initrd: do a debug log if failed to detect rootfs type

(cherry picked from commit 3377c740d9121f38385e70d6a380b5e4bd8c672a)

Related: #1959339

4 years agoinitrd: extend SYSTEMD_IN_INITRD to accept non-ramfs rootfs
Kairui Song [Tue, 12 Jan 2021 16:04:53 +0000 (00:04 +0800)]
initrd: extend SYSTEMD_IN_INITRD to accept non-ramfs rootfs

Sometimes, non-ramfs initrd root are useful. Eg, for kdump, because
initramfs is memory consuming, so mount a compressed image in earlier
initrd, chroot into it then let systemd do the rest of job is a good
solution.

But systemd doesn't recognize the initrd environment if rootfs is not a
temporary fs. This is a reasonable check, because switch-root in initrd
will wipe the whole rootfs, will be a disaster if there are any
misdetect.

So extend SYSTEMD_IN_INITRD environment variable, now it accepts boolean
value and two extra keyword, "auto" and "lenient". "auto" is same as
before, and it's the default value. "lenient" will let systemd bypass
the rootfs check.

(cherry picked from commit db4c45cf4f10ca094b9e9570b758abd445d65381)

Related: #1959339

4 years agoutil: rework in_initrd() to make use of path_is_temporary_fs()
Kairui Song [Fri, 8 Jan 2021 06:52:26 +0000 (14:52 +0800)]
util: rework in_initrd() to make use of path_is_temporary_fs()

(cherry picked from commit 96cceb35e7985f5ee6c9b17e129a76259273cdde)

Related: #1959339

4 years agocore: Hide "Deactivated successfully" message
Jan Macku [Thu, 27 May 2021 10:25:51 +0000 (12:25 +0200)]
core: Hide "Deactivated successfully" message

Show message "Deactivated successfully" in debug mode (when manager is
user) rather than in info mode. This message has low information value
for regular users and it might be a bit overwhelming on a system with
a lot of devices.

(cherry picked from commit edf2ee22f54005d76b2fb8fdcc9c60974feb88bc)

Resolves: #1954802

4 years agocopy: handle copy_file_range() weirdness on procfs/sysfs
Lennart Poettering [Fri, 26 Feb 2021 09:25:24 +0000 (10:25 +0100)]
copy: handle copy_file_range() weirdness on procfs/sysfs

This addresses the issue described in https://lwn.net/Articles/846403/
and makes sure we will be able to stream bytes from procfs/sysfs via
copy_bytes() if people ask us to.

Based on: ee1aa61c4710ae567a2b844e0f0bb8cb0456ab8c
Related: #1970860

4 years agomeson: remove strange dep that causes meson to enter infinite loop
Zbigniew Jędrzejewski-Szmek [Wed, 6 Nov 2019 11:44:39 +0000 (12:44 +0100)]
meson: remove strange dep that causes meson to enter infinite loop

The value is obviously bogus, but didn't seem to cause problems so far.
With meson-0.52.0, it causes a hang. The number of aliases is always rather
small (usually just one or two, possibly up to a dozen in a few cases), so
even if this causes some looping, it is strange that it has such a huge impact.
But let's just remove it.

Fixes #13742.

Tested with meson-0.52.0-1.module_f31+6771+f5d842eb.noarch,
meson-0.51.1-1.fc29.noarch.

(cherry picked from commit af336643a01d0b210b18312c253a50594ba54b0a)

Resolves: #1970860

4 years agoseccomp: allow turning off of seccomp filtering via env var
Lennart Poettering [Mon, 2 Nov 2020 13:51:10 +0000 (14:51 +0100)]
seccomp: allow turning off of seccomp filtering via env var

Fixes: #17504

(While we are it, also move $SYSTEMD_SECCOMP_LOG= env var description
into the right document section)

Also suggested in: https://github.com/systemd/systemd/issues/17245#issuecomment-704773603

(cherry picked from commit ce8f6d478e3f6c6a313fb19615aa5029bb18f86d)

Resolves: #1916835

4 years agocgroup: Also set io.bfq.weight
Kai Krakow [Sat, 17 Aug 2019 00:33:43 +0000 (02:33 +0200)]
cgroup: Also set io.bfq.weight

Current kernels with BFQ scheduler do not yet set their IO weight
through "io.weight" but through "io.bfq.weight" (using a slightly
different interface supporting only default weights, not per-device
weights). This commit enables "IOWeight=" to just to that.

This patch may be dropped at some time later.

Link: https://github.com/systemd/systemd/issues/7057
Signed-off-by: Kai Krakow <kai@kaishome.de>
(cherry picked from commit 21221ce1ce9a572e82d46d80692afd65c224fc50)

Related: #1927290

4 years agotest/udev-test.pl: drop test cases that add mutliple devices v239-46 v239-47
Michal Sekletar [Mon, 17 May 2021 13:54:10 +0000 (15:54 +0200)]
test/udev-test.pl: drop test cases that add mutliple devices

[msekleta: It is easier to delete test-cases that would make
udev test fail. Once we reintroduce the fix for link_update()
we will revert this commit.]

Related: #1942299

4 years agoRevert "udev: make algorithm that selects highest priority devlink less susceptible...
Michal Sekletar [Mon, 17 May 2021 13:50:31 +0000 (15:50 +0200)]
Revert "udev: make algorithm that selects highest priority devlink less susceptible to race conditions"

This reverts commit 1d5f966c1758eb620755fcae54abd07a1ac36d3d.

Related: #1942299

4 years agoRevert "udev: run link_update() with increased retry count in second invocation"
Michal Sekletar [Mon, 17 May 2021 13:49:08 +0000 (15:49 +0200)]
Revert "udev: run link_update() with increased retry count in second invocation"

This reverts commit 1f3165bda13c8572c8c31d23c998835c4e2ad8f3.

Related: #1942299

4 years agopam-systemd: use secure_getenv() rather than getenv() v239-45
Lennart Poettering [Mon, 4 Feb 2019 09:23:43 +0000 (10:23 +0100)]
pam-systemd: use secure_getenv() rather than getenv()

And explain why in a comment.

(cherry picked from commit 83d4ab55336ff8a0643c6aa627b31e351a24040a)

CVE-2019-3842

Resolves: #1687514

4 years agoudev: run link_update() with increased retry count in second invocation
Michal Sekletar [Thu, 4 Mar 2021 16:35:22 +0000 (17:35 +0100)]
udev: run link_update() with increased retry count in second invocation

In PR #17431 we have introduced retry loop in link_update() in order to
maximize the chance that we end up with correct target when there are
multiple contenders for given symlink.

Number of iterations in retry loop is either 1 or
LINK_UPDATE_MAX_RETRIES, depending on the value of 'initialized' db
flag. When device appears for the first time we need to set the
flag before calling link_update() via update_devnode() for the second
time to make sure we run the second invocation with higher retry loop
counter.

(cherry picked from commit 996c83903da5bf8b371314b4207ff97afeef65a4)

Related: #1931947

4 years agocore: prevent excessive /proc/self/mountinfo parsing
Michal Sekletár [Thu, 9 Jul 2020 16:16:44 +0000 (18:16 +0200)]
core: prevent excessive /proc/self/mountinfo parsing

(cherry picked from commit d586f642fd90e3bb378f7b6d3e3a64a753e51756)

Resolves: #1819868

4 years agotest: add ratelimiting test
Michal Sekletár [Mon, 23 Nov 2020 17:04:57 +0000 (18:04 +0100)]
test: add ratelimiting test

(Taken from Michal's #17274 by Lennart, and slightly adjusted)

(cherry picked from commit 68d890651781904a4c762ac866af36e30c4f7ff8)

Related: #1819868

4 years agosd-event: add ability to ratelimit event sources
Lennart Poettering [Mon, 23 Nov 2020 17:02:40 +0000 (18:02 +0100)]
sd-event: add ability to ratelimit event sources

Let's a concept of "rate limiting" to event sources: if specific event
sources fire too often in some time interval temporarily take them
offline, and take them back online once the interval passed.

This is a simple scheme of avoiding starvation of event sources if some
event source fires too often.

This introduces the new conceptual states of "offline" and "online" for
event sources: an event source is "online" only when enabled *and* not
ratelimited, and offline in all other cases. An event source that is
online hence has its fds registered in the epoll, its signals in the
signalfd and so on.

(cherry picked from commit b6d5481b3d9f7c9b1198ab54b54326ec73e855bf)

Related: #1819868

4 years agosd-event: increase n_enabled_child_sources just once
Zbigniew Jędrzejewski-Szmek [Tue, 10 Nov 2020 11:57:34 +0000 (12:57 +0100)]
sd-event: increase n_enabled_child_sources just once

Neither source_child_pidfd_register() nor event_make_signal_data() look at
n_enabled_child_sources.

(cherry picked from commit ac9f2640cb9c107b43f47bba7e068d3b92b5337b)

Related: #1819868

4 years agosd-event: update state at the end in event_source_enable
Zbigniew Jędrzejewski-Szmek [Tue, 10 Nov 2020 09:38:37 +0000 (10:38 +0100)]
sd-event: update state at the end in event_source_enable

Coverity in CID#1435966 was complaining that s->enabled is not "restored" in
all cases. But the code was actually correct, since it should only be
"restored" in the error paths. But let's still make this prettier by not setting
the state before all operations that may fail are done.

We need to set .enabled for the prioq reshuffling operations, so move those down.

No functional change intended.

(cherry picked from commit d2eafe61ca07f8300dc741a0491a914213fa2b6b)

Related: #1819868

4 years agosd-event: remove earliest_index/latest_index into common part of event source objects
Lennart Poettering [Mon, 23 Nov 2020 16:49:27 +0000 (17:49 +0100)]
sd-event: remove earliest_index/latest_index into common part of event source objects

So far we used these fields to organize the earliest/latest timer event
priority queue.  In a follow-up commit we want to introduce ratelimiting
to event sources, at which point we want any kind of event source to be
able to trigger time wakeups, and hence they all need to be included in
the earliest/latest prioqs.  Thus, in preparation let's make this
generic.

No change in behaviour, just some shifting around of struct members from
the type-specific to the generic part.

(cherry picked from commit f41315fceb5208c496145cda2d6c865a5458ce44)

Related: #1819868

4 years agosd-event: follow coding style with naming return parameter
Lennart Poettering [Mon, 23 Nov 2020 16:47:16 +0000 (17:47 +0100)]
sd-event: follow coding style with naming return parameter

(cherry picked from commit cad143a8f26976a23e634d5e1ecfb7d7ba75c3bf)

Related: #1819868

4 years agosd-event: ref event loop while in sd_event_prepare() ot sd_event_run()
Lennart Poettering [Mon, 23 Nov 2020 14:38:00 +0000 (15:38 +0100)]
sd-event: ref event loop while in sd_event_prepare() ot sd_event_run()

sd_event_prepare() invokes callbacks that might drop the last user ref
on our event loop. Let's make sure we keep an explicit ref around it, so
that we won't end up with an invalid pointer. Similar in sd_event_run().

Basically, any function that is publically callable that might end up
invoking callbacks should ref the relevant objects to be protected
against callbacks destroying these objects while we still want to access
them. We did this correctly in sd_event_dispatch() and sd_event_loop(),
but these are not the only ones which are callable from the outside.

(cherry picked from commit f814c871e65df8552a055dd887bc94b074037833)

Related: #1819868

4 years agosd-event: refuse running default event loops in any other thread than the one they...
Lennart Poettering [Wed, 30 Oct 2019 19:26:50 +0000 (20:26 +0100)]
sd-event: refuse running default event loops in any other thread than the one they are default for

(cherry picked from commit e544601536ac13a288d7476f4400c7b0f22b7ea1)

Related: #1819868

4 years agosd-event: let's suffix last_run/last_log with "_usec"
Lennart Poettering [Mon, 23 Nov 2020 14:33:50 +0000 (15:33 +0100)]
sd-event: let's suffix last_run/last_log with "_usec"

Otherwise it's a bit confusing what this is about: two timestamps.

(cherry picked from commit e6a7bee538f6638c2d5ca2afc66bf47cba3f075c)

Related: #1819868

4 years agosd-event: fix delays assert brain-o (#17790)
Vito Caputo [Tue, 1 Dec 2020 08:26:54 +0000 (00:26 -0800)]
sd-event: fix delays assert brain-o (#17790)

s/sizeof/ELEMENTSOF/

Bug introduced in 34b87517749caa4142b19eb3c63bdf349fafbc49.

(cherry picked from commit cb9d621ebbfa30bbd620c17e143daeb0d78c12f0)

Related: #1819868

4 years agosd-event: split out code to add/remove timer event sources to earliest/latest prioq
Lennart Poettering [Mon, 23 Nov 2020 14:25:35 +0000 (15:25 +0100)]
sd-event: split out code to add/remove timer event sources to earliest/latest prioq

Just some refactoring that makes code prettier, and will come handy
later, because we can reuse these functions at more places.

(cherry picked from commit 1e45e3fecc303e7ae9946220c742f69675e99c34)

Related: #1819868

4 years agosd-event: split clock data allocation out of sd_event_add_time()
Lennart Poettering [Mon, 23 Nov 2020 10:40:24 +0000 (11:40 +0100)]
sd-event: split clock data allocation out of sd_event_add_time()

Just some simple refactoring, that will make things easier for us later.
But it looks better this way even without the later function reuse.

(cherry picked from commit 41c63f36c3352af8bebf03b6181f5d866431d0af)

Related: #1819868

4 years agosd-event: mention that two debug logged events are ignored
Lennart Poettering [Mon, 23 Nov 2020 10:39:40 +0000 (11:39 +0100)]
sd-event: mention that two debug logged events are ignored

(cherry picked from commit f80a5d6a86dc2346f406ee086ba179879afaab70)

Related: #1819868

4 years agosd-event: split out enable and disable codepaths from sd_event_source_set_enabled()
Lennart Poettering [Fri, 23 Oct 2020 19:21:58 +0000 (21:21 +0200)]
sd-event: split out enable and disable codepaths from sd_event_source_set_enabled()

So far half of sd_event_source_set_enabled() was doing enabling, the
other half was doing disabling. Let's split that into two separate
calls.

(This also adds a new shortcut to sd_event_source_set_enabled(): if the
caller toggles between "ON" and "ONESHOT" we'll now shortcut this, since
the event source is already enabled in that case and shall remain
enabled.)

This heavily borrows and is inspired from Michal Sekletár's #17284
refactoring.

(cherry picked from commit ddfde737b546c17e54182028153aa7f7e78804e3)

Related: #1819868

4 years agosd-event: split out helper functions for reshuffling prioqs
Michal Sekletár [Fri, 23 Oct 2020 16:29:27 +0000 (18:29 +0200)]
sd-event: split out helper functions for reshuffling prioqs

We typically don't just reshuffle a single prioq at once, but always
two. Let's add two helper functions that do this, and reuse them
everywhere.

(Note that this drops one minor optimization:
sd_event_source_set_time_accuracy() previously only reshuffled the
"latest" prioq, since changing the accuracy has no effect on the
earliest time of an event source, just the latest time an event source
can run. This optimization is removed to simplify things, given that
it's not really worth the effort as prioq_reshuffle() on properly
ordered prioqs has practically zero cost O(1)).

(Slightly generalized, commented and split out of #17284 by Lennart)

(cherry picked from commit e1951c16a8fbe5b0b9ecc08f4f835a806059d28f)

Related: #1819868

4 years agotest/sys-script.py: add missing DEVNAME entries to uevents
Martin Wilck [Tue, 24 Apr 2018 19:40:23 +0000 (21:40 +0200)]
test/sys-script.py: add missing DEVNAME entries to uevents

Resolves: #1931947

4 years agoRevert "test: add test cases for empty string match" and "test: add test case for...
Michal Sekletar [Tue, 2 Mar 2021 17:57:59 +0000 (12:57 -0500)]
Revert "test: add test cases for empty string match" and "test: add test case for multi matches when use ||"

This effectively reverts commits 03bc565e6e3249385c4e1ca0ae27670ca2ad9a41
and 03b766cc937ffa4dcb7cfb25b2ac20d8a00cb6db.

Resolves: #1931947

4 years agotest/udev-test: gracefully exit when imports fail v239-44
Zbigniew Jędrzejewski-Szmek [Tue, 17 Nov 2020 16:13:31 +0000 (17:13 +0100)]
test/udev-test: gracefully exit when imports fail

In Fedora rawhide various perl modules are now available as separate
packages that are not pulled in by dependencies. If we don't have some
package, skip the tests.

This ugly code is apparently the way to do conditional imports:
https://www.cs.ait.ac.th/~on/O/oreilly/perl/cookbook/ch12_03.htm.

(cherry picked from commit d40763838278246e2073d15ca927ee700e583afc)

Related: #1642728

4 years agotest/udev_test.pl: add "expected good" count
Martin Wilck [Thu, 26 Apr 2018 12:07:27 +0000 (14:07 +0200)]
test/udev_test.pl: add "expected good" count

Since 'test/udev-test.pl: count "good" results', we know how many
checks succeeded. Add an "expected good" count to make that number
more meaningful.

(cherry picked from commit cbeb23d863d540408cd1fb274d78213f59639df2)

Related: #1642728

4 years agotest/udev-test.pl: suppress umount error message at startup
Martin Wilck [Thu, 26 Apr 2018 11:25:11 +0000 (13:25 +0200)]
test/udev-test.pl: suppress umount error message at startup

umount emits an error message "no mount point specified" if the
tmpfs isn't mounted yet, which is the normal case.
Suppress that by redirecting stderr.

(cherry picked from commit f1cb0860549e775be5f91237b5a3b97698dd14dd)

Related: #1642728

4 years agotest/udev-test.pl: generator for large list of block devices
Martin Wilck [Wed, 25 Apr 2018 07:54:26 +0000 (09:54 +0200)]
test/udev-test.pl: generator for large list of block devices

Manually listing all devices in the test definition becomes cumbersome with
lots of devices. Add a function that scans on all block devices in
the test sysfs and generates a list of devices to test.

(cherry picked from commit eb44d715ebee2fe11288433b99f8e1dc5fdac84a)

Related: #1642728

4 years agotest/udev-test.pl: add repeat count
Martin Wilck [Tue, 24 Apr 2018 20:24:43 +0000 (22:24 +0200)]
test/udev-test.pl: add repeat count

for easier reproduction of sporadic test failures.

(cherry picked from commit 2ab0a8d00bc48d3531e953d938db889d8a932d65)

Related: #1642728

4 years agotests/udev-test.pl: add multiple device test
Martin Wilck [Tue, 24 Apr 2018 20:04:55 +0000 (22:04 +0200)]
tests/udev-test.pl: add multiple device test

Add 4 new tests using multiple devices. Number 2-4 use many
devices claiming the same symlink, where only one device has
a higher priority thatn the others. They fail sporadically with
the current code, if a race condition causes the symlink to point
to the wrong device. Test 4 is like test 2 with sleeps in between,
it's much less likely to fail.

(cherry picked from commit 4a0ec82daf32446519e1d86329bb802325b82104)

Related: #1642728

4 years agotest/udev-test.pl: count "good" results
Martin Wilck [Tue, 24 Apr 2018 18:55:01 +0000 (20:55 +0200)]
test/udev-test.pl: count "good" results

This is helpful to catch possible regressions in the test.
Also, don't count wait() errors, they are likely not udev errors.

(cherry picked from commit b95c43982ab7d0253b552ad56cffb3d68fcbb4f6)

Related: #1642728

4 years agotest/udev-test.pl: merge import parent tests into one
Martin Wilck [Tue, 24 Apr 2018 16:30:09 +0000 (18:30 +0200)]
test/udev-test.pl: merge import parent tests into one

As we can test multiple devices and multiple links per device
in one test now, these two tests can be merged into one.

(cherry picked from commit a96cd21d31cb7af211862768e133b50b085634e7)

Related: #1642728

4 years agotest/udev-test.pl: merge "space and var with space" tests
Martin Wilck [Tue, 24 Apr 2018 16:27:25 +0000 (18:27 +0200)]
test/udev-test.pl: merge "space and var with space" tests

As we can check multiple links in a single test now, these 3
tests can be merged into one.

(cherry picked from commit 2084fe0d3290c525ecb9faa07d07c3abc2488e59)

Related: #1642728

4 years agotest/udev-test.pl: remove bogus rules from magic subsys test
Martin Wilck [Tue, 24 Apr 2018 16:16:59 +0000 (18:16 +0200)]
test/udev-test.pl: remove bogus rules from magic subsys test

These rules have survived from an ancient version of the code
and save no purpose any more.

(cherry picked from commit 86634df43b715f3f77c7de73a3ef6566e5cdf571)

Related: #1642728

4 years agotest/udev-test.pl: Make some tests a little harder
Martin Wilck [Tue, 24 Apr 2018 16:09:50 +0000 (18:09 +0200)]
test/udev-test.pl: Make some tests a little harder

Add some rules that make it a bit harder to pass, mainly the
non-existence checks.

(cherry picked from commit 06d4d4e24e7d0b51120b165e540d278842e8b1a3)

Related: #1642728

4 years agotest/udev-test.pl: last_rule is unsupported
Martin Wilck [Tue, 24 Apr 2018 16:08:18 +0000 (18:08 +0200)]
test/udev-test.pl: last_rule is unsupported

the "last_rule" option hasn't been supported for some time.
Therefore this test fails if a "not_exp_links" attribute is added,
as it should be. Mark it appropriately.

(cherry picked from commit 17cce031531a5d3f38a27374c99d1bdba5959dbd)

Related: #1642728

4 years agotest/udev-test.pl: fix wrong test descriptions
Martin Wilck [Tue, 24 Apr 2018 15:57:47 +0000 (17:57 +0200)]
test/udev-test.pl: fix wrong test descriptions

udev hasn't supported renaming device nodes for some time.

(cherry picked from commit 46bc71b2b73f8a1e27dc5e142730e9877dd05e3e)

Related: #1642728

4 years agotest/udev-test.pl: allow checking multiple symlinks
Martin Wilck [Tue, 24 Apr 2018 15:15:58 +0000 (17:15 +0200)]
test/udev-test.pl: allow checking multiple symlinks

Instead of testing the existence or non-exisitence of just a single
symlink, allow testing of several links per device.

Change the test definitions accordingly.

(cherry picked from commit e62acc3159935781f05fa59c48e5a74e85c61ce2)

Related: #1642728

4 years agotest/udev-test.pl: test correctness of symlink targets
Martin Wilck [Tue, 24 Apr 2018 08:50:24 +0000 (10:50 +0200)]
test/udev-test.pl: test correctness of symlink targets

Test if symlinks are created correctly by comparing the symlink
targets to the devnode path. This implies (for the symlink) that
major/minor numbers and permissions are correct, as we have tested
that on the devnode already.

(cherry picked from commit 997683c8f152e1c139a7ce537de81a0aeae4627f)

Related: #1642728

4 years agotest/udev-test.pl: use computed devnode name
Martin Wilck [Tue, 24 Apr 2018 07:38:26 +0000 (09:38 +0200)]
test/udev-test.pl: use computed devnode name

More often than not, the created devnode is the basename of the
sysfs entry. The "devnode" device may be used to override the
auto-detected node name.

Permissions and major/minor number are now verified on the devnode
itself, not on symlinks.

For those tests where exp_name is set to the computed devnode name,
the explicit "exp_name" can be removed. "exp_name" is only required for
symlinks.

This allows separate testing for devnodes and symlinks an a follow-up
patch.

(cherry picked from commit f0dccf01a7b4e72278e14effd74782ea83d0a73b)

Related: #1642728

4 years agotest/udev-test.pl: allow concurrent additions and removals
Martin Wilck [Mon, 23 Apr 2018 19:59:05 +0000 (21:59 +0200)]
test/udev-test.pl: allow concurrent additions and removals

Allow testing cases where multiple devices are added and removed
simultaneously. Tests are started as synchronously as possible using a
semaphore, in order to test possible race conditions. If this isn't desired,
the test parameter "sleep_us" can be set to the number of microseconds to wait
between udev invocations.

(cherry picked from commit 09a4062d70b3a10d022e40066e2adf09df05bbbc)

Related: #1642728