Commit Graph

1329 Commits

Author SHA1 Message Date
Daan De Meyer
d86fead481 meson: Rework clang-tidy integration to be done via unit tests
Instead of using run-clang-tidy.py with its own scheduling, let's
just gather a list of source files ourselves and then use that to
add a unit test for each source file that runs clang-tidy on the
source file.

We also add a bit of logic to run clang-tidy on most header files
as well for extra coverage. This uncovered various header files that
were not standalone so this commit also includes fixes to make sure
the clang-tidy tests are all green.

We can also use this in a later commit to run clang-include-cleaner
on each source file in the same way.
2025-05-20 10:29:59 +02:00
Daan De Meyer
b7400b14ed meson: Build fuzz executables by default if fuzz-tests option is enabled
fuzz-tests is enabled by default now but we still don't build the fuzz
executables by default. Let's change that so that we always make sure these
still compile when we make changes.
2025-05-20 10:29:59 +02:00
Daan De Meyer
691abc5ea8 journal-remote: Allow building without microhttpd support
systemd-journal-remote is useful even if the microhttpd related features
are not enabled so let's not skip it entirely if microhttpd is not available.
2025-05-20 10:29:58 +02:00
Yu Watanabe
e9ad95438d meson: fix path to coverage.h
Follow-up for 30d20907bd.
2025-05-14 02:28:27 +09:00
Ivan Kruglov
8c823a038c meson: introduce PROJECT_VERSION_STR and use it in udev 2025-05-13 01:53:22 -07:00
Daan De Meyer
1fbaabf9ec meson: Don't create static library target unless option is enabled
While we don't build these by default, all the source files still
get added to the compile_commands.json file by meson, which can confuse
tools as they might end up analyzing the source files twice or analyzing
the wrong one.

To avoid this issue, only define the static library target if the
corresponding option is enabled.
2025-05-12 13:35:50 +02:00
Daan De Meyer
30d20907bd meson: Remove unneeded include directories
meson by default adds the current source and build directory as include
directories. Because we structure our meson code by gathering a giant dict
of everything we want to do and then doing all the actual target generation
in the top level meson.build, this behavior does not make sense at all because
we end up adding the top level repository directory as an include directory
which is never what we want.

At the same time, let's also make sure the top level directory of the build
directory is not an include directory, by moving the version.h generation
into the src/version subdirectory and then adding the src/version subdirectory
of the build directory as an include directory instead of the top level
repository directory.

Making this change means that language servers such as clangd can't get
confused when they automatically insert an #include line and insert
"#include "src/basic/fs-util.h" instead of "#include "fs-util.h".
2025-05-12 13:35:50 +02:00
Daan De Meyer
6350d2dbd9 meson: Extract objects instead of creating intermediate static libraries
Currently, when we want to add unit tests for code that is compiled into
an executable, we either compile the code at least twice (once for the
executable, and once for each test that uses it) or we create a static
library which is then used by both the executable and all the tests.

Both of these options are not ideal, compiling source files more than
once slows down the build for no reason and creating the intermediate
static libraries takes a lot of boilerplate.

Instead, let's use the extract_objects() method that meson exposes on
build targets. This allows us to extract the objects corresponding to
specific source files and use them in other executables. Because we
define all executables upfront into a dictionary, we integrate this into
the dictionary approach by adding two new fields:

- 'extract' takes a list of files for which objects should be extracted.
  The extracted objects are stored in a dict keyed by the executable name
  from which they were extracted.
- 'objects' takes the name of an executable from which the extracted
  objects should be added to the current executable.

One side effect of this approach is that we can't build test executables
anymore without building the main executable, so we stop building test
executables unless we're also building the main executable. This allows
us to switch to using subdir_done() in all of these subdirectories to skip
parsing them if the corresponding component is disabled.

These changes get me down from 2439 => 2403 ninja targets on a full rebuild
from scratch.
2025-05-12 13:35:50 +02:00
Daan De Meyer
d8def5dc87 meson: Stop doing nested build when fuzzers are enabled
Currently, when fuzzers are enabled, we run meson from within meson
to build the fuzzer executables with sanitizers. The idea is that
we can build the fuzzers with different kinds of sanitizers
independently from the main build.

