Commit Graph

6835 Commits

Author SHA1 Message Date
Daan De Meyer
6d47c16ce0 log: Make sure LOG_CONTEXT_SET_LOG_LEVEL() can be nested 2025-04-23 14:46:12 +02:00
Daan De Meyer
d25c238f97 basic: Move various macros from assert-util.h to assert-fundamental.h
ASSERT_PTR() and friends in assert-fundamental.h make use of assert()
and assert_se() which when not building for sd-boot are defined in
assert-util.h. Because assert() from glibc is only overridden in
assert-util.h, the macros in assert-fundamental.h still end up using
the glibc assert.

Let's fix this by moving the required macros and related logic to
assert-fundamental.h.
2025-04-23 13:48:48 +02:00
Daan De Meyer
a843382d1e journal: Always compile journal authentication related files
Tooling such as clang-tidy is bad at dealing with condition
compilation on the build system level instead of at the source file
level. What happens? It still tries to analyze the file and fails
horribly if the required headers aren't available. Let's work around
the issue and make things more consistent at the same time by doing
the necessary HAVE_GCRYPT checks inside of the source files instead
of doing them at the build system level.

We also add some typedefs to allow getting rid of various HAVE_GCRYPT
checks.
2025-04-23 11:50:33 +02:00
Daan De Meyer
401a22bfc1 tree-wide: Make sure all headers are standalone
Let's make sure all of our headers include everything they require.
2025-04-23 10:33:38 +02:00
Daan De Meyer
44de729cdc basic: Use _Static_assert() in missing_audit.h instead of assert_cc()
We want to make the header standalone so it includes all the stuff it
needs. However, including macro.h for assert_cc() doesn't work because
of generate-audit_type-list.sh which would have to become more complex
to handle the extra include directories.

