Commit Graph

6091 Commits

Author SHA1 Message Date
Yu Watanabe
c876cbdd19 time-util: define TIMESPEC_OMIT
Follow-up for 34c3d57474.
2024-05-10 10:11:06 +09:00
Florian Fainelli
41a94ae670 basic/linux: Copy netfilter.h to the source tree
This fixes build with old toolchains prior to Linux < 4.2 which do not
have a definition for NFPROTO_NETDEV.
2024-05-09 15:27:23 +02:00
Mike Yuan
63a0e57724 path-util: take char* const* for strv where appropriate 2024-05-09 17:02:19 +08:00
Lennart Poettering
d6bfc3d889 pidfd: properly detect if libc offers pidfd syscalls and make use of them then
We never updated the meson checks when glibc finally learned about these
syscalls, address that.
2024-05-08 15:36:40 +02:00
Lennart Poettering
cd7c207795 tree-wide: add dlopen ELF notes to all dlopen() deps of ours
Use 'recommended' priority for the default compression library, to
indicate that it should be prioritized over the other ones, as it
will be used to compress journals/core files.
Also use 'recommended' for kmod, as systems will likely fail to boot
if it's missing from the initrd.
Use 'suggested' for everything else.

There is one dlopen'ed TPM library that has the name generated
at runtime (depending on the driver), so that cannot be added, as it
needs to be known at build time.
Also when we support multiple ABI versions list them all, as for the
same reason we cannot know which one will be used at build time.

$ dlopen-notes.py build/libsystemd.so.0.39.0 build/src/shared/libsystemd-shared-256.so
libarchive.so.13 suggested
libbpf.so.0 suggested
libbpf.so.1 suggested
libcryptsetup.so.12 suggested
libdw.so.1 suggested
libelf.so.1 suggested
libfido2.so.1 suggested
libgcrypt.so.20 suggested
libidn2.so.0 suggested
libip4tc.so.2 suggested
libkmod.so.2 recommended
liblz4.so.1 suggested
liblzma.so.5 suggested
libp11-kit.so.0 suggested
libpcre2-8.so.0 suggested
libpwquality.so.1 suggested
libqrencode.so.3 suggested
libqrencode.so.4 suggested
libtss2-esys.so.0 suggested
libtss2-mu.so.0 suggested
libtss2-rc.so.0 suggested
libzstd.so.1 recommended

Co-authored-by: Luca Boccassi <bluca@debian.org>
2024-05-08 11:07:36 +01:00
Lennart Poettering
2f6bd11c1a dlfcn: add macro for exporting dlopen() module names in ELF sections
This allows code to declare "weak" dlopen() style deps via an ELF
section following the just added specification.

The idea is that any user of dlopen() will place ELF_NOTE_DLOPEN(…)
somewhere close which will synthesize the note.

Tools such as rpm/dpkg package builders as well as initrd generators
(such as dracut) can then automatically pick up these weak deps of
suggested dependencies for their purposes.

Co-authored-by: Luca Boccassi <bluca@debian.org>
2024-05-08 11:07:36 +01:00
Mike Yuan
158681f0f9 basic/mkdir: use timespec_store instead of _nsec for mkdir_p_root_full
Follow-up for 34c3d57474

O_RDONLY is dropped when O_DIRECTORY is specified, since
it's unnecessary and even arguably confusing here, as
the dir is modified.
2024-05-08 00:18:27 +08:00
Moritz Sanft
34c3d57474 repart: respect SOURCE_DATE_EPOCH on mkdir_p_root
This let's systemd-repart respect the `SOURCE_DATE_EPOCH` environment
variable when creating directories in the local tree through `CopyFiles`
or `MakeDirectories`.

To do this, we pass a timestamp `ts` to `mkdir_p_root`, which it will
use to fix up `mtime` and `atime` of the directory it creates as
well as the `mtime` of the directory it creates the other directory *in*,
as the `mtime` of the latter is modified when creating a directory in it.

For the same reason, it also needs to fixup the `mtime` of the upper
directory when copying a file into it through `CopyFiles`.

If `SOURCE_DATE_EPOCH`, times are left as is. (`UTIME_OMIT`)
2024-05-07 09:29:58 +02:00
Yu Watanabe
affde1d7e7 logs-show: adjust source timestamp with header timestamp
Previously, _SOURCE_REALTIME_TIMESTAMP was only used for realtime
timestamp, and _SOURCE_MONOTONIC_TIMESTAMP was for monotonic.

This make these journal field used more aggressively. If we need
realtime timestamp, but an entry has only _SOURCE_MONOTONIC_TIMESTAMP,
then now realtime timestamp is calculated based on
_SOURCE_MONOTONIC_TIMESTAMP and the header dual timestamp.
Similary, monotonic timestamp is obtained from
_SOURCE_REALTIME_TIMESTAMP and the header dual timestamp.

This should change shown timestamps not so much in most cases, but may
be improve the situation such as #32492.
2024-05-02 06:34:01 +09:00
Luca Boccassi
ba2caa8a38 build-path: fix SIGSEGV on RISC-V and MIPS
On RISC-V and MIPS DT_STRTAB is an offset, not a full address.

Follow-up for 91d149cfb4
2024-04-30 18:11:10 +02:00
Christian Göttsche
4be62f821c basic: add open_mkdir_at_full()
Add helper for open_mkdir_at() which accepts xopen flags, e.g. to pass
XO_LABEL to create the target with the correct security context.
2024-04-29 18:16:58 +02:00
Mike Yuan
f193fcbce9 Merge pull request #32547 from YHNdnzj/minor-cleanup
Some cleanups prompted during review
2024-04-29 21:08:06 +08:00
Daan De Meyer
7a66f21556 core: Add systemd.crash_action= kernel command line argument
Required for integration tests to power off on PID 1 crashes. We
deprecate systemd.crash_reboot and related options by removing them
from the documentation but still parsing them.
2024-04-29 14:34:22 +02:00
Mike Yuan
f0fb294369 fs-util: modernize touch_file a bit 2024-04-29 16:33:17 +08:00
Mike Yuan
973464ad0e fs-util: try AT_EMPTY_PATH first for futimens_opath 2024-04-29 16:33:17 +08:00
Mike Yuan
cce82462a1 efivars: drop unneeded UTIME_NOW
futimens(2) defaults to current time if 'times' is NULL.
2024-04-29 16:33:17 +08:00
Mike Yuan
39a8ef05cd various: drop unnecessary DISABLE_WARNING_FORMAT_NONLITERAL
We use _printf_ for these functions, so there shouldn't
be a warning in the first place.
2024-04-28 13:33:17 +02:00
Lennart Poettering
47bb0b8c29 errno-util: consider ENOPROTOOPT another "not supported"
It's generated by not supported getsocktopt()/setsockopt() options, and
it's just another way for saying "not supported", hence treat it as
such.
2024-04-25 12:43:21 +02:00
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