Commit Graph
6073 Commits
Author SHA1 Message Date
Lennart Poettering fbe8f6928e capability-util: avoid thread_local
While stracing PID1's forking off of children I noticed that every
single forked off child reads cap_last_cap from procfs. That value is a
kernel constant, hence we can save a lot of work if we'd cache it.

Thing is, we actually do cache it, in a thread_local cache field. This
means that the forked off processes (which are considered new threads)
will have to re-query it, even though we already know the result.

Hence, let's get rid of the thread_local stuff (given that the value is
going to be the same for all threads anyway, and we pretty much have a
single thread only anyway). Use an C11 atomic_int instead, which ensures
the value is either initialized or not initialized, but we don't need to
be concerned of partial initialization.

This makes the cap_last_cap reading go away in the children, as strace
shows (since cap_last_cap() is already called by PID 1 before
fork()ing, anyway).
2024-04-24 17:33:38 +02:00
Yu Watanabe 21ae0b4b3c in-addr-util: introduce in{4,6}_addr_prefix_intersect() 2024-04-24 12:22:05 +09:00
Daan De Meyer 00bc83a275 core: Limit terminal reset using ANSI sequences to /dev/console
Doing this in reset_terminal_fd() is a bit too invasive, see
https://github.com/systemd/systemd/pull/32406#issuecomment-2070923583.

Let's only do this for /dev/console so that we work around weird firmwares
disabling line-wrapping, but avoid messing too much with other things.

While we're at it, let's handle more than just line wrapping, and do a
more general reset of stuff to get the terminal into a sane state.
2024-04-23 15:05:50 +02:00
Daan De Meyer f57705d67d terminal-util: Enable line wrapping in reset_terminal_fd()
The qemu seabios firmware disables serial console line wrapping. Let's
make sure we re-enable it again when we reset a terminal to some sane
defaults.

To avoid potentially blocking on writing to the terminal, we put it
in nonblocking mode and add a timeout of 50ms.
2024-04-22 15:28:26 +02:00
Daan De Meyer e6724664c3 fd-util: Return 1 from fd_nonblock() if we actually change the mode 2024-04-22 15:28:26 +02:00
Daan De Meyer 1b889631ed core: Check for TERM=dumb in show_status()
We shouldn't try to use any ANSI escape sequences if TERM=dumb.
Also, the "\r\n" we output can get interpreted as a double newline
(for example by Github Actions), so let's output just "\n" when
TERM=dumb to clean up the CI logs.
2024-04-22 13:27:27 +02:00
Luca Boccassi c3411932b1 Merge pull request #32389 from keszybz/bin-sbin-merge
Try PATH without sbin even if compiled with split-bin=true
2024-04-22 13:07:48 +02:00
Lennart Poettering b7866fa6aa Merge pull request #31987 from flatcar-hub/krnowak/usr-perm-check
sysext: Fix issues with merged hierarchy mode
2024-04-22 11:14:35 +02:00
Zbigniew Jędrzejewski-Szmek 0f36a4c897 Try path without sbin even if compiled with split-bin=true
I'm working on the transition to merged sbin in Fedora. While the transition is
happening (and probably for a while after), we need to compile systemd with
split-bin=true to support systems upgraded from previous versions. But when the
system has been upgraded and already has /usr/sbin that is a symlink, be nice
and give $PATH without sbin.

We check for both /usr/sbin and /usr/local/sbin. If either exists and is not a
symlink to ./bin, we retain previous behaviour. This means that if both are
converted, we get the same behaviour as split-bin=false, and otherwise we
get the same behaviour as before.