Instead, let's just use _Static_assert() directly which is a builtin and
doesn't need any extra includes.
2025-04-23 10:33:37 +02:00
Mike Yuan
497e607ca0 cgroup-util: drop now unused cg_ns_supported() 2025-04-21 16:54:37 +02:00
Mike Yuan
418082596c namespace-util: generalize namespace_type_supported() 2025-04-21 16:54:37 +02:00
Mike Yuan
3c86a935ad cgroup-util: drop cg_freezer_supported(), assume supported 2025-04-21 16:29:40 +02:00
Daan De Meyer
3bb398c299 resolve,import: always use openssl (#36937) 2025-04-18 15:30:33 +02:00
Daan De Meyer
b8fd3f77db Various changes made as part of trying to run include-what-you-use on the systemd repository (#37112)
I have been trying to run
https://github.com/include-what-you-use/include-what-you-use on the
systemd repository to hopefully get a handle on the rampant numbers of
includes we have in every file with no idea if any of the symbols coming
from that file are used or not.

While I haven't got it fully working yet, these changes still make sense
IMO and can be merged already.

Except the last commit, all other changes are about removing circular
dependencies between headers which trips up include-what-you-use.
Regardless of the tool, circular dependencies between headers are a code
smell and I think we should get rid of them regardless of whether we end
up using the tool or not.
2025-04-18 15:07: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
793e187718 basic: Remove circular dependency between process-util.h and pidref.h 2025-04-18 14:19:16 +02:00
Daan De Meyer
95609f3dff basic: Remove circular dep between alloc-util.h and memory-util.h 2025-04-18 14:19:16 +02:00
Daan De Meyer
5d226b2f9a basic: Move macro.h include in list.h to the top of the file
Now that the circular dependency between log.h, macro.h and list.h
is gone, we can move the include to the top.
2025-04-18 14:19:16 +02:00
Daan De Meyer
93a1f7921a basic: Stop including log.h in macro.h
Now that the necessary functions from log.h have been moved to macro.h,
we can stop including log.h in macro.h. This requires modifying source
files all over the tree to include log.h instead.
2025-04-18 14:19:15 +02:00
Daan De Meyer
03e17cbe6e basic: Move assertion specific functions to assert-util.h
Various functions in log.h are only used by asserts, and there's
enough assertion related stuff in macro.h to justify a separate header
which also makes it easier to avoid circular dependencies.

Let's introduce assert-util.h and an accompanying fundamental header
and move all the assertion related stuff over there. PROJECT_FILE is
moved over to macro.h.
2025-04-18 13:59:06 +02:00
Daan De Meyer
5a124e8ee1 macro: Move definition of dummy_t to macro-fundamental.h
There is code in macro-fundamental.h that makes use of dummy_t so
let's make sure to declare dummy_t in macro-fundamental.h as well.
2025-04-18 13:59:06 +02:00
Daan De Meyer
69ebfef1a1 basic: Remove stdio-util.h include from log.h 2025-04-18 13:59:06 +02:00
Daan De Meyer
4a52d26d2b basic: Remove list.h include from log.h 2025-04-18 13:59:06 +02:00
Daan De Meyer
b14f74f9ab basic: Move trivial cleanup/ref/unref macros from macro.h to memory-util.h
Let's keep macro.h for the extremely generic macros that don't fit anywhere
else. Since CLEANUP_ARRAY() is already in memory-util-fundamental.h, we can
make a good case for moving the other cleanup macros in there as well.
2025-04-18 13:59:04 +02:00
Daan De Meyer
a4bff6ef8e basic: Move log context functions to log-context.h 2025-04-18 11:57:33 +02:00
Daan De Meyer
40d60725ec basic: Move ratelimit logging functions to ratelimit.h
The ratelimit logging functions are only useful in a few scenarios
so let's move them to ratelimit.h instead of keeping them in the
generic log.h
2025-04-18 10:11:40 +02:00
Yu Watanabe
4cbc25ab4c hashmap: drop hashmap_free_with_destructor() and friends 2025-04-18 09:16:44 +09:00
Yu Watanabe
885001ed5d hashmap: drop unused free func arguments in hashmap_free() and hashmap_clear() 2025-04-18 09:16:44 +09:00
Yu Watanabe
2d4c4d9e10 set: drop unused set_free_free() 2025-04-18 09:16:44 +09:00
Yu Watanabe
7baf24c949 network/manager: hash_ops related cleanups (#37121) 2025-04-18 06:00:15 +09:00
Stefan Hansson
b1236ce38b missing_fcntl: Introduce O_ACCMODE_STRICT
On musl, O_ACCMODE is defined as (03|O_SEARCH), unlike glibc which
defines it as (O_RDONLY|O_WRONLY|O_RDWR). Additionally, O_SEARCH is
simply defined as O_PATH.

This causes problems for systemd on musl, as it changes the
behaviour of open_mkdir_at_full() to return -EINVAL if O_PATH is
included in flags due to the fact that O_ACCMODE includes O_SEARCH
(i.e. O_PATH). Consequently, this makes the test-fs-util test fail.

Upstream musl seems content with this behaviour and doesn't seem
interested in matching glibc's behaviour due to that defining it this
way allows for O_SEARCH to match POSIX better by allowing it to open
directories where read permission is missing. Apparently musl does some
emulation in other places to make this work more consistently as well.

Initially I took the approach of working around this by redefining
O_SEARCH as O_RDONLY if O_SEARCH == O_PATH. This fixes the test and is
the approach taken by both XZ[1] and Gzip[2][3], but was not taken as
redefining system headers potentially could be problematic.

Instead, introduce O_ACCMODE_STRICT which just is a copy of glibc's
O_ACCMODE and use it everywhere. This way we don't have to deal with
unusual definitions of O_ACCMODE from C standard libraries other than
glibc.

 [1]: https://git.tukaani.org/?p=xz.git;a=blob;f=src/xz/file_io.c;h=8c83269b13fa31284f7ea5f3627a1dfbce7d6e14;hb=HEAD#l72
 [2]: https://git.savannah.gnu.org/cgit/gnulib.git/tree/lib/fcntl.in.h
      (lines 380 and 396, commit d7f551b30f3f2a0fa57c1b10c12f4eea41a9b89e)
 [3]: https://lists.gnu.org/archive/html/bug-gzip/2025-01/msg00000.html
2025-04-18 05:22:06 +09:00
Yu Watanabe
667fc1d993 conf-files: use hashmap_dump_sorted() at one more place 2025-04-16 08:17:52 +09:00
Luca Boccassi
86cfbfae97 xattr: fix assert that breaks importctl (#37146)
getxattr_at_malloc() calls getxattr_pinned_internal() with size 0 to get
the size of the xattr, and then asserts because n > 0
```
Assertion '(size_t) n <= size' failed at src/basic/xattr-util.c:107, function getxattr_pinned_internal().
```

Follow-up for b8df25dcfe
2025-04-16 06:44:24 +09:00
Yu Watanabe
6dbf2c1beb sd-netlink,sd-device: drop old kernels (<4.2) support
NETLINK_LIST_MEMBERSHIPS is supported since kernel v4.2, specifically
b42be38b27

Our baseline on the kernel is v5.4. Let's drop unnecessary conditions.
2025-04-15 03:40:40 +09:00
Yu Watanabe
09ddaf2af3 hashmap: introduce ordered_hashmap_free_and_replace() 2025-04-13 10:15:02 +09:00
Yu Watanabe
21d84e8905 locale-util: use string_hash_ops_free and set_to_strv()
Then we can drop hackish combination of use of set_free_free() and
set_free().
2025-04-13 04:59:26 +09:00
Yu Watanabe
3f23b37c5a strv: constify arguments for strv_equal_ignore_order()
Follow-up for 5072f4268b.
2025-04-13 04:59:26 +09:00
Yu Watanabe
24655047b0 set: introduce set_to_strv()
It is similar to set_get_strv(), but invalidates the set on success.
2025-04-13 04:59:26 +09:00
Yu Watanabe
4da43aeb0c locale-util: coding style cleanups 2025-04-13 04:59:26 +09:00
Yu Watanabe
a4a5ee4cd1 locale-util: filter out non-UTF-8 locales even when failed to parse $SYSTEMD_LIST_NON_UTF8_LOCALES 2025-04-13 04:59:26 +09:00
Yu Watanabe
90abb64fd5 locale-util: fix argument for munmap() 2025-04-13 04:59:26 +09:00
Busayo Dada
a51804a5ff Use secure_getenv() instead of getenv() where appropriate 2025-04-12 11:48:22 +01:00
Michal Sekletar
8b5e3be88e basic/namespace-util: obtain uid and gid before unsharing user namespace
Getting user and group after unsharing user namespace is too late
because without any mapping, i.e. just after unshare(), we are mapped to
nobody.
2025-04-09 03:06:05 +09:00
Yu Watanabe
8bf8e51bf5 fs-util: fix typo
Follow-up for 053e0626db.
2025-04-07 16:53:15 +09:00
Yu Watanabe
77c796d46f terminal-util: fix typo
Follow-up for 3390be38d1.
2025-04-07 16:35:18 +09:00
Yu Watanabe
79ef03740d terminal-util: fix typo
Follow-up for b27f791691.
2025-04-07 16:34:07 +09:00
Daan De Meyer
6aa69f702b core: Resolve /dev/console if it's connected to stdin (#36666) 2025-04-06 14:14:35 +02:00
Mike Yuan
c0ebcb818e build-path: teach pin_callout_binary() to search $PATH too
Prompted by 2caa462504
2025-04-06 02:39:06 +02:00
Mike Yuan
28b6bfd370 build-path: port to open_and_check_executable(), do not return resolved path
Follow-up for b58c240312

We need to be extremely careful with using the path associated with fd,
since it contains the resolved path if a symlink was opened. In particular,
it's really not desirable to return the resolved executable path in
pin_callout_binary(), which would end up as argv[0] in udev_event_spawn(),
potentially changing the behavior of spawned process.
2025-04-06 02:39:05 +02:00
Mike Yuan
326d60a9d0 path-util: generalize open_and_check_executable() 2025-04-06 02:32:47 +02:00
Yu Watanabe
e4e40936f3 nspawn: drop cgv1 handling; core: drop cgroup agent (#36764) 2025-04-05 17:57:18 +09:00
Yu Watanabe
99d704c6e8 stat-util: drop unnecessary call of xopenat() in xstatfsat() 2025-04-05 00:13:01 +09:00
Daan De Meyer
c7f7d87db5 terminal-util: Make sure resolve_dev_console() always returns a full path
Currently it returns a full path in some cases and a partial path in others.
Let's make sure it always returns a full path.
2025-04-04 17:12:58 +02:00
Mike Yuan
40d54c2da0 procfs-util: modernize convert_meminfo_value_to_uint64_bytes() 2025-04-04 15:34:51 +02:00