The issue with this setup is that we don't actually make use of it.
We only build the fuzzers with one set of sanitizers (address,undefined)
so we're adding a bunch of extra complexity without any benefit as we
can just setup the top level meson build with these sanitizers and get
the same result.

The other issue with this setup is that we don't pass on all the options
passed to the top level meson build to the nested meson build. The only things
we pass on are extra compiler arguments and the value of the auto_features
option, but none of the individual feature options if overridden are passed on,
which can lead to very hard to debug issues as an option enabled in the top
level build is not enabled in the nested build.

Since we're not getting anything useful out of this setup, let's simplify
and get rid of the nested meson build. Instead, sanitizers should be enabled
for the top level meson.build. This currently didn't work as we were overriding
the sanitizers passed to the meson build with the fuzzer sanitizer, so we
fix that as well by making sure we combine the fuzzer sanitizer with the ones
passed in by the user.

We also drop support for looking up libFuzzer as a separate library as
it has been shipped builtin in clang since clang 6.0, so we can assume
that -fsanitize=fuzzer is available.

To make sure we still run the fuzzing tests, we enable the fuzz-tests option
by default now to make sure they still always run (without instrumentation unless
one of llvm-fuzz or oss-fuzz is enabled).
2025-05-12 13:34:28 +02:00
Daan De Meyer
d06abcf68e meson: Implement duplicate includes check with clang-tidy
Instead of doing this with our own script, let's use clang-tidy
instead.
2025-04-24 12:36:38 +02:00
Daan De Meyer
44e86153d1 meson: Define our own clang-tidy target
meson's target has a few issues:
- Runs on all source files regardless if they're included in the
  build or not
- Doesn't have any dependencies on generated sources which means we
  have to do a full build first before we can run clang-tidy
- Doesn't allow us to pass any extra arguments