sd-path uses the same logic. This is not a hot path, so I got rid of the nulstr
macros that duplicated the logic.
2024-04-22 09:53:24 +02:00
Daan De Meyer 7a7d7a2e22 test: Don't allocate scope if already running in unit with delegated cgroup
If we're already running in a unit with delegation turned on, let's
skip allocation of a scope unit and cgroup subroot. This allows journald
to correctly attribute the logs of all subprocesses spawned by tests such
as test-execute to the test-execute service when the test is running in a service.
2024-04-22 09:42:29 +02:00
Lennart Poettering cea9216a42 detect-virt: detect hyperv-enlightened qemu as qemu, not as hyperv
CPUID reporting hyperv should be taken with a grain of salt, and we
should prefer other mechanisms then.

Fixes: #28001
2024-04-20 12:10:42 +02:00
Krzesimir Nowak 581d8a1470 path-util: Add a helper for checking paths
The difference with the already existing path_equal_or_inode_same function is
that the new one does not swallow errors.
2024-04-19 08:30:40 +02:00
Matteo Croce 64f7b2961a introduce FOREACH_ELEMENT
Add a FOREACH_ELEMENT() macro which just passes ELEMENTSOF(v)
as third argument to FOREACH_ARRAY().
2024-04-18 17:39:34 +02:00
Yu Watanabe 52fb945cb7 Merge pull request #32318 from YHNdnzj/skip-leading-char
journal-gatewayd: use skip_leading_chars
2024-04-18 06:18:09 +09:00
Lennart Poettering 7e16650d83 Merge pull request #32143 from yuwata/magic
basic/linux: copy magic.h from kernel to our code
2024-04-17 17:03:48 +02:00
Mike Yuan ee0373cb80 journal-gatewayd: use skip_leading_chars where appropriate
Prompted by c5d6754725
2024-04-17 21:50:22 +08:00
Mike Yuan c498b2f7ee string-util: use mempcpy where appropriate 2024-04-17 17:04:23 +08:00
Yu Watanabe d723363a86 string-util: use special_glyph() at one more place
No functional change, just refactoring.
2024-04-17 17:03:49 +08:00
Mike Yuan 58ff2f1e38 core/execute: also check cg_is_threaded for clone3()
Prompted by #32259

We already have this check in exec_invoke(), i.e. child.
But if CLONE_INTO_CGROUP is used, the failure would
occur on parent's side, so do the check there too.
2024-04-14 23:22:13 +08:00
Yu Watanabe 7f5c82aaf3 tree-wide: insert missing space after comma 2024-04-13 05:44:04 +09:00
Yu Watanabe 87bbcb26c8 Merge pull request #32255 from YHNdnzj/strextendf
shared/killall: minor modernization
2024-04-13 05:10:20 +09:00
Mike Yuan dbbc86ffbd string-util: correct comment in strextendf_with_separator 2024-04-13 02:35:01 +08:00
Zbigniew Jędrzejewski-Szmek c71b50179e meson: do not fail build with newer kernel headers
systemd-255 is failing a build with the latest kernel headers… Let's downgrade
this warning, because it's fine if there's a file system we don't know about
and it makes thing less brittle if we don't treat this as a hard error.

(I initially conditionalized this on BUILD_MODE, but I don't think we need a
hard error there either. A warning will be noticed and fixed.)
2024-04-12 11:44:58 +01:00
Yu Watanabe 0a07ee146d meson: use headers in our code base when checking filesystem table
Note, GFS2_MAGIC is also defined in missing_magic.h, so
linux/gfs2_ondisk.h is not necessary anymore.
2024-04-10 06:45:41 +09:00
Yu Watanabe 2c57fcabab basic/missing_magic: drop unnecessary entries and update comments 2024-04-10 06:40:32 +09:00
Yu Watanabe 613da12f9f basic/linux: copy magic.h to our source code tree
Let's import kernel headers into our source code tree.
2024-04-10 06:23:55 +09:00
Yu Watanabe 9ee34b21cc basic/linux: update linux headers
From Linux 6.9-rc3.
2024-04-10 06:23:00 +09:00
Frantisek Sumsal edda10f2ae tree-wide: make sure net/if.h is included before any linux/ header
The linux/ headers include linux/libc-compat.h that makes sure the
linux/ headers won't redeclare symbols already declared by net/if.h, but
glibc's net/if.h doesn't do that, so if the include order is reversed
we'll end up with a bunch of errors about redeclared stuff:

