Commit Graph

6870 Commits

Author SHA1 Message Date
Mike Yuan
b04ddbcbd7 string-table: annotate _to_string and _from_string with _const_ and _pure_, respectively
Follow-up for c94f6ab1bf
2025-05-06 23:07:00 +02:00
Daan De Meyer
1fbfbe81b5 tree-wide: Get rid of prefix_roota() in favor of path_join()
We deprecated prefix_roota() in favor of chase() and path_join().
Let's finish the removal by replacing the few remaining call sites
with path_join().
2025-05-06 17:40:33 +02:00
Daan De Meyer
38c9ca5380 tree-wide: Remove strv_from_stdarg_alloca()
It's trivial to replace all uses of this function with STRV_MAKE()
and strv_new_ap() so let's get rid of this variant.
2025-05-06 17:40:01 +02:00
Mike Yuan
c0239e5f11 macro: implement ABS via __builtin_imaxabs() 2025-05-06 17:39:01 +02:00
Daan De Meyer
efc529cfbd Add missing alloc-util.h to string-util.h
Used by strndupa_safe() and strdupa_safe().

Follow up for 02207b54d5
2025-05-06 17:38:11 +02:00
Daan De Meyer
02207b54d5 alloc-util: Move strdupa_safe() and strndupa_safe() to string-util.h 2025-05-06 15:42:01 +02:00
Daan De Meyer
e4a08721c3 string-util: Remove utf8.h and alloc-util.h includes 2025-05-06 13:27:54 +02:00
Daan De Meyer
0682853b2f Various preparatory changes from #37344 (#37348) 2025-05-06 11:23:15 +02:00
Daan De Meyer
c09ce222b6 hashmap: Drop debug params
Passing in the func, file and line information complicates the
interface. On top of that, it prevents forward declaring Hashmap in
strv.h, as we need to pass the macros everywhere that we allocate a
hashmap, which means we have to include the hashmap header everywhere
we have a function that allocates a hashmap instead of just having to
forward declare Hashmap.

Let's drop the file, func and line information from the debug information.
Instead, in the future we can add a description field to hashmaps like we
already have in various other structs to describe the purpose of the hashmap
which should be much more useful than having the file, line and function where
the hashmap was allocated.
2025-05-06 10:14:26 +02:00
Daan De Meyer
40a6cdc29e macro: Introduce ABS() macro and use it in header files
abs() requires including the entirety of stdlib.h just for a single
trivial function. Let's introduce the ABS() macro and use it in header
files instead so we can get rid of stdlib.h transitive includes in header
files in a later commit.
2025-05-06 10:14:26 +02:00
Daan De Meyer
c94f6ab1bf string-table: Move more implementation logic into functions
Let's move some more implementation logic into functions. We keep
the logic that requires the macro in the macro and move the rest into
functions.

While we're at it, let's also make the parameter declarations of
all the string table macros less clausthrophobic.
2025-05-06 10:14:24 +02:00
Yu Watanabe
a3a98a3793 prioq: coding style fixes 2025-05-05 22:53:01 +02:00
Daan De Meyer
b75c6c3c3f meson: Make sure check-filesystems.sh runs from the build directory
run_command()'s working directory is documented as undefined but it
seems to be the current source directory as when the -ftime-trace
clang option is enabled, -.json is written to src/basic/meson.build
every time meson is run.

Let's make sure the command is executed in the build directory so that
any auxiliary files are written there as well.
2025-05-05 17:09:18 +02:00
Daan De Meyer
a0233fcd86 socket-util: Replace sockaddr length macros with functions
There's no need for these to be macros, let's just make them regular
functions instead.
2025-05-02 09:41:41 +02:00
Daan De Meyer
d30d1ed00a basic: Add our own net/if_arp.h header
To avoid conflicts with <linux/if_arp.h>.
2025-05-01 14:02:17 +02:00
Mike Yuan
e0c4b80fb0 audit-util: use read_full_virtual_file()
Conversely this one is "raw" file, but let's switch to
static inline helper for it.
2025-05-01 13:10:26 +09:00
Mike Yuan
42dbe9d6b9 rlimit-util: use read_full_file() for /proc/PID/limits
This one uses "seq_file", i.e. normal FILE stream just works.
2025-05-01 13:10:26 +09:00
Mike Yuan
d6c8e0ce95 process-util: use procfs_file_get_field() where appropriate 2025-05-01 13:10:26 +09:00
Mike Yuan
5fd63a5a5e process-util: introduce procfs_file_get_field() wrapper
which combines procfs_file_alloca() and get_proc_field()
2025-05-01 13:10:26 +09:00
Mike Yuan
3589d6c01f process-util: assert on pid in procfs_file_alloca(), use strjoina() 2025-05-01 13:10:26 +09:00
Mike Yuan
d1313fea9b mountpoint-util: use get_proc_field() 2025-05-01 13:10:26 +09:00
Mike Yuan
d2c4df9e48 pidfd-util: use get_proc_field() for pidfd_get_pid_fdinfo() 2025-05-01 13:10:26 +09:00
Mike Yuan
15036f8555 fileio: modernize get_proc_field()
- Drop effectively unused "terminator" param, imply whitespace
- Make ret param optional
- Return ENODATA if the requested key is not found, rather than
  ENOENT