To work around these, let's define our own clang-tidy target instead
using llvm's run-clang-tidy script. Alongside the clang-tidy target,
let's start keeping track of all generated sources which we make the
clang-tidy target depend on. We also add a new target which will only
generate source files which is useful for setting up the source tree
for running code analysis against it.
2025-04-24 12:36:36 +02:00
Daan De Meyer
3bb398c299 resolve,import: always use openssl (#36937) 2025-04-18 15:30:33 +02:00
Daan De Meyer
44c2c9a036 tree-wide: Mark linux and sys includes as system includes
Even though these are in our tree, we should still treat them as
system includes which helps various tools (clangd, iwyu, ...) understand
that these are system includes and <> should be used instead of "".
2025-04-18 14:19:16 +02:00
Daan De Meyer
710653d3bc test: Use meson add_test_setup() instead of environment variables
We add a default test setup that excludes the integration-tests suite
so that the integration tests don't run by default. This allows us to
get rid of $SYSTEMD_INTEGRATION_TESTS. Then, we add two extra setups:
'integration' and 'shell'. The 'integration' setup does not exclude the
integration-tests suite, and so can be used to run the integration tests.
The 'shell' setup does the same, but additionally sets $TEST_SHELL=1,
allowing to get rid of $TEST_SHELL in the docs.
2025-04-17 20:31:08 +02:00
Daan De Meyer
b2634bde3c meson: Use custom_target() instead of vcs_tag()
vsc_tag() always reruns even if the vcs-tag option is disabled. Let's
use custom_target() instead so that we can only enable build_always_stale
if the vcs-tag option is enabled.
2025-04-09 16:21:08 +02:00
Daan De Meyer
a0ce5e642f test: Install files required to run integration tests standalone
Let's make it possible to run the integration tests without requiring
the sources by installing the mkosi and integration-tests directories.
2025-04-08 13:02:24 +02:00
Yu Watanabe
e4e40936f3 nspawn: drop cgv1 handling; core: drop cgroup agent (#36764) 2025-04-05 17:57:18 +09:00
Mike Yuan
be1d96dbc3 core: remove cgroups-agent 2025-04-04 15:34:51 +02:00
Yu Watanabe
ab29e77aa9 meson: enable -Werror=flex-array-member-not-at-end 2025-04-04 20:54:53 +09:00
Yu Watanabe
011360eed3 meson: rename RC_LOCAL_PATH -> SYSTEM_SYSVRCLOCAL_PATH
No functional change, but just for emphasizing that this is for
SysV compatibility.
2025-04-03 00:19:49 +09:00
Yu Watanabe
74f25ea7a9 meson: disable rc-local-generator when an empty string is specified to rc-local= meson option
In such case, the generator is meaningless. Let's kill it.
2025-04-03 00:18:48 +09:00
Yu Watanabe
e9d4b88b81 resolve,import: always use openssl
This deprecate cryptolib meson option.
2025-04-02 05:47:47 +09:00
Yu Watanabe
b1c3f57e76 resolve: always use openssl as backend of DNS-over-TLS
This drops support for dns-over-tls=gnutls meson option.
2025-04-02 05:20:40 +09:00
Lennart Poettering
0bdd5ccc81 validatefs: add new tool that enforces mount constraints
This new tool looks for a three xattr on the root inode of a file system
that encode mount constraints of the file system. The tool is supposed
to be hooke into the mount logic and is supposed to protect against
misappropriating trusted file systems in unintended ways.

Consider the following scenario: we boot up on first boot and create a
tpm-locked pair of /var/ and /srv/ partitions via systemd-repart. An
attacker then offline modifies the partition table, exchanging the
metadata of the /var/ and /srv/ partition. So far we'd happily accept
that, honour the modified metadata and boot up. This could be used to
revert changes to /var/ or similar. And all that even though both
partitions are encrypted and locked to TPM!

With this new mechanism we can encode in the protected contents of the
file systems the ways it can be used: the partition type uuid, the
partition label and the intended mount point can be stored in xattrs,
and we can check them automatically on mount, and take action on
mismatch. (action would typically be immediate reboot).
2025-03-31 15:14:13 +02:00
Luca Boccassi
d95818f522 meson: add feature flag for nspawn build
Other tools have it, nspawn doesn't, add one
2025-03-28 10:34:02 +00:00
Daan De Meyer
e213ecd484 test: Make it possible to run the integration tests standalone (#36868)
Currently, to run the integration tests, it's still necessary to
install various other build tools besides meson: A compiler, gperf,
libcap, ... which we want to avoid in CI systems where we receive
prebuilt systemd packages and only want to test them. Examples are
Debian's autopkgtest CI and Fedora CI. Let's make it possible for
these systems to run the integration tests without having to install
any other build dependency besides meson by extracting the logic
required to run the integration tests with meson into a separate
subdirectory and adding a standalone top-level meson.build file which
can be used to configure a meson tree with as its only purpose running
the integration tests.

Practically, we do the following:
- all the integration test directories and integration-test-wrapper.py
  are moved from test/ to test/integration-tests/.
- All the installation logic is kept out of test/integration-tests/ or
  any of its subdirectories and moved into test/meson.build instead.
- We add test/integration-tests/standalone/meson.build to run the
  integration tests standalone. This meson file includes
  test/integration-tests via a cute symlink hack to trick meson into
  including a parent directory with subdir().
- Documentation is included on how to use the new standalone mode.
2025-03-27 21:38:00 +01:00
Daan De Meyer
b4b1d94a09 meson: Drop project_source_root and project_build_root variables
We can now rely on meson.project_source_root() and meson.project_build_root()
which do the same thing.
2025-03-26 14:45:34 +01:00
Nick Rosbrook
bc3a11097f login: add polkit example rules for allowing root to ignore inhibitors
The semantics of strong inhibitors require that POLKIT_ALWAYS_QUERY
always be set when checking if we can allow blocking inhibitors to be
ignored on shutdown, reboot, etc. With the default polkit rules and
policy, users may experience a situation where users in the sudo group
are authorized to run:

 systemctl reboot --check-inhibitors=no

but the root user is not authorized. Instead, the following error is
given:

 Call to Reboot failed: Interactive authentication required.

While this is correct according to the semantics of strong inhibitors,
it is confusing. To help the situation, provide example polkit rules
that allow root to perform these actions.

Finally, when root receives SD_BUS_ERROR_INTERACTIVE_AUTHORIZATION_REQUIRED
when calling e.g. systemctl reboot, print a message explaining that this
is due to the current polkit policy, and point to the new example rule.

Related: https://github.com/systemd/systemd/issues/36786
2025-03-25 16:15:34 -04:00
Yu Watanabe
59e64dd86d meson: make pointer-sign warning critical
With the previous commit, no pointer signedness warning should be
triggered even built with C23. Let's make the warning critical.
2025-03-16 10:16:08 +09:00
Yu Watanabe
88f4650f22 meson: handle bool-compare warning as error
Then we can detect the error fixed by the previous commit like the following:

../src/libsystemd/sd-device/test-sd-device.c: In function ‘test_sd_device_enumerator_add_all_parents’:
../src/shared/tests.h:225:51: error: comparison of constant ‘0’ with boolean expression is always true [-Werror=bool-compare]
  225 | #define ASSERT_OK(expr) __coverity_check__((expr) >= 0)
      |                                                   ^~
../src/libsystemd/sd-device/test-sd-device.c:547:9: note: in expansion of macro ‘ASSERT_OK’
  547 |         ASSERT_OK(sd_device_enumerator_add_all_parents(e) >= 0);
      |         ^~~~~~~~~
2025-03-15 08:56:38 +09:00
Yu Watanabe
51c086b9cc meson: use more features provided by newer meson
No functional change. Preparation for future bump of required meson
version.
2025-03-10 02:41:40 +09:00
Yu Watanabe
c0cc01de8a meson: use install_symlink() where applicable
Now our baseline of meson is 0.62, hence install_symlink() can be used.

Note, install_symlink() implies install_emptydir() for specified
install_dir. Hence, this also drops several unnecessary
install_emptydir() calls.

Note, the function currently does not support 'relative' and 'force' flags,
so several 'ln -frsT' inline calls cannot be replaced.
2025-03-10 02:41:40 +09:00
Yu Watanabe
a030f8cc94 meson: bump required minimum version to 0.62.0
The commit 8442ac9c02 set
install_tag option to install_emptydir() calls, but it requires
meson-0.62.0. Hence, after the commit, we cannot build systemd
with older meson anymore. As using install_tag is quite useful
for building systemd package, let's bump the requirement of
meson version to 0.62.0.

Note, the current meson versions of major distributions are:
CentOS 9:  0.63.3
CentOS 10: 1.4.1
Fedora 40: 1.4.1
Fedora 41: 1.5.1
Ubuntu 20.04 LTS (focal): 0.53.2 -- EOL on 2025-04
Ubuntu 22.04 LTS (jammy): 0.61.2 -- EOL on 2027-04
Ubuntu 24.04 LTS (noble): 1.3.2
Ubuntu 24.10 (oracular):  1.5.2
Debian 11 (bullseye): 0.56.2 (1.0.0 in backports) -- EOL on 2024-08
Debian 12 (bookworm): 1.0.1  (1.5.1 in backports)
openSUSE Leap 15.6:  1.6.1
openSUSE Tumbleweed: 1.6.1

As the next version (v258) is not expected to be released before
the end of 2025-04, it is OK to cut the support of Ubuntu 20.04 LTS and
Debian 11. Also, our policy for support of distributions explicitly says
only latest Ubuntu LTS and non-LTS releases are supported.
Hence, we can also cut Ubuntu 22.04, even if it is not EOL.

Follow-up for 8442ac9c02.
Closes #35967.
2025-03-10 02:41:40 +09:00
Lennart Poettering
41d9ed93d9 factory-reset: revamp infrastructure
This introduces a bunch of facilities:

1. The factory-reset.target unit that requests a factory reset is now
   complemented by factory-reset-now.target that executes it at next
   boot.

2. This latter is added to the initial transaction via the new trivial
   systemd-factory-reset-generator.

3. A tool systemd-factory-reset has been added to query, request,
   cancel, complete factory reset operations (via EFI variables). Two of
   these are wrapped into units that are plugged into
   factory-reset.target and factory-reset-now.target respectively. The
   tool also provides a simple Varlink API.

This should make things a lot cleaner, and both be useful as explicit
implementation on UEFI, and as template + hookpoints for alternative
implementations on non-UEFI.
2025-03-05 12:37:26 +01:00
Yu Watanabe
e86a492ff0 dirent-util: introduce simple wrapper of posix_getdents()
glibc exports getdents64 syscall as is, but musl exports it as
posix_getdents(). Let's introduce a simple wrapper of posix_getdents().

Note, our baseline for glibc is 2.31. Hence, we can assume getdents64()
always defined when building with glibc.
2025-03-04 04:23:57 +09:00
Yu Watanabe
ec32732043 basic: introduce our own sys/mount.h implementation
To resolve conflict with sys/mount.h and linux/mount.h or linux/fs.h.

The conflict between sys/mount.h and linux/mount.h is resolved in
glibc-2.37 (774058d72942249f71d74e7f2b639f77184160a6), but our baseline
is still glibc-2.31. Also, even with the version or newer, still
sys/mount.h conflicts with linux/fs.h, which is included by
linux/btrfs.h.

This introduces our own implementation of sys/mount.h, that can be
simultaneously included with linux/mount.h and linux/fs.h. This also
imports linux/fs.h, linux/mount.h, and several other dependent headers.
The introduced sys/mount.h header itself may not be enough simple, but
by using the header, we can drop most of workarounds in other source files.
2025-03-04 02:24:49 +09:00
Yu Watanabe
e7e91769e8 basic/linux: import ioprio.h from kernel 6.14-rc4
This also fixes the maximum allowed ioprio class: 8 -> 7
2025-03-04 02:24:49 +09:00
Yu Watanabe
b5337d1d52 meson: cleanup glibc header checkers 2025-03-04 02:24:49 +09:00
Yu Watanabe
883360f63a missing_type: char16_t and char32_t are always defined in uchar.h since C11
Now, we use C17, hence the fallback definitions can be dropped.
2025-03-04 02:24:49 +09:00
Yu Watanabe
905497c86d missing_stdlib: secure_getenv() exists since glibc-2.17 2025-03-04 02:24:49 +09:00
Yu Watanabe
e79d88320a alloc-util: reallocarray() exists since glibc-2.26 2025-03-04 02:24:49 +09:00
Yu Watanabe
2e22dd218a memory-util: explicit_bzero() exists since glibc-2.25 2025-03-04 02:24:49 +09:00
Yu Watanabe
fbfe09ccd0 missing_syscall: drop unused rt_sigqueueinfo wrapper
The syscall is unused since 19e1a908b5.
2025-03-04 02:24:49 +09:00
Yu Watanabe
177f168f43 missing_syscall: copy_file_range is supported by glibc since 2.27
Now our baseline of glibc is 2.31, hence it is OK to drop our
definition.
2025-03-04 02:24:49 +09:00
Yu Watanabe
f2786bd3e7 missing_syscall: renameat2 is supported by glibc since 2.28
Now our baseline of glibc is 2.31, hence it is OK to drop our
definition.
2025-03-04 02:24:49 +09:00
Yu Watanabe
d322854cac missing_syscall: setns is supported by glibc since 2.14
Also, CLONE_PIDFD is defined in sched.h since 2.31.
Now our baseline of glibc is 2.31, hence it is OK to drop our
definition.
2025-03-04 02:24:49 +09:00
Yu Watanabe
96ff465861 missing_syscall: name_to_handle_at is supported by glibc since 2.14
Now our baseline of glibc is 2.31, hence it is OK to drop our
definition.
2025-03-04 02:24:49 +09:00
Yu Watanabe
65e844bdb8 missing_syscall: gettid is supported by glibc since 2.30
Now our baseline of glibc is 2.31, hence it is OK to drop our
definition.
2025-03-04 02:24:49 +09:00
Yu Watanabe
69a5c4b14c missing_syscall: getrandom is supported by glibc since 2.25
Now our baseline of glibc is 2.31, hence it is OK to drop our
definition.
2025-03-04 02:24:49 +09:00
Yu Watanabe
6ca5be8d3f missing_syscall: memfd_create() is supported by glibc since 2.27
Now, our baseline of glibc is 2.31, hence it is OK to drop it.
2025-03-04 02:24:36 +09:00