[3/519] Compiling C object test-network-tables.p/src_network_test-network-tables.c.o
FAILED: test-network-tables.p/src_network_test-network-tables.c.o
cc -Itest-network-tables.p -I. -I.. -Isrc/basic -I../src/basic -Isrc/fundamental -I../src/fundamental -Isrc/systemd -I../src/systemd -I../src/libsystemd/sd-bus -I../src/libsystemd/sd-device -I../src/libsystemd/sd-event -I../src/libsystemd/sd-hwdb -I../src/libsystemd/sd-id128 -I../src/libsystemd/sd-journal -I../src/libsystemd/sd-netlink -I../src/libsystemd/sd-network -I../src/libsystemd/sd-resolve -Isrc/shared -I../src/shared -Isrc/libsystemd-network -I../src/libsystemd-network -Isrc/network -I../src/network -I../src/network/netdev -I../src/network/tc -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -std=gnu11 -O0 -g -Wno-missing-field-initializers -Wno-unused-parameter -Wno-nonnull-compare -Warray-bounds -Warray-bounds=2 -Wdate-time -Wendif-labels -Werror=format=2 -Werror=format-signedness -Werror=implicit-function-declaration -Werror=implicit-int -Werror=incompatible-pointer-types -Werror=int-conversion -Werror=missing-declarations -Werror=missing-prototypes -Werror=overflow -Werror=override-init -Werror=return-type -Werror=shift-count-overflow -Werror=shift-overflow=2 -Werror=strict-flex-arrays -Werror=undef -Wfloat-equal -Wimplicit-fallthrough=5 -Winit-self -Wlogical-op -Wmissing-include-dirs -Wmissing-noreturn -Wnested-externs -Wold-style-definition -Wpointer-arith -Wredundant-decls -Wshadow -Wstrict-aliasing=2 -Wstrict-prototypes -Wsuggest-attribute=noreturn -Wunused-function -Wwrite-strings -Wzero-length-bounds -fdiagnostics-show-option -fno-common -fstack-protector -fstack-protector-strong -fstrict-flex-arrays --param=ssp-buffer-size=4 -Wno-unused-result -Werror=shadow -fno-strict-aliasing -fstrict-flex-arrays=1 -fvisibility=hidden -fno-omit-frame-pointer -include config.h -pthread -DTEST_CODE=1 -MD -MQ test-network-tables.p/src_network_test-network-tables.c.o -MF test-network-tables.p/src_network_test-network-tables.c.o.d -o test-network-tables.p/src_network_test-network-tables.c.o -c ../src/network/test-network-tables.c
In file included from ../src/basic/linux/if_bonding.h:47,
                 from ../src/network/netdev/bond.h:5,
                 from ../src/network/test-network-tables.c:3:
../src/basic/linux/if.h:111:41: error: redeclaration of enumerator ‘IFF_UP’
  111 | #define IFF_UP                          IFF_UP
      |                                         ^~~~~~
../src/basic/linux/if.h:84:9: note: previous definition of ‘IFF_UP’ with type ‘enum net_device_flags’
   84 |         IFF_UP                          = 1<<0,  /* sysfs */
      |         ^~~~~~
../src/basic/linux/if.h:112:41: error: redeclaration of enumerator ‘IFF_BROADCAST’
  112 | #define IFF_BROADCAST                   IFF_BROADCAST
      |                                         ^~~~~~~~~~~~~
...

This also drops remaining workarounds from the last time this issue was
brought up (6f270e6bd8) since they shouldn't be needed anymore if the
order of the includes is the "correct" one. I also added a comment to
each affected include when this is inevitably encountered again in the
future.