- Turn ENOENT -> ENOSYS if /proc/ is not mounted
- Don't skip whitespaces before ':', nothing needs this handling
  anyways
- Remove the special treatment for all "0"s. We don't actually
  use this for capabilities given pidref_get_capability() exists
- Switch away from read_full_virtual_file() - files using "field"
  scheme under /proc/ seem all to be "seq_file"s (refer to
  da65941c3e for details on file types)
2025-05-01 13:10:26 +09:00
Daan De Meyer
d62017b5a1 Add our own <netinet/in.h> and <net/if.h> headers and sort includes tree-wide with clang-format (#37278) 2025-04-30 10:42:57 +02:00
Daan De Meyer
1cf40697e3 tree-wide: Sort includes
This was done by running a locally built clang-format with
https://github.com/llvm/llvm-project/pull/137617 and
https://github.com/llvm/llvm-project/pull/137840 applied on all .c
and .h files.
2025-04-30 09:30:51 +02:00
Daan De Meyer
b773143708 clang-format: Disable for src/basic/include/linux
We shouldn't try to format these headers, so add a custom .clang-format
that disables formatting for the directory.
2025-04-30 09:30:33 +02:00
Daan De Meyer
6be15dce13 basic: Remove assertions from missing_fs.h
These assertions impose an include order between <linux/fs.h> and
"missing_fs.h", specifically <linux/fs.h> can't be included before
"missing_fs.h". This makes automated include refactoring very painful,
so let's get rid of these assertions and instead assume that linux/fs.h
does the right thing.
2025-04-30 07:50:10 +02:00
Daan De Meyer
54f6bc152f basic: Add macro.h include to missing_syscall_def.h
Required for assert_cc()
2025-04-30 07:50:10 +02:00
Daan De Meyer
d559f46384 basic: Add our own <netinet/in.h> and <net/if.h> headers
These glibc headers conflicts with the corresponding linux headers
(<linux/in.h> and <linux/if.h>) and impose an include order (the glibc one
has to be included before any linux header is included). This makes sorting
includes a royal pain so let's define our own versions of these headers using
various linux headers to do all the work and filling in the missing bits
ourselves.
2025-04-30 07:50:03 +02:00
Yu Watanabe
0dc09ccba7 linux: include sys/socket.h in linux/vm_sockets.h
The header requires struct sockaddr declared. So, otherwise, we need to
include sys/socket.h earlier than linux/vm_sockets.h.
Let's make the header includable at any place.
2025-04-30 07:37:34 +02:00
Yu Watanabe
3a03b97d6f tree-wide: drop unnecessary inclusion of tmpfile-util.h 2025-04-30 05:38:48 +09:00
Yu Watanabe
bd4ab24f49 basic/include/linux: update kernel headers from v6.15-rc4 2025-04-29 21:58:25 +09:00
David Rheinsberg
8166075498 basic/time-util: fix error handling of clock_nanosleep()
`clock_nanosleep()` returns error codes directly, rather than using
`errno`. Ensure that we use those codes, rather than checking for `<0`.
2025-04-28 19:31:16 +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
bcf716ca01 tree-wide: Remove dead code
This code seems to not be used anywhere at all, so let's drop it.

Follow up for ba8d00e859
Follow up for 85686b37b0
Follow up for aff853f8ea
Follow up for 36dad381a2
2025-04-24 10:15:19 +09:00
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