Resolves: #32160
2024-04-09 21:19:15 +02:00
Mike Yuan 74531a93d6 pidref: 0 -> NULL for pointer 2024-04-10 01:45:12 +08:00
Mike Yuan 7fe28d8386 uid-range: place 'ret' param at last 2024-04-08 20:14:38 +08:00
Mike Yuan 0aec92a5cc uid-range: use FOREACH_ARRAY at one more place 2024-04-08 20:14:38 +08:00
Yu Watanabe 6952ebae3b tree-wide: drop several remaining license headers
And downgrade the license of utf8.c to LGPL-2.0-or-later, to follow the
original license.
2024-04-08 10:14:50 +02:00
Lennart Poettering 3b2874952f cgroup-util: add helpers for opening cgroup by id 2024-04-06 16:08:23 +02:00
Lennart Poettering cb1b813f0d lock-util: make global lock return parameter to image_path_lock() optional
When adding unprivileged nspawn support we don't really want a global
lock file, since we cannot even access the dir they are stored in, hence
make the concept optional.

Some minor other modernizations.
2024-04-06 16:08:23 +02:00
Lennart Poettering e4f62e7a12 namespace-util: add new helper is_our_namespace() 2024-04-06 16:08:23 +02:00
Lennart Poettering 574a07c79d namespace-util: add namespace_open_by_type() helper 2024-04-06 16:08:23 +02:00
Lennart Poettering 2ad2f0c89e namespace-util: add detach_mount_namespace_userns() 2024-04-06 16:08:23 +02:00
Lennart Poettering e02fb2099c namespace-util: add helper for allocating an empty userns fd 2024-04-06 16:08:23 +02:00
Lennart Poettering 5783b4a954 namespace-util: add detach_mount_namespace_harder()
This is just like detach_mount_namespace() but if need be uses unpriv
user namespaces to be able to execute CLONE_NEWNS.
2024-04-06 16:08:23 +02:00
Lennart Poettering afdd0efa63 uid-range: add some basic operations on UidRange objects
Helpers to compare and get size, and whether the object is empty.
2024-04-06 16:08:23 +02:00
Lennart Poettering 20ba086e77 uid-range: add new uid_range_load_userns_by_fd() helper
This is similar to uid_range_load_userns() but instead of reading the
uid_map off a process it reads it off a userns fd.

(Of course the kernel has no API for this right now, hence we fork off a
throw-away process which joins the user namespace, and then read off the
data from there.)
2024-04-06 16:08:23 +02:00
Lennart Poettering 6ebb53d945 uid-range: optionally load outside view of UID range from uid_map procfs file 2024-04-06 16:08:23 +02:00
Lennart Poettering 5bff40e719 uid-range: add uid_range_overlaps() helper 2024-04-06 16:08:23 +02:00
Luca Boccassi e92042269e Merge pull request #32123 from mrc0mmand/assorted-tweaks
A couple of assorted tweaks
2024-04-05 22:22:06 +01:00
Mike YuanandLennart Poettering 99f3b67f3f os-util: use ENDSWITH_SET where appropriate
Addresses https://github.com/systemd/systemd/pull/31435#discussion_r1553969156

Co-authored-by: Lennart Poettering <lennart@poettering.net>
2024-04-06 02:16:53 +08:00
Zbigniew Jędrzejewski-Szmek c1e7f938ca Merge pull request #31435 from bluca/portable_fix_versioned
portable: assorted bug fixes
2024-04-05 17:04:17 +02:00
Frantisek Sumsal e55db9e792 log: fix comment 2024-04-05 12:14:18 +02:00
Mike Yuan 596c9e671a string-util: add missing assertion in cellescape 2024-04-03 23:51:11 +08:00
Luca Boccassi 1c6ca6d924 Merge pull request #32065 from bluca/dlopen_debug
dlopen: fix bpf symbol loading check and log at debug level when loading a library
2024-04-03 16:36:35 +01:00
Luca Boccassi 26cbb21449 Merge pull request #32019 from bluca/gcrypt_dlopen
gcrypt: dlopenify for libsystemd
2024-04-03 16:10:00 +01:00