From: Daan De Meyer Date: Thu, 22 May 2025 09:17:20 +0000 (+0200) Subject: shared: Clean up includes X-Git-Tag: v258-rc1~506 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69a283c5f21a21ea2e2fdcc18fc0d058ffe0d2e1;p=thirdparty%2Fsystemd.git shared: Clean up includes Split out of #37344. --- diff --git a/src/libsystemd/sd-bus/test-bus-address.c b/src/libsystemd/sd-bus/test-bus-address.c index 347ba1a39b0..ab668060f30 100644 --- a/src/libsystemd/sd-bus/test-bus-address.c +++ b/src/libsystemd/sd-bus/test-bus-address.c @@ -2,6 +2,7 @@ #include "sd-bus.h" +#include "argv-util.h" #include "bus-internal.h" #include "log.h" #include "string-util.h" diff --git a/src/libsystemd/sd-journal/test-journal-flush.c b/src/libsystemd/sd-journal/test-journal-flush.c index 309220e20a5..05252d7f096 100644 --- a/src/libsystemd/sd-journal/test-journal-flush.c +++ b/src/libsystemd/sd-journal/test-journal-flush.c @@ -6,6 +6,7 @@ #include "sd-journal.h" #include "alloc-util.h" +#include "argv-util.h" #include "chattr-util.h" #include "dirent-util.h" #include "fd-util.h" @@ -13,9 +14,11 @@ #include "journal-internal.h" #include "logs-show.h" #include "macro.h" +#include "output-mode.h" #include "path-util.h" #include "rm-rf.h" #include "string-util.h" +#include "strv.h" #include "tests.h" #include "tmpfile-util.h" diff --git a/src/libsystemd/sd-journal/test-journal-interleaving.c b/src/libsystemd/sd-journal/test-journal-interleaving.c index 6d5eacff020..9703f46c429 100644 --- a/src/libsystemd/sd-journal/test-journal-interleaving.c +++ b/src/libsystemd/sd-journal/test-journal-interleaving.c @@ -7,6 +7,7 @@ #include "sd-journal.h" #include "alloc-util.h" +#include "argv-util.h" #include "chattr-util.h" #include "iovec-util.h" #include "journal-file-util.h" diff --git a/src/libsystemd/sd-journal/test-journal.c b/src/libsystemd/sd-journal/test-journal.c index 8892bec2cbf..6f6aa9d2751 100644 --- a/src/libsystemd/sd-journal/test-journal.c +++ b/src/libsystemd/sd-journal/test-journal.c @@ -3,6 +3,7 @@ #include #include +#include "argv-util.h" #include "chattr-util.h" #include "iovec-util.h" #include "journal-authenticate.h" diff --git a/src/libsystemd/sd-login/test-login.c b/src/libsystemd/sd-login/test-login.c index 66e427411e4..f7dab9b7236 100644 --- a/src/libsystemd/sd-login/test-login.c +++ b/src/libsystemd/sd-login/test-login.c @@ -8,6 +8,7 @@ #include "sd-login.h" #include "alloc-util.h" +#include "argv-util.h" #include "errno-list.h" #include "fd-util.h" #include "format-util.h" diff --git a/src/libsystemd/sd-login/test-sd-login.c b/src/libsystemd/sd-login/test-sd-login.c index a9026eb4182..a388a199a96 100644 --- a/src/libsystemd/sd-login/test-sd-login.c +++ b/src/libsystemd/sd-login/test-sd-login.c @@ -3,8 +3,10 @@ #include "sd-login.h" #include "alloc-util.h" +#include "format-util.h" #include "main-func.h" #include "parse-util.h" +#include "strv.h" #include "tests.h" static const char *arg_verb = NULL; /* NULL means all */ diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c index b5c8fa01357..a057e8028ce 100644 --- a/src/shared/acl-util.c +++ b/src/shared/acl-util.c @@ -1,15 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include -#include #include "acl-util.h" #include "alloc-util.h" #include "errno-util.h" #include "extract-word.h" -#include "log.h" #include "string-util.h" #include "strv.h" #include "user-util.h" diff --git a/src/shared/acl-util.h b/src/shared/acl-util.h index 8d62e6460f3..2164017de3c 100644 --- a/src/shared/acl-util.h +++ b/src/shared/acl-util.h @@ -1,19 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "forward.h" int fd_acl_make_read_only_fallback(int fd); int fd_acl_make_writable_fallback(int fd); #if HAVE_ACL -#include -#include -#include - -#include "macro.h" -#include "memory-util.h" +#include /* IWYU pragma: export */ +#include /* IWYU pragma: export */ int calc_acl_mask_if_needed(acl_t *acl_p); int add_base_acls_if_needed(acl_t *acl_p, const char *path); diff --git a/src/shared/acpi-fpdt.c b/src/shared/acpi-fpdt.c index 22a36bdd243..d1551acbc91 100644 --- a/src/shared/acpi-fpdt.c +++ b/src/shared/acpi-fpdt.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include #include #include diff --git a/src/shared/acpi-fpdt.h b/src/shared/acpi-fpdt.h index 56f8c9e0770..167813a462a 100644 --- a/src/shared/acpi-fpdt.h +++ b/src/shared/acpi-fpdt.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int acpi_get_boot_usec(usec_t *ret_loader_start, usec_t *ret_loader_exit); diff --git a/src/shared/apparmor-util.c b/src/shared/apparmor-util.c index cddf23073eb..2878517fe97 100644 --- a/src/shared/apparmor-util.c +++ b/src/shared/apparmor-util.c @@ -1,11 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include "alloc-util.h" #include "apparmor-util.h" #include "fileio.h" -#include "log.h" #include "parse-util.h" #if HAVE_APPARMOR diff --git a/src/shared/apparmor-util.h b/src/shared/apparmor-util.h index b1b511aed5e..3d9df43c714 100644 --- a/src/shared/apparmor-util.h +++ b/src/shared/apparmor-util.h @@ -1,15 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "dlfcn-util.h" +#include "forward.h" #if HAVE_APPARMOR # include -#include "memory-util.h" +# include "dlfcn-util.h" extern DLSYM_PROTOTYPE(aa_change_onexec); extern DLSYM_PROTOTYPE(aa_change_profile); diff --git a/src/shared/ask-password-agent.c b/src/shared/ask-password-agent.c index c5898ca5640..015d413506c 100644 --- a/src/shared/ask-password-agent.c +++ b/src/shared/ask-password-agent.c @@ -1,10 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include -#include #include "ask-password-agent.h" +#include "bus-util.h" #include "exec-util.h" #include "log.h" #include "process-util.h" diff --git a/src/shared/ask-password-agent.h b/src/shared/ask-password-agent.h index a76cdb11fea..610f910905f 100644 --- a/src/shared/ask-password-agent.h +++ b/src/shared/ask-password-agent.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "bus-util.h" +#include "forward.h" int ask_password_agent_open(void); void ask_password_agent_close(void); diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index a52d874ad85..5709987ce41 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -1,20 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include -#include -#include -#include +#include #include -#include #include #include #include -#include -#include -#include #include #include @@ -22,7 +13,6 @@ #include "ansi-color.h" #include "ask-password-api.h" #include "creds-util.h" -#include "env-util.h" #include "fd-util.h" #include "fileio.h" #include "format-util.h" @@ -33,10 +23,7 @@ #include "iovec-util.h" #include "keyring-util.h" #include "log.h" -#include "macro.h" -#include "memory-util.h" #include "missing_syscall.h" -#include "mkdir-label.h" #include "nulstr-util.h" #include "parse-util.h" #include "path-lookup.h" diff --git a/src/shared/ask-password-api.h b/src/shared/ask-password-api.h index f39a3459d6a..4756e517b19 100644 --- a/src/shared/ask-password-api.h +++ b/src/shared/ask-password-api.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "time-util.h" +#include "forward.h" typedef enum AskPasswordFlags { ASK_PASSWORD_ACCEPT_CACHED = 1 << 0, /* read from kernel keyring */ diff --git a/src/shared/async.c b/src/shared/async.c index c8f755cb2ec..0d5fbc13a7b 100644 --- a/src/shared/async.c +++ b/src/shared/async.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include +#include #include #include #include @@ -10,8 +9,8 @@ #include "errno-util.h" #include "fd-util.h" #include "log.h" -#include "macro.h" #include "process-util.h" +#include "rm-rf.h" #include "signal-util.h" int asynchronous_sync(PidRef *ret_pid) { diff --git a/src/shared/async.h b/src/shared/async.h index c49b3853083..d887a4ca551 100644 --- a/src/shared/async.h +++ b/src/shared/async.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "macro.h" -#include "pidref.h" -#include "rm-rf.h" +#include "forward.h" /* These functions implement various potentially slow operations that are executed asynchronously. They are * carefully written to not use pthreads, but use fork() or clone() (without CLONE_VM) so that the child does diff --git a/src/shared/barrier.c b/src/shared/barrier.c index bd5bdd75908..d08a78d49a9 100644 --- a/src/shared/barrier.c +++ b/src/shared/barrier.c @@ -1,19 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include -#include +#include #include -#include #include #include "barrier.h" #include "errno-util.h" #include "fd-util.h" #include "io-util.h" -#include "macro.h" /** * Barriers diff --git a/src/shared/barrier.h b/src/shared/barrier.h index d9e185646f2..0be490bd545 100644 --- a/src/shared/barrier.h +++ b/src/shared/barrier.h @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - -#include "macro.h" -#include "memory-util.h" +#include "forward.h" /* See source file for an API description. */ diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index 8cb49c47663..080e13a17a5 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -1,23 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include #include #include #include #include "alloc-util.h" -#include "architecture.h" #include "base-filesystem.h" #include "errno-util.h" #include "fd-util.h" #include "log.h" -#include "macro.h" #include "nulstr-util.h" #include "path-util.h" -#include "string-util.h" #include "umask-util.h" #include "user-util.h" diff --git a/src/shared/base-filesystem.h b/src/shared/base-filesystem.h index a1ccf451c47..5c5aa573ef0 100644 --- a/src/shared/base-filesystem.h +++ b/src/shared/base-filesystem.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int base_filesystem_create_fd(int fd, const char *root, uid_t uid, gid_t gid); int base_filesystem_create(const char *root, uid_t uid, gid_t gid); diff --git a/src/shared/battery-util.h b/src/shared/battery-util.h index c58f30b0b15..3c39fc76c9a 100644 --- a/src/shared/battery-util.h +++ b/src/shared/battery-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-device.h" +#include "forward.h" int on_ac_power(void); diff --git a/src/shared/binfmt-util.c b/src/shared/binfmt-util.c index c96ad24b3d2..c88ce2cd0e2 100644 --- a/src/shared/binfmt-util.c +++ b/src/shared/binfmt-util.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include "binfmt-util.h" diff --git a/src/shared/bitmap.c b/src/shared/bitmap.c index 9aa766139bb..d88a7895d6e 100644 --- a/src/shared/bitmap.c +++ b/src/shared/bitmap.c @@ -1,15 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include -#include -#include #include #include "alloc-util.h" #include "bitmap.h" -#include "hashmap.h" -#include "macro.h" #include "memory-util.h" /* Bitmaps are only meant to store relatively small numbers diff --git a/src/shared/bitmap.h b/src/shared/bitmap.h index e77e2e1f889..cb9a951235c 100644 --- a/src/shared/bitmap.h +++ b/src/shared/bitmap.h @@ -1,10 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "hashmap.h" -#include "macro.h" +#include "forward.h" +#include "iterator.h" typedef struct Bitmap { uint64_t *bitmaps; diff --git a/src/shared/blkid-util.c b/src/shared/blkid-util.c index 5446eb0f916..34953ce2a48 100644 --- a/src/shared/blkid-util.c +++ b/src/shared/blkid-util.c @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ - #if HAVE_BLKID -#include +#include "sd-id128.h" #include "blkid-util.h" #include "string-util.h" diff --git a/src/shared/blkid-util.h b/src/shared/blkid-util.h index fab4ab29870..502b8670240 100644 --- a/src/shared/blkid-util.h +++ b/src/shared/blkid-util.h @@ -5,9 +5,7 @@ #include -#include "sd-id128.h" - -#include "memory-util.h" +#include "forward.h" DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(blkid_probe, blkid_free_probe, NULL); diff --git a/src/shared/blockdev-list.c b/src/shared/blockdev-list.c index 4c43fb67622..0e7cd99fad2 100644 --- a/src/shared/blockdev-list.c +++ b/src/shared/blockdev-list.c @@ -6,7 +6,6 @@ #include "blockdev-list.h" #include "blockdev-util.h" #include "device-util.h" -#include "macro.h" #include "strv.h" #include "terminal-util.h" diff --git a/src/shared/blockdev-list.h b/src/shared/blockdev-list.h index 7fbf824ab2c..f569cf22e36 100644 --- a/src/shared/blockdev-list.h +++ b/src/shared/blockdev-list.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "forward.h" + typedef enum BlockDevListFlags { BLOCKDEV_LIST_SHOW_SYMLINKS = 1 << 0, BLOCKDEV_LIST_REQUIRE_PARTITION_SCANNING = 1 << 1, diff --git a/src/shared/blockdev-util.c b/src/shared/blockdev-util.c index b5c82aaccd6..42a5c08b729 100644 --- a/src/shared/blockdev-util.c +++ b/src/shared/blockdev-util.c @@ -1,9 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include #include -#include +#include #include #include "sd-device.h" @@ -19,8 +20,9 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" -#include "missing_magic.h" #include "parse-util.h" +#include "path-util.h" +#include "string-util.h" static int fd_get_devnum(int fd, BlockDeviceLookupFlag flags, dev_t *ret) { struct stat st; diff --git a/src/shared/blockdev-util.h b/src/shared/blockdev-util.h index df52d78c59e..8bb890aefbb 100644 --- a/src/shared/blockdev-util.h +++ b/src/shared/blockdev-util.h @@ -1,13 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include -#include "sd-device.h" - -#include "macro.h" +#include "forward.h" #include "stdio-util.h" -#include "string-util.h" #define SYS_BLOCK_PATH_MAX(suffix) \ (STRLEN("/sys/dev/block/") + DECIMAL_STR_MAX(dev_t) + 1 + DECIMAL_STR_MAX(dev_t) + STRLEN(suffix)) diff --git a/src/shared/bond-util.h b/src/shared/bond-util.h index 84b18942ee6..11fefedc27c 100644 --- a/src/shared/bond-util.h +++ b/src/shared/bond-util.h @@ -1,11 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include #include -#include -#include "macro.h" +#include "forward.h" /* * Maximum number of targets supported by the kernel for a single diff --git a/src/shared/boot-entry.c b/src/shared/boot-entry.c index cbade699a22..3288d0de597 100644 --- a/src/shared/boot-entry.c +++ b/src/shared/boot-entry.c @@ -5,7 +5,6 @@ #include "chase.h" #include "fd-util.h" #include "fileio.h" -#include "id128-util.h" #include "log.h" #include "os-util.h" #include "path-util.h" diff --git a/src/shared/boot-entry.h b/src/shared/boot-entry.h index 836b63733a9..927802e5eee 100644 --- a/src/shared/boot-entry.h +++ b/src/shared/boot-entry.h @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - #include "sd-id128.h" +#include "forward.h" + typedef enum BootEntryTokenType { BOOT_ENTRY_TOKEN_MACHINE_ID, BOOT_ENTRY_TOKEN_OS_IMAGE_ID, diff --git a/src/shared/boot-timestamps.c b/src/shared/boot-timestamps.c index e49bd8f1f2c..06313ac06a7 100644 --- a/src/shared/boot-timestamps.c +++ b/src/shared/boot-timestamps.c @@ -3,7 +3,6 @@ #include "acpi-fpdt.h" #include "boot-timestamps.h" #include "efi-loader.h" -#include "macro.h" #include "time-util.h" int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader) { diff --git a/src/shared/boot-timestamps.h b/src/shared/boot-timestamps.h index 55b7ad19aa7..9ccbeb2c047 100644 --- a/src/shared/boot-timestamps.h +++ b/src/shared/boot-timestamps.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int boot_timestamps(const dual_timestamp *n, dual_timestamp *firmware, dual_timestamp *loader); diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index a22bc706232..f57a3d57407 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -3,16 +3,18 @@ #include #include +#include "sd-json.h" + #include "alloc-util.h" #include "bootspec.h" #include "bootspec-fundamental.h" #include "chase.h" -#include "conf-files.h" #include "devnum-util.h" #include "dirent-util.h" #include "efi-loader.h" +#include "efivars.h" #include "env-file.h" -#include "errno-util.h" +#include "extract-word.h" #include "fd-util.h" #include "fileio.h" #include "find-esp.h" @@ -22,13 +24,13 @@ #include "pe-binary.h" #include "pretty-print.h" #include "recurse-dir.h" +#include "set.h" #include "sort-util.h" #include "stat-util.h" #include "string-table.h" +#include "string-util.h" #include "strv.h" -#include "terminal-util.h" #include "uki.h" -#include "unaligned.h" static const char* const boot_entry_type_table[_BOOT_ENTRY_TYPE_MAX] = { [BOOT_ENTRY_CONF] = "Boot Loader Specification Type #1 (.conf)", diff --git a/src/shared/bootspec.h b/src/shared/bootspec.h index a574a0be93c..e0c561808c7 100644 --- a/src/shared/bootspec.h +++ b/src/shared/bootspec.h @@ -2,15 +2,7 @@ #pragma once -#include -#include -#include -#include - -#include "sd-json.h" - -#include "set.h" -#include "string-util.h" +#include "forward.h" typedef enum BootEntryType { BOOT_ENTRY_CONF, /* Boot Loader Specification Type #1 entries: *.conf files */ diff --git a/src/shared/bpf-dlopen.c b/src/shared/bpf-dlopen.c index 5a3b0b6cb3c..5f5402609bf 100644 --- a/src/shared/bpf-dlopen.c +++ b/src/shared/bpf-dlopen.c @@ -3,7 +3,6 @@ #include "bpf-dlopen.h" #include "dlfcn-util.h" #include "log.h" -#include "strv.h" #if HAVE_LIBBPF diff --git a/src/shared/bpf-dlopen.h b/src/shared/bpf-dlopen.h index bb78312363f..639c1128946 100644 --- a/src/shared/bpf-dlopen.h +++ b/src/shared/bpf-dlopen.h @@ -1,16 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include #include #if HAVE_LIBBPF -#include -#include +#include /* IWYU pragma: export */ +#include /* IWYU pragma: export */ -#include "bpf-compat.h" +#include "bpf-compat.h" /* IWYU pragma: export */ #include "dlfcn-util.h" +#include "forward.h" extern DLSYM_PROTOTYPE(bpf_link__destroy); extern DLSYM_PROTOTYPE(bpf_link__fd); diff --git a/src/shared/bpf-link.h b/src/shared/bpf-link.h index 53711e49053..acd64f88eb7 100644 --- a/src/shared/bpf-link.h +++ b/src/shared/bpf-link.h @@ -1,14 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ - #pragma once #if HAVE_LIBBPF -#include #include -#include "fdset.h" -#include "macro.h" +#include "forward.h" bool bpf_can_link_program(struct bpf_program *prog); diff --git a/src/shared/bpf-program.c b/src/shared/bpf-program.c index 83af54ec681..d369b008fd2 100644 --- a/src/shared/bpf-program.c +++ b/src/shared/bpf-program.c @@ -1,22 +1,26 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include -#include -#include #include #include "alloc-util.h" #include "bpf-program.h" #include "errno-util.h" #include "escape.h" +#include "extract-word.h" #include "fd-util.h" +#include "fdset.h" +#include "log.h" #include "memory-util.h" #include "missing_syscall.h" #include "parse-util.h" #include "path-util.h" #include "serialize.h" +#include "set.h" #include "string-table.h" +#include "string-util.h" static const char *const bpf_cgroup_attach_type_table[__MAX_BPF_ATTACH_TYPE] = { [BPF_CGROUP_INET_INGRESS] = "ingress", diff --git a/src/shared/bpf-program.h b/src/shared/bpf-program.h index e820ed8196d..3b3aae4a75b 100644 --- a/src/shared/bpf-program.h +++ b/src/shared/bpf-program.h @@ -1,22 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include - -#include "fdset.h" -#include "list.h" -#include "macro.h" - -typedef struct BPFProgram BPFProgram; +#include "forward.h" /* This encapsulates three different concepts: the loaded BPF program, the BPF code, and the attachment to a * cgroup. Typically our BPF programs go through all three stages: we build the code, we load it, and finally * we attach it, but it might happen that we operate with programs that aren't loaded or aren't attached, or * where we don't have the code. */ -struct BPFProgram { +typedef struct BPFProgram { /* The loaded BPF program, if loaded */ int kernel_fd; uint32_t prog_type; @@ -31,7 +22,7 @@ struct BPFProgram { char *attached_path; int attached_type; uint32_t attached_flags; -}; +} BPFProgram; int bpf_program_supported(void); diff --git a/src/shared/bridge-util.h b/src/shared/bridge-util.h index 1ea7b93394c..c23a3acf069 100644 --- a/src/shared/bridge-util.h +++ b/src/shared/bridge-util.h @@ -2,9 +2,8 @@ #pragma once #include -#include -#include "conf-parser.h" +#include "forward.h" typedef enum BridgeState { NETDEV_BRIDGE_STATE_DISABLED = BR_STATE_DISABLED, diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 0615b27a02a..61fe50e012a 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -1,37 +1,26 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include #include #include -#include #include -#include #include -#include #include #include #include #include #include "alloc-util.h" -#include "blockdev-util.h" #include "btrfs-util.h" #include "chase.h" #include "chattr-util.h" #include "copy.h" #include "errno-util.h" #include "fd-util.h" -#include "fileio.h" #include "fs-util.h" -#include "io-util.h" #include "log.h" -#include "macro.h" -#include "missing_fs.h" #include "path-util.h" #include "rm-rf.h" -#include "smack-util.h" #include "sparse-endian.h" #include "stat-util.h" #include "string-util.h" @@ -1904,6 +1893,16 @@ int btrfs_subvol_get_parent(int fd, uint64_t subvol_id, uint64_t *ret) { return -ENXIO; } +bool btrfs_might_be_subvol(const struct stat *st) { + if (!st) + return false; + + /* Returns true if this 'struct stat' looks like it could refer to a btrfs subvolume. To make a final + * decision, needs to be combined with an fstatfs() check to see if this is actually btrfs. */ + + return S_ISDIR(st->st_mode) && st->st_ino == 256; +} + int btrfs_forget_device(const char *path) { _cleanup_close_ int control_fd = -EBADF; struct btrfs_ioctl_vol_args args = {}; diff --git a/src/shared/btrfs-util.h b/src/shared/btrfs-util.h index 58380029b09..44438bbaf3f 100644 --- a/src/shared/btrfs-util.h +++ b/src/shared/btrfs-util.h @@ -1,15 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - #include "sd-id128.h" -#include "btrfs.h" -#include "copy.h" -#include "time-util.h" +#include "btrfs.h" /* IWYU pragma: export */ +#include "forward.h" typedef struct BtrfsSubvolInfo { uint64_t subvol_id; @@ -132,15 +127,7 @@ int btrfs_qgroup_get_quota(const char *path, uint64_t qgroupid, BtrfsQuotaInfo * int btrfs_log_dev_root(int level, int ret, const char *p); -static inline bool btrfs_might_be_subvol(const struct stat *st) { - if (!st) - return false; - - /* Returns true if this 'struct stat' looks like it could refer to a btrfs subvolume. To make a final - * decision, needs to be combined with an fstatfs() check to see if this is actually btrfs. */ - - return S_ISDIR(st->st_mode) && st->st_ino == 256; -} +bool btrfs_might_be_subvol(const struct stat *st); int btrfs_forget_device(const char *path); diff --git a/src/shared/bus-get-properties.c b/src/shared/bus-get-properties.c index 5be6bbc9067..e21eafc4baf 100644 --- a/src/shared/bus-get-properties.c +++ b/src/shared/bus-get-properties.c @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "bus-get-properties.h" #include "bus-message-util.h" -#include "log.h" #include "rlimit-util.h" -#include "stdio-util.h" #include "string-util.h" BUS_DEFINE_PROPERTY_GET_GLOBAL(bus_property_get_bool_false, "b", 0); diff --git a/src/shared/bus-get-properties.h b/src/shared/bus-get-properties.h index 95eab4a4bf1..a77d3653bea 100644 --- a/src/shared/bus-get-properties.h +++ b/src/shared/bus-get-properties.h @@ -3,7 +3,7 @@ #include "sd-bus.h" -#include "macro.h" +#include "forward.h" int bus_property_get_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); int bus_property_set_bool(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error); diff --git a/src/shared/bus-locator.c b/src/shared/bus-locator.c index 9ceb976b0b6..a310f61bb98 100644 --- a/src/shared/bus-locator.c +++ b/src/shared/bus-locator.c @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "assert-util.h" +#include "sd-bus.h" + #include "bus-locator.h" -#include "macro.h" const BusLocator* const bus_home_mgr = &(BusLocator){ .destination = "org.freedesktop.home1", diff --git a/src/shared/bus-locator.h b/src/shared/bus-locator.h index 8116aa27c0a..467bc2b344c 100644 --- a/src/shared/bus-locator.h +++ b/src/shared/bus-locator.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" +#include "forward.h" typedef struct BusLocator { const char *destination; diff --git a/src/shared/bus-log-control-api.c b/src/shared/bus-log-control-api.c index ad667d0e64a..6ff7a3c04fc 100644 --- a/src/shared/bus-log-control-api.c +++ b/src/shared/bus-log-control-api.c @@ -5,10 +5,14 @@ #include "alloc-util.h" #include "bus-get-properties.h" #include "bus-log-control-api.h" -#include "bus-util.h" +#include "bus-object.h" #include "log.h" #include "syslog-util.h" +int bus_log_control_api_register(sd_bus *bus) { + return bus_add_implementation(bus, &log_control_object, NULL); +} + int bus_property_get_log_level( sd_bus *bus, const char *path, diff --git a/src/shared/bus-log-control-api.h b/src/shared/bus-log-control-api.h index 85f60a7a2f0..76647da0266 100644 --- a/src/shared/bus-log-control-api.h +++ b/src/shared/bus-log-control-api.h @@ -1,14 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "bus-object.h" +#include "forward.h" extern const BusObjectImplementation log_control_object; -static inline int bus_log_control_api_register(sd_bus *bus) { - return bus_add_implementation(bus, &log_control_object, NULL); -} + +int bus_log_control_api_register(sd_bus *bus); int bus_property_get_log_level(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *reply, void *userdata, sd_bus_error *error); int bus_property_set_log_level(sd_bus *bus, const char *path, const char *interface, const char *property, sd_bus_message *value, void *userdata, sd_bus_error *error); diff --git a/src/shared/bus-map-properties.c b/src/shared/bus-map-properties.c index c2af0498ba1..1a7f88c5f66 100644 --- a/src/shared/bus-map-properties.c +++ b/src/shared/bus-map-properties.c @@ -1,11 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "alloc-util.h" +#include "sd-bus.h" + #include "bus-map-properties.h" -#include "bus-message.h" #include "bus-message-util.h" #include "bus-util.h" -#include "log.h" +#include "string-util.h" #include "strv.h" int bus_map_id128(sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata) { diff --git a/src/shared/bus-map-properties.h b/src/shared/bus-map-properties.h index 183e9722f1e..4c36f572f2c 100644 --- a/src/shared/bus-map-properties.h +++ b/src/shared/bus-map-properties.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" +#include "forward.h" typedef int (*bus_property_set_t) (sd_bus *bus, const char *member, sd_bus_message *m, sd_bus_error *error, void *userdata); diff --git a/src/shared/bus-message-util.c b/src/shared/bus-message-util.c index 20a0d0eb779..dd939a67525 100644 --- a/src/shared/bus-message-util.c +++ b/src/shared/bus-message-util.c @@ -2,11 +2,16 @@ #include +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-message-util.h" #include "bus-util.h" #include "copy.h" +#include "in-addr-util.h" #include "resolve-util.h" +#include "set.h" +#include "socket-netlink.h" int bus_message_read_id128(sd_bus_message *m, sd_id128_t *ret) { const void *a; diff --git a/src/shared/bus-message-util.h b/src/shared/bus-message-util.h index 02c670695e4..3580c843c45 100644 --- a/src/shared/bus-message-util.h +++ b/src/shared/bus-message-util.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "in-addr-util.h" -#include "set.h" -#include "socket-netlink.h" +#include "forward.h" int bus_message_read_id128(sd_bus_message *m, sd_id128_t *ret); diff --git a/src/shared/bus-object.c b/src/shared/bus-object.c index 1fa97a1ff2b..bc5995a67f9 100644 --- a/src/shared/bus-object.c +++ b/src/shared/bus-object.c @@ -1,10 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-introspect.h" #include "bus-object.h" #include "log.h" -#include "macro.h" +#include "ordered-set.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/bus-object.h b/src/shared/bus-object.h index 145bbd268f5..2cdade79135 100644 --- a/src/shared/bus-object.h +++ b/src/shared/bus-object.h @@ -1,19 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "sd-bus.h" - -typedef struct BusObjectImplementation BusObjectImplementation; +#include "forward.h" typedef struct BusObjectVtablePair { const sd_bus_vtable *vtable; sd_bus_object_find_t object_find; } BusObjectVtablePair; -struct BusObjectImplementation { +typedef struct BusObjectImplementation { const char *path; const char *interface; const sd_bus_vtable **vtables; @@ -21,7 +16,7 @@ struct BusObjectImplementation { sd_bus_node_enumerator_t node_enumerator; bool manager; const BusObjectImplementation **children; -}; +} BusObjectImplementation; #define BUS_VTABLES(...) ((const sd_bus_vtable* []){ __VA_ARGS__, NULL }) #define BUS_FALLBACK_VTABLES(...) ((const BusObjectVtablePair[]) { __VA_ARGS__, {} }) diff --git a/src/shared/bus-polkit.c b/src/shared/bus-polkit.c index 99d99a5bbb7..93a3c7e6a4e 100644 --- a/src/shared/bus-polkit.c +++ b/src/shared/bus-polkit.c @@ -1,13 +1,18 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "bus-internal.h" +#include "sd-bus.h" +#include "sd-event.h" + #include "bus-message.h" #include "bus-polkit.h" #include "bus-util.h" +#include "errno-util.h" +#include "hashmap.h" +#include "list.h" #include "log.h" -#include "process-util.h" +#include "pidref.h" +#include "string-util.h" #include "strv.h" -#include "user-util.h" #include "varlink-util.h" static int bus_message_check_good_user(sd_bus_message *m, uid_t good_user) { diff --git a/src/shared/bus-polkit.h b/src/shared/bus-polkit.h index 7f6f21b51e6..893ce635ead 100644 --- a/src/shared/bus-polkit.h +++ b/src/shared/bus-polkit.h @@ -1,11 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" +#include "sd-json.h" #include "sd-varlink.h" -#include "hashmap.h" -#include "user-util.h" +#include "forward.h" typedef enum PolkitFlags { POLKIT_ALLOW_INTERACTIVE = 1 << 0, /* Allow interactive auth (typically not required, because can be derived from bus message/link automatically) */ diff --git a/src/shared/bus-print-properties.c b/src/shared/bus-print-properties.c index ec7e2c95439..5ea670599a3 100644 --- a/src/shared/bus-print-properties.c +++ b/src/shared/bus-print-properties.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-print-properties.h" #include "cap-list.h" @@ -9,11 +11,10 @@ #include "mountpoint-util.h" #include "nsflags.h" #include "parse-util.h" -#include "stdio-util.h" +#include "set.h" #include "string-util.h" #include "strv.h" #include "time-util.h" -#include "user-util.h" int bus_print_property_value(const char *name, const char *expected_value, BusPrintPropertyFlags flags, const char *value) { assert(name); diff --git a/src/shared/bus-print-properties.h b/src/shared/bus-print-properties.h index a17875cc47c..9bbf8a9eceb 100644 --- a/src/shared/bus-print-properties.h +++ b/src/shared/bus-print-properties.h @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-bus.h" - -#include "macro.h" -#include "set.h" +#include "forward.h" typedef enum BusPrintPropertyFlags { BUS_PRINT_PROPERTY_ONLY_VALUE = 1 << 0, /* e.g. systemctl --value */ diff --git a/src/shared/bus-unit-procs.c b/src/shared/bus-unit-procs.c index c47b8b23b46..cfdfb736f7e 100644 --- a/src/shared/bus-unit-procs.c +++ b/src/shared/bus-unit-procs.c @@ -1,13 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "ansi-color.h" #include "bus-locator.h" #include "bus-unit-procs.h" +#include "format-util.h" #include "glyph-util.h" #include "hashmap.h" #include "list.h" #include "log.h" -#include "macro.h" +#include "output-mode.h" #include "path-util.h" #include "process-util.h" #include "sort-util.h" diff --git a/src/shared/bus-unit-procs.h b/src/shared/bus-unit-procs.h index 78c55697aea..e112ef5daba 100644 --- a/src/shared/bus-unit-procs.h +++ b/src/shared/bus-unit-procs.h @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "output-mode.h" +#include "forward.h" int unit_show_processes(sd_bus *bus, const char *unit, const char *cgroup_path, const char *prefix, unsigned n_columns, OutputFlags flags, sd_bus_error *error); diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 63478664535..328caca3396 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -1,6 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "af-list.h" +#include +#include + +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-common-errors.h" #include "bus-error.h" @@ -11,24 +15,21 @@ #include "cgroup-setup.h" #include "cgroup-util.h" #include "condition.h" +#include "constants.h" #include "coredump-util.h" #include "cpu-set-util.h" -#include "dissect-image.h" #include "escape.h" #include "exec-util.h" #include "exit-status.h" -#include "fileio.h" +#include "extract-word.h" #include "firewall-util.h" #include "hexdecoct.h" #include "hostname-util.h" #include "in-addr-util.h" +#include "install.h" #include "ioprio-util.h" #include "ip-protocol-list.h" -#include "libmount-util.h" -#include "locale-util.h" #include "log.h" -#include "macro.h" -#include "missing_fs.h" #include "mountpoint-util.h" #include "nsflags.h" #include "numa-util.h" @@ -37,20 +38,17 @@ #include "parse-util.h" #include "path-util.h" #include "percent-util.h" +#include "pidref.h" #include "process-util.h" #include "rlimit-util.h" #include "seccomp-util.h" #include "securebits-util.h" #include "signal-util.h" #include "socket-util.h" -#include "sort-util.h" -#include "stdio-util.h" #include "string-util.h" #include "syslog-util.h" -#include "terminal-util.h" +#include "time-util.h" #include "unit-def.h" -#include "user-util.h" -#include "utf8.h" int bus_parse_unit_info(sd_bus_message *message, UnitInfo *u) { assert(message); diff --git a/src/shared/bus-unit-util.h b/src/shared/bus-unit-util.h index 8090b36e3d5..ba3115c0806 100644 --- a/src/shared/bus-unit-util.h +++ b/src/shared/bus-unit-util.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "install.h" -#include "pidref.h" -#include "unit-def.h" +#include "forward.h" typedef enum ExecDirectoryFlags { EXEC_DIRECTORY_READ_ONLY = 1 << 0, /* Public API via DBUS, do not change */ diff --git a/src/shared/bus-util.c b/src/shared/bus-util.c index c3b1a01c1a2..89d96a4045c 100644 --- a/src/shared/bus-util.c +++ b/src/shared/bus-util.c @@ -1,12 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include +#include #include -#include -#include #include +#include #include #include "sd-bus.h" @@ -23,16 +21,20 @@ #include "chase.h" #include "daemon-util.h" #include "env-util.h" +#include "errno-util.h" #include "fd-util.h" #include "format-util.h" #include "log.h" #include "memfd-util.h" #include "memstream-util.h" #include "path-util.h" +#include "pidref.h" #include "socket-util.h" #include "stdio-util.h" #include "string-table.h" +#include "string-util.h" #include "strv.h" +#include "time-util.h" #include "uid-classification.h" static int name_owner_change_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { @@ -64,6 +66,10 @@ int bus_log_connect_full(int log_level, int r, BusTransport transport, RuntimeSc "Failed to connect to %s scope bus via %s transport: %m", runtime_scope_to_string(scope), bus_transport_to_string(transport)); } +int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) { + return bus_log_connect_full(LOG_ERR, r, transport, scope); +} + int bus_async_unregister_and_exit(sd_event *e, sd_bus *bus, const char *name) { const char *match; const char *unique; diff --git a/src/shared/bus-util.h b/src/shared/bus-util.h index 7f890e4b9f2..5f160ffcafd 100644 --- a/src/shared/bus-util.h +++ b/src/shared/bus-util.h @@ -1,22 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include +#include "sd-bus.h" /* IWYU pragma: export */ -#include "sd-bus.h" -#include "sd-event.h" - -#include "errno-util.h" #include "log.h" -#include "macro.h" -#include "pidref.h" -#include "runtime-scope.h" -#include "set.h" -#include "string-util.h" -#include "time-util.h" +#include "forward.h" typedef enum BusTransport { BUS_TRANSPORT_LOCAL, @@ -50,9 +38,7 @@ int bus_connect_transport_systemd(BusTransport transport, const char *host, Runt int bus_log_address_error(int r, BusTransport transport); int bus_log_connect_full(int log_level, int r, BusTransport transport, RuntimeScope scope); -static inline int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope) { - return bus_log_connect_full(LOG_ERR, r, transport, scope); -} +int bus_log_connect_error(int r, BusTransport transport, RuntimeScope scope); #define bus_log_parse_error(r) \ log_error_errno(r, "Failed to parse bus message: %m") diff --git a/src/shared/bus-wait-for-jobs.c b/src/shared/bus-wait-for-jobs.c index f58422777df..2526e2511fc 100644 --- a/src/shared/bus-wait-for-jobs.c +++ b/src/shared/bus-wait-for-jobs.c @@ -1,12 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-internal.h" #include "bus-util.h" #include "bus-wait-for-jobs.h" +#include "errno-util.h" #include "escape.h" #include "log.h" #include "set.h" +#include "string-util.h" #include "strv.h" #include "unit-def.h" diff --git a/src/shared/bus-wait-for-jobs.h b/src/shared/bus-wait-for-jobs.h index ff15ede19cd..bce4f25ac20 100644 --- a/src/shared/bus-wait-for-jobs.h +++ b/src/shared/bus-wait-for-jobs.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "macro.h" -#include "memory-util.h" +#include "forward.h" typedef struct BusWaitForJobs BusWaitForJobs; diff --git a/src/shared/bus-wait-for-units.c b/src/shared/bus-wait-for-units.c index 8cb2d8ded4d..9730a6c738e 100644 --- a/src/shared/bus-wait-for-units.c +++ b/src/shared/bus-wait-for-units.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-error.h" #include "bus-map-properties.h" @@ -7,7 +9,6 @@ #include "hashmap.h" #include "log.h" #include "string-util.h" -#include "strv.h" #include "unit-def.h" typedef struct WaitForItem { diff --git a/src/shared/bus-wait-for-units.h b/src/shared/bus-wait-for-units.h index 29725e9adb5..eed7fd1f4b4 100644 --- a/src/shared/bus-wait-for-units.h +++ b/src/shared/bus-wait-for-units.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-bus.h" - -#include "macro.h" -#include "memory-util.h" +#include "forward.h" typedef struct BusWaitForUnits BusWaitForUnits; diff --git a/src/shared/calendarspec.c b/src/shared/calendarspec.c index c95898507c1..3569f15db4f 100644 --- a/src/shared/calendarspec.c +++ b/src/shared/calendarspec.c @@ -1,9 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include -#include -#include #include #include #include @@ -12,10 +8,7 @@ #include "alloc-util.h" #include "calendarspec.h" #include "errno-util.h" -#include "fd-util.h" -#include "fileio.h" #include "log.h" -#include "macro.h" #include "memstream-util.h" #include "parse-util.h" #include "process-util.h" diff --git a/src/shared/calendarspec.h b/src/shared/calendarspec.h index 9a8bdbd21ac..2289d9cfed1 100644 --- a/src/shared/calendarspec.h +++ b/src/shared/calendarspec.h @@ -4,10 +4,7 @@ /* A structure for specifying (possibly repetitive) points in calendar * time, a la cron */ -#include - -#include "memory-util.h" -#include "time-util.h" +#include "forward.h" typedef struct CalendarComponent { int start; diff --git a/src/shared/cgroup-setup.c b/src/shared/cgroup-setup.c index d804a7746bb..8e6cb55427f 100644 --- a/src/shared/cgroup-setup.c +++ b/src/shared/cgroup-setup.c @@ -7,6 +7,7 @@ #include "errno-util.h" #include "fd-util.h" #include "fileio.h" +#include "format-util.h" #include "fs-util.h" #include "log.h" #include "missing_magic.h" @@ -15,6 +16,8 @@ #include "path-util.h" #include "process-util.h" #include "recurse-dir.h" +#include "set.h" +#include "stat-util.h" #include "stdio-util.h" #include "string-util.h" #include "user-util.h" diff --git a/src/shared/cgroup-setup.h b/src/shared/cgroup-setup.h index 5e654426a6d..4cc5c9f4cc2 100644 --- a/src/shared/cgroup-setup.h +++ b/src/shared/cgroup-setup.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - -#include "cgroup-util.h" +#include "forward.h" int cg_weight_parse(const char *s, uint64_t *ret); int cg_cpu_weight_parse(const char *s, uint64_t *ret); diff --git a/src/shared/cgroup-show.c b/src/shared/cgroup-show.c index 0331ce23236..258229daf3d 100644 --- a/src/shared/cgroup-show.c +++ b/src/shared/cgroup-show.c @@ -1,10 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include -#include #include -#include + +#include "sd-bus.h" #include "alloc-util.h" #include "ansi-color.h" @@ -16,19 +15,18 @@ #include "escape.h" #include "fd-util.h" #include "format-util.h" +#include "glyph-util.h" #include "hostname-util.h" -#include "locale-util.h" #include "log.h" -#include "macro.h" #include "nulstr-util.h" #include "output-mode.h" -#include "parse-util.h" #include "path-util.h" #include "process-util.h" +#include "runtime-scope.h" #include "sort-util.h" #include "string-util.h" #include "terminal-util.h" -#include "unit-name.h" +#include "unit-def.h" #include "xattr-util.h" static void show_pid_array( diff --git a/src/shared/cgroup-show.h b/src/shared/cgroup-show.h index db3c9c9cd0f..9dd81d59334 100644 --- a/src/shared/cgroup-show.h +++ b/src/shared/cgroup-show.h @@ -1,13 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "sd-bus.h" - -#include "logs-show.h" -#include "output-mode.h" +#include "forward.h" int show_cgroup_by_path(const char *path, const char *prefix, size_t n_columns, OutputFlags flags); int show_cgroup(const char *controller, const char *path, const char *prefix, size_t n_columns, OutputFlags flags); diff --git a/src/shared/chown-recursive.c b/src/shared/chown-recursive.c index 1bd2bb57057..73e8b98871f 100644 --- a/src/shared/chown-recursive.c +++ b/src/shared/chown-recursive.c @@ -2,15 +2,13 @@ #include #include -#include #include "chown-recursive.h" #include "dirent-util.h" #include "errno-util.h" #include "fd-util.h" #include "fs-util.h" -#include "macro.h" -#include "stdio-util.h" +#include "path-util.h" #include "strv.h" #include "user-util.h" #include "xattr-util.h" diff --git a/src/shared/chown-recursive.h b/src/shared/chown-recursive.h index 2aab8e74142..8bf8a80d6b3 100644 --- a/src/shared/chown-recursive.h +++ b/src/shared/chown-recursive.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int path_chown_recursive(const char *path, uid_t uid, gid_t gid, mode_t mask, int flags); diff --git a/src/shared/clean-ipc.c b/src/shared/clean-ipc.c index f4afa746d5d..28ee195e0d1 100644 --- a/src/shared/clean-ipc.c +++ b/src/shared/clean-ipc.c @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include #include -#include #include #include #include @@ -20,9 +17,7 @@ #include "fileio.h" #include "format-util.h" #include "log.h" -#include "macro.h" -#include "string-util.h" -#include "strv.h" +#include "path-util.h" #include "user-util.h" static bool match_uid_gid(uid_t subject_uid, gid_t subject_gid, uid_t delete_uid, gid_t delete_gid) { diff --git a/src/shared/clean-ipc.h b/src/shared/clean-ipc.h index ed348fb6014..a1f8b9ec638 100644 --- a/src/shared/clean-ipc.h +++ b/src/shared/clean-ipc.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "user-util.h" +#include "forward.h" int clean_ipc_internal(uid_t uid, gid_t gid, bool rm); diff --git a/src/shared/clock-util.c b/src/shared/clock-util.c index 8ab2d4ca95f..edd2669d037 100644 --- a/src/shared/clock-util.c +++ b/src/shared/clock-util.c @@ -1,16 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include "alloc-util.h" #include "clock-util.h" -#include "errno-util.h" #include "fd-util.h" #include "fileio.h" -#include "macro.h" #include "string-util.h" +#include "time-util.h" int clock_is_localtime(const char *adjtime_path) { int r; diff --git a/src/shared/color-util.c b/src/shared/color-util.c index e8258de95d1..19127859547 100644 --- a/src/shared/color-util.c +++ b/src/shared/color-util.c @@ -2,9 +2,7 @@ #include -#include "assert-util.h" #include "color-util.h" -#include "macro.h" void rgb_to_hsv(double r, double g, double b, double *ret_h, double *ret_s, double *ret_v) { diff --git a/src/shared/color-util.h b/src/shared/color-util.h index a4ae9eba09f..1816b7971c0 100644 --- a/src/shared/color-util.h +++ b/src/shared/color-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" void rgb_to_hsv(double r, double g, double b, double *ret_h, double *ret_s, double *ret_v); diff --git a/src/shared/common-signal.c b/src/shared/common-signal.c index e3f92503618..cbc17778d76 100644 --- a/src/shared/common-signal.c +++ b/src/shared/common-signal.c @@ -1,12 +1,18 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include +#include + +#include "sd-event.h" + +#include "alloc-util.h" #include "common-signal.h" -#include "fd-util.h" -#include "fileio.h" +#include "format-util.h" #include "log.h" #include "memstream-util.h" #include "process-util.h" #include "signal-util.h" +#include "string-util.h" int sigrtmin18_handler(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) { struct sigrtmin18_info *info = userdata; diff --git a/src/shared/common-signal.h b/src/shared/common-signal.h index 3fd7d832991..07bc4c5f000 100644 --- a/src/shared/common-signal.h +++ b/src/shared/common-signal.h @@ -3,7 +3,7 @@ #include -#include "sd-event.h" +#include "forward.h" /* All our long-running services should implement a SIGRTMIN+18 handler that can be used to trigger certain * actions that affect service runtime. The specific action is indicated via the "value integer" you can pass diff --git a/src/shared/compare-operator.h b/src/shared/compare-operator.h index 900f3e54b20..aa19835fd0d 100644 --- a/src/shared/compare-operator.h +++ b/src/shared/compare-operator.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "forward.h" #define COMPARE_OPERATOR_CHARS "!<=>" #define COMPARE_OPERATOR_WITH_FNMATCH_CHARS COMPARE_OPERATOR_CHARS "$" diff --git a/src/shared/condition.c b/src/shared/condition.c index 63acf3906c6..61f900c59d8 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -1,14 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include #include -#include -#include #include -#include #include #include #include @@ -29,8 +24,8 @@ #include "confidential-virt.h" #include "cpu-set-util.h" #include "creds-util.h" -#include "efi-api.h" #include "efi-loader.h" +#include "efivars.h" #include "env-file.h" #include "env-util.h" #include "extract-word.h" @@ -39,20 +34,20 @@ #include "fs-util.h" #include "glob-util.h" #include "hostname-setup.h" -#include "hostname-util.h" #include "id128-util.h" #include "ima-util.h" #include "initrd-util.h" #include "libaudit-util.h" #include "limits-util.h" #include "list.h" -#include "macro.h" +#include "log.h" #include "mountpoint-util.h" #include "nulstr-util.h" #include "os-util.h" #include "parse-util.h" #include "path-util.h" #include "percent-util.h" +#include "pidref.h" #include "proc-cmdline.h" #include "process-util.h" #include "psi-util.h" @@ -62,6 +57,8 @@ #include "stat-util.h" #include "string-table.h" #include "string-util.h" +#include "strv.h" +#include "time-util.h" #include "tomoyo-util.h" #include "tpm2-util.h" #include "uid-classification.h" diff --git a/src/shared/condition.h b/src/shared/condition.h index 0644ec28f51..a06d2a89d15 100644 --- a/src/shared/condition.h +++ b/src/shared/condition.h @@ -1,12 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - #include "list.h" -#include "macro.h" +#include "forward.h" typedef enum ConditionType { CONDITION_ARCHITECTURE, diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 2c5d6275a6f..5a2e253175c 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include -#include #include -#include -#include #include "sd-id128.h" @@ -29,7 +24,6 @@ #include "in-addr-prefix-util.h" #include "ip-protocol-list.h" #include "log.h" -#include "macro.h" #include "missing_network.h" #include "nulstr-util.h" #include "parse-helpers.h" @@ -40,6 +34,7 @@ #include "rlimit-util.h" #include "set.h" #include "signal-util.h" +#include "siphash24.h" #include "socket-util.h" #include "stat-util.h" #include "string-util.h" @@ -879,6 +874,22 @@ int _hashmap_by_section_find_unused_line( return 0; } +int hashmap_by_section_find_unused_line( + Hashmap *entries_by_section, + const char *filename, + unsigned *ret) { + + return _hashmap_by_section_find_unused_line(HASHMAP_BASE(entries_by_section), filename, ret); +} + +int ordered_hashmap_by_section_find_unused_line( + OrderedHashmap *entries_by_section, + const char *filename, + unsigned *ret) { + + return _hashmap_by_section_find_unused_line(HASHMAP_BASE(entries_by_section), filename, ret); +} + #define DEFINE_PARSER(type, vartype, conv_func) \ DEFINE_CONFIG_PARSE_PTR(config_parse_##type, conv_func, vartype) diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 2a60eb6ab82..e3f4666dfb7 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -1,17 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include -#include #include +#include "alloc-util.h" #include "conf-parser-forward.h" -#include "hashmap.h" +#include "forward.h" #include "log.h" -#include "memory-util.h" /* An abstract parser for simple, line based, shallow configuration files consisting of variable assignments only. */ @@ -159,18 +154,9 @@ int _hashmap_by_section_find_unused_line( HashmapBase *entries_by_section, const char *filename, unsigned *ret); -static inline int hashmap_by_section_find_unused_line( - Hashmap *entries_by_section, - const char *filename, - unsigned *ret) { - return _hashmap_by_section_find_unused_line(HASHMAP_BASE(entries_by_section), filename, ret); -} -static inline int ordered_hashmap_by_section_find_unused_line( - OrderedHashmap *entries_by_section, - const char *filename, - unsigned *ret) { - return _hashmap_by_section_find_unused_line(HASHMAP_BASE(entries_by_section), filename, ret); -} + +int hashmap_by_section_find_unused_line(Hashmap *entries_by_section, const char *filename, unsigned *ret); +int ordered_hashmap_by_section_find_unused_line(OrderedHashmap *entries_by_section, const char *filename, unsigned *ret); static inline bool section_is_invalid(ConfigSection *section) { /* If this returns false, then it does _not_ mean the section is valid. */ diff --git a/src/shared/copy.c b/src/shared/copy.c index 2f153a97326..08828856c0b 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -1,20 +1,15 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include -#include #include -#include #include #include #include #include -#include #include #include "alloc-util.h" -#include "btrfs-util.h" #include "chattr-util.h" #include "copy.h" #include "dirent-util.h" @@ -22,23 +17,19 @@ #include "fd-util.h" #include "fileio.h" #include "fs-util.h" -#include "io-util.h" +#include "hashmap.h" #include "log.h" -#include "macro.h" -#include "missing_fs.h" -#include "missing_syscall.h" -#include "mkdir-label.h" #include "mountpoint-util.h" #include "nulstr-util.h" +#include "path-util.h" #include "rm-rf.h" #include "selinux-util.h" #include "signal-util.h" #include "stat-util.h" +#include "set.h" #include "stdio-util.h" #include "string-util.h" -#include "strv.h" #include "sync-util.h" -#include "time-util.h" #include "tmpfile-util.h" #include "umask-util.h" #include "user-util.h" diff --git a/src/shared/copy.h b/src/shared/copy.h index 4eea560bed1..3efe877c4b9 100644 --- a/src/shared/copy.h +++ b/src/shared/copy.h @@ -1,15 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include -#include -#include -#include - -#include "set.h" +#include "forward.h" typedef enum CopyFlags { COPY_REFLINK = 1 << 0, /* Try to reflink */ diff --git a/src/shared/coredump-util.h b/src/shared/coredump-util.h index a72db4b4e55..cbf5678ed29 100644 --- a/src/shared/coredump-util.h +++ b/src/shared/coredump-util.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "macro.h" +#include "forward.h" typedef enum CoredumpFilter { COREDUMP_FILTER_PRIVATE_ANONYMOUS = 0, diff --git a/src/shared/cpu-set-util.c b/src/shared/cpu-set-util.c index 711e94ef452..1703da0ed2f 100644 --- a/src/shared/cpu-set-util.c +++ b/src/shared/cpu-set-util.c @@ -1,24 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include +#include #include "alloc-util.h" #include "cpu-set-util.h" -#include "dirent-util.h" -#include "errno-util.h" #include "extract-word.h" -#include "fd-util.h" #include "hexdecoct.h" #include "log.h" -#include "macro.h" -#include "memory-util.h" #include "parse-util.h" -#include "stat-util.h" #include "string-util.h" -#include "strv.h" char* cpu_set_to_string(const CPUSet *a) { _cleanup_free_ char *str = NULL; diff --git a/src/shared/cpu-set-util.h b/src/shared/cpu-set-util.h index d62b2d60e6d..e2ea839aa89 100644 --- a/src/shared/cpu-set-util.h +++ b/src/shared/cpu-set-util.h @@ -3,8 +3,7 @@ #include -#include "memory-util.h" -#include "missing_syscall.h" +#include "forward.h" /* This wraps the libc interface with a variable to keep the allocated size. */ typedef struct CPUSet { diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index 6e0149e92e7..55aeace3769 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -1,6 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include +#include +#include "efivars.h" +#include "time-util.h" #if HAVE_OPENSSL #include @@ -12,9 +16,7 @@ #include "alloc-util.h" #include "blockdev-util.h" -#include "capability-util.h" #include "chattr-util.h" -#include "constants.h" #include "copy.h" #include "creds-util.h" #include "efi-api.h" @@ -37,6 +39,7 @@ #include "recurse-dir.h" #include "sparse-endian.h" #include "stat-util.h" +#include "string-util.h" #include "tmpfile-util.h" #include "tpm2-util.h" #include "user-util.h" diff --git a/src/shared/creds-util.h b/src/shared/creds-util.h index 3b9580850cc..7124ecd8543 100644 --- a/src/shared/creds-util.h +++ b/src/shared/creds-util.h @@ -1,14 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - #include "sd-id128.h" #include "fd-util.h" -#include "time-util.h" +#include "forward.h" #define CREDENTIAL_NAME_MAX FDNAME_MAX diff --git a/src/shared/cryptsetup-fido2.c b/src/shared/cryptsetup-fido2.c index 8d4c1791837..8655acba3e7 100644 --- a/src/shared/cryptsetup-fido2.c +++ b/src/shared/cryptsetup-fido2.c @@ -2,16 +2,16 @@ #include "sd-json.h" +#include "alloc-util.h" #include "ask-password-api.h" #include "cryptsetup-fido2.h" +#include "cryptsetup-util.h" #include "env-util.h" #include "fido2-util.h" -#include "fileio.h" -#include "hexdecoct.h" #include "iovec-util.h" #include "libfido2-util.h" -#include "parse-util.h" -#include "random-util.h" +#include "log.h" + #include "strv.h" int acquire_fido2_key( @@ -32,6 +32,7 @@ int acquire_fido2_key( void **ret_decrypted_key, size_t *ret_decrypted_key_size) { +#if HAVE_LIBCRYPTSETUP && HAVE_LIBFIDO2 _cleanup_(erase_and_freep) char *envpw = NULL; _cleanup_strv_free_erase_ char **pins = NULL; _cleanup_(iovec_done_erase) struct iovec loaded_salt = {}; @@ -128,6 +129,9 @@ int acquire_fido2_key( askpw_flags &= ~ASK_PASSWORD_ACCEPT_CACHED; } +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "FIDO2 token support not available."); +#endif } int acquire_fido2_key_auto( @@ -141,6 +145,7 @@ int acquire_fido2_key_auto( void **ret_decrypted_key, size_t *ret_decrypted_key_size) { +#if HAVE_LIBCRYPTSETUP && HAVE_LIBFIDO2 _cleanup_free_ void *cid = NULL; size_t cid_size = 0; int r, ret = -ENOENT; @@ -276,4 +281,7 @@ int acquire_fido2_key_auto( log_info("Unlocked volume via automatically discovered security FIDO2 token."); return ret; +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "FIDO2 token support not available."); +#endif } diff --git a/src/shared/cryptsetup-fido2.h b/src/shared/cryptsetup-fido2.h index 3e08b79f7a0..63d46cd97fa 100644 --- a/src/shared/cryptsetup-fido2.h +++ b/src/shared/cryptsetup-fido2.h @@ -1,15 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "ask-password-api.h" -#include "cryptsetup-util.h" -#include "libfido2-util.h" -#include "log.h" -#include "time-util.h" - -#if HAVE_LIBFIDO2 +#include "forward.h" int acquire_fido2_key( const char *volume_name, @@ -39,43 +31,3 @@ int acquire_fido2_key_auto( AskPasswordFlags askpw_flags, void **ret_decrypted_key, size_t *ret_decrypted_key_size); - -#else - -static inline int acquire_fido2_key( - const char *volume_name, - const char *friendly_name, - const char *device, - const char *rp_id, - const void *cid, - size_t cid_size, - const char *key_file, - size_t key_file_size, - uint64_t key_file_offset, - const struct iovec *key_data, - usec_t until, - Fido2EnrollFlags required, - const char *askpw_credential, - AskPasswordFlags askpw_flags, - void **ret_decrypted_key, - size_t *ret_decrypted_key_size) { - - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "FIDO2 token support not available."); -} - -static inline int acquire_fido2_key_auto( - struct crypt_device *cd, - const char *name, - const char *friendly_name, - const char *fido2_device, - usec_t until, - const char *askpw_credential, - AskPasswordFlags askpw_flags, - void **ret_decrypted_key, - size_t *ret_decrypted_key_size) { - - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "FIDO2 token support not available."); -} -#endif diff --git a/src/shared/cryptsetup-tpm2.c b/src/shared/cryptsetup-tpm2.c index d7f2e545fd4..7fc0bf9fdd8 100644 --- a/src/shared/cryptsetup-tpm2.c +++ b/src/shared/cryptsetup-tpm2.c @@ -5,14 +5,16 @@ #include "alloc-util.h" #include "ask-password-api.h" #include "cryptsetup-tpm2.h" +#include "cryptsetup-util.h" #include "env-util.h" #include "fileio.h" #include "hexdecoct.h" -#include "parse-util.h" +#include "log.h" #include "random-util.h" -#include "sha256.h" +#include "strv.h" #include "tpm2-util.h" +#if HAVE_LIBCRYPTSETUP && HAVE_TPM2 static int get_pin( usec_t until, const char *askpw_credential, @@ -59,6 +61,7 @@ static int get_pin( return r; } +#endif int acquire_tpm2_key( const char *volume_name, @@ -86,6 +89,7 @@ int acquire_tpm2_key( AskPasswordFlags askpw_flags, struct iovec *ret_decrypted_key) { +#if HAVE_LIBCRYPTSETUP && HAVE_TPM2 _cleanup_(sd_json_variant_unrefp) sd_json_variant *signature_json = NULL; _cleanup_(iovec_done) struct iovec loaded_blob = {}; _cleanup_free_ char *auto_device = NULL; @@ -230,6 +234,9 @@ int acquire_tpm2_key( return r; } +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "TPM2 support not available."); +#endif } int find_tpm2_auto_data( @@ -252,6 +259,7 @@ int find_tpm2_auto_data( int *ret_keyslot, int *ret_token) { +#if HAVE_LIBCRYPTSETUP && HAVE_TPM2 int r, token; assert(cd); @@ -339,4 +347,7 @@ int find_tpm2_auto_data( } return log_error_errno(SYNTHETIC_ERRNO(ENXIO), "No valid TPM2 token data found."); +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "TPM2 support not available."); +#endif } diff --git a/src/shared/cryptsetup-tpm2.h b/src/shared/cryptsetup-tpm2.h index 240a09077fd..f66a5168872 100644 --- a/src/shared/cryptsetup-tpm2.h +++ b/src/shared/cryptsetup-tpm2.h @@ -1,15 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include -#include "ask-password-api.h" -#include "cryptsetup-util.h" -#include "log.h" -#include "time-util.h" -#include "tpm2-util.h" - -#if HAVE_TPM2 +#include "forward.h" int acquire_tpm2_key( const char *volume_name, @@ -56,61 +50,3 @@ int find_tpm2_auto_data( TPM2Flags *ret_flags, int *ret_keyslot, int *ret_token); - -#else - -static inline int acquire_tpm2_key( - const char *volume_name, - const char *device, - uint32_t hash_pcr_mask, - uint16_t pcr_bank, - const struct iovec *pubkey, - uint32_t pubkey_pcr_mask, - const char *signature_path, - const char *pcrlock_path, - uint16_t primary_alg, - const char *key_file, - size_t key_file_size, - uint64_t key_file_offset, - const struct iovec blobs[], - size_t n_blobs, - const struct iovec policy_hash[], - size_t n_policy_hash, - const struct iovec *salt, - const struct iovec *srk, - const struct iovec *pcrlock_nv, - TPM2Flags flags, - usec_t until, - const char *askpw_credential, - AskPasswordFlags askpw_flags, - struct iovec *ret_decrypted_key) { - - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "TPM2 support not available."); -} - -static inline int find_tpm2_auto_data( - struct crypt_device *cd, - uint32_t search_pcr_mask, - int start_token, - uint32_t *ret_hash_pcr_mask, - uint16_t *ret_pcr_bank, - struct iovec *ret_pubkey, - uint32_t *ret_pubkey_pcr_mask, - uint16_t *ret_primary_alg, - struct iovec **ret_blobs, - size_t *ret_n_blobs, - struct iovec **ret_policy_hash, - size_t *ret_n_policy_hash, - struct iovec *ret_salt, - struct iovec *ret_srk, - struct iovec *ret_pcrlock_nv, - TPM2Flags *ret_flags, - int *ret_keyslot, - int *ret_token) { - - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), - "TPM2 support not available."); -} - -#endif diff --git a/src/shared/cryptsetup-util.c b/src/shared/cryptsetup-util.c index 46f91934537..e45e8431bcd 100644 --- a/src/shared/cryptsetup-util.c +++ b/src/shared/cryptsetup-util.c @@ -1,10 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + +#include "sd-json.h" + #include "alloc-util.h" #include "cryptsetup-util.h" #include "dlfcn-util.h" #include "log.h" #include "parse-util.h" +#include "string-util.h" +#include "strv.h" #if HAVE_LIBCRYPTSETUP static void *cryptsetup_dl = NULL; @@ -338,3 +344,8 @@ int cryptsetup_get_keyslot_from_token(sd_json_variant *v) { return keyslot; } + +const char* mangle_none(const char *s) { + /* A helper that turns cryptsetup/integritysetup/veritysetup "options" strings into NULL if they are effectively empty */ + return isempty(s) || STR_IN_SET(s, "-", "none") ? NULL : s; +} diff --git a/src/shared/cryptsetup-util.h b/src/shared/cryptsetup-util.h index ea3baf9675b..6ecc8f601f0 100644 --- a/src/shared/cryptsetup-util.h +++ b/src/shared/cryptsetup-util.h @@ -1,16 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-json.h" - -#include "alloc-util.h" #include "dlfcn-util.h" -#include "macro.h" -#include "string-util.h" -#include "strv.h" +#include "forward.h" #if HAVE_LIBCRYPTSETUP -#include +#include /* IWYU pragma: export */ /* These next two are defined in libcryptsetup.h from cryptsetup version 2.3.4 forwards. */ #ifndef CRYPT_ACTIVATE_NO_READ_WORKQUEUE @@ -116,7 +111,4 @@ int dlopen_cryptsetup(void); int cryptsetup_get_keyslot_from_token(sd_json_variant *v); -static inline const char* mangle_none(const char *s) { - /* A helper that turns cryptsetup/integritysetup/veritysetup "options" strings into NULL if they are effectively empty */ - return isempty(s) || STR_IN_SET(s, "-", "none") ? NULL : s; -} +const char* mangle_none(const char *s); diff --git a/src/shared/daemon-util.c b/src/shared/daemon-util.c index e189e401321..21ccfdfd365 100644 --- a/src/shared/daemon-util.c +++ b/src/shared/daemon-util.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-daemon.h" + #include "alloc-util.h" #include "daemon-util.h" #include "fd-util.h" diff --git a/src/shared/daemon-util.h b/src/shared/daemon-util.h index e3daa9ebf50..6b81fcd75c9 100644 --- a/src/shared/daemon-util.h +++ b/src/shared/daemon-util.h @@ -1,11 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "sd-daemon.h" /* IWYU pragma: export */ -#include "sd-daemon.h" - -#include "macro.h" +#include "forward.h" #define NOTIFY_READY_MESSAGE "READY=1\n" "STATUS=Processing requests..." #define NOTIFY_STOPPING_MESSAGE "STOPPING=1\n" "STATUS=Shutting down..." @@ -17,7 +15,6 @@ static inline const char* notify_start(const char *start, const char *stop) { return stop; } -/* This is intended to be used with _cleanup_ attribute. */ static inline void notify_on_cleanup(const char **p) { if (*p) (void) sd_notify(false, *p); diff --git a/src/shared/data-fd-util.c b/src/shared/data-fd-util.c index 20d54f325d9..a9b799bd610 100644 --- a/src/shared/data-fd-util.c +++ b/src/shared/data-fd-util.c @@ -1,5 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include +#include + #include "copy.h" #include "data-fd-util.h" #include "fd-util.h" diff --git a/src/shared/data-fd-util.h b/src/shared/data-fd-util.h index db03fba251a..605ba6b24e2 100644 --- a/src/shared/data-fd-util.h +++ b/src/shared/data-fd-util.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "forward.h" int copy_data_fd(int fd); int memfd_clone_fd(int fd, const char *name, int mode); diff --git a/src/shared/dev-setup.c b/src/shared/dev-setup.c index 0ac195c86f5..e79db91ddee 100644 --- a/src/shared/dev-setup.c +++ b/src/shared/dev-setup.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include @@ -10,13 +8,11 @@ #include "fd-util.h" #include "fs-util.h" #include "label-util.h" -#include "lock-util.h" #include "log.h" #include "mkdir-label.h" #include "nulstr-util.h" #include "path-util.h" #include "stat-util.h" -#include "terminal-util.h" #include "umask-util.h" #include "user-util.h" diff --git a/src/shared/dev-setup.h b/src/shared/dev-setup.h index 92ba6cf7640..8844d751ac1 100644 --- a/src/shared/dev-setup.h +++ b/src/shared/dev-setup.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int dev_setup(const char *prefix, uid_t uid, gid_t gid); diff --git a/src/shared/device-nodes.c b/src/shared/device-nodes.c index d08c40fe2ca..8d4e38ec063 100644 --- a/src/shared/device-nodes.c +++ b/src/shared/device-nodes.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include diff --git a/src/shared/device-nodes.h b/src/shared/device-nodes.h index 8b17a8e1904..f57378c0f61 100644 --- a/src/shared/device-nodes.h +++ b/src/shared/device-nodes.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int encode_devnode_name(const char *str, char *str_enc, size_t len); int allow_listed_char_for_devnode(char c, const char *additional); diff --git a/src/shared/discover-image.c b/src/shared/discover-image.c index 2a973ef57c0..71d64bed8df 100644 --- a/src/shared/discover-image.c +++ b/src/shared/discover-image.c @@ -1,16 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include #include -#include #include #include #include +#include #include +#include "sd-json.h" #include "sd-path.h" #include "alloc-util.h" @@ -34,19 +34,17 @@ #include "lock-util.h" #include "log.h" #include "loop-util.h" -#include "macro.h" -#include "missing_fs.h" #include "mkdir.h" #include "nulstr-util.h" #include "os-util.h" #include "path-util.h" #include "rm-rf.h" +#include "runtime-scope.h" #include "stat-util.h" #include "string-table.h" #include "string-util.h" #include "strv.h" #include "time-util.h" -#include "utf8.h" #include "vpick.h" #include "xattr-util.h" diff --git a/src/shared/discover-image.h b/src/shared/discover-image.h index 27d48713644..4b586f68dd8 100644 --- a/src/shared/discover-image.h +++ b/src/shared/discover-image.h @@ -1,21 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - #include "sd-id128.h" -#include "sd-json.h" -#include "hashmap.h" -#include "image-policy.h" -#include "lock-util.h" -#include "macro.h" +#include "forward.h" #include "os-util.h" -#include "path-util.h" -#include "runtime-scope.h" -#include "string-util.h" -#include "time-util.h" typedef enum ImageType { IMAGE_DIRECTORY, diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index 775f6aaff3f..646bbfc6337 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -1,17 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#if HAVE_VALGRIND_MEMCHECK_H -#include -#endif - #include -#include #include #include #include -#include -#include -#include #if HAVE_OPENSSL #include @@ -34,29 +26,28 @@ #include "constants.h" #include "copy.h" #include "cryptsetup-util.h" -#include "device-nodes.h" #include "device-private.h" -#include "device-util.h" #include "devnum-util.h" -#include "discover-image.h" #include "dissect-image.h" #include "dm-util.h" #include "env-file.h" #include "env-util.h" +#include "errno-util.h" #include "extension-util.h" #include "extract-word.h" #include "fd-util.h" #include "fileio.h" -#include "fs-util.h" +#include "format-util.h" #include "fsck-util.h" #include "gpt.h" +#include "hash-funcs.h" #include "hexdecoct.h" #include "hostname-setup.h" -#include "id128-util.h" +#include "image-policy.h" #include "import-util.h" #include "io-util.h" #include "json-util.h" -#include "missing_syscall.h" +#include "loop-util.h" #include "mkdir-label.h" #include "mount-util.h" #include "mountpoint-util.h" @@ -67,16 +58,13 @@ #include "path-util.h" #include "proc-cmdline.h" #include "process-util.h" -#include "raw-clone.h" #include "resize-fs.h" #include "signal-util.h" -#include "sparse-endian.h" +#include "siphash24.h" #include "stat-util.h" -#include "stdio-util.h" -#include "string-table.h" #include "string-util.h" #include "strv.h" -#include "tmpfile-util.h" +#include "time-util.h" #include "udev-util.h" #include "user-util.h" #include "xattr-util.h" @@ -4029,6 +4017,14 @@ Architecture dissected_image_architecture(DissectedImage *img) { return _ARCHITECTURE_INVALID; } +bool dissected_image_is_portable(DissectedImage *m) { + return m && strv_env_pairs_get(m->os_release, "PORTABLE_PREFIXES"); +} + +bool dissected_image_is_initrd(DissectedImage *m) { + return m && !strv_isempty(m->initrd_release); +} + int dissect_loop_device( LoopDevice *loop, const VeritySettings *verity, diff --git a/src/shared/dissect-image.h b/src/shared/dissect-image.h index 191bfb8fbb7..2343b6b46dd 100644 --- a/src/shared/dissect-image.h +++ b/src/shared/dissect-image.h @@ -1,29 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - #include "sd-id128.h" #include "architecture.h" -#include "env-util.h" +#include "forward.h" #include "gpt.h" #include "list.h" -#include "loop-util.h" -#include "macro.h" -#include "os-util.h" -#include "strv.h" -typedef struct DissectedImage DissectedImage; -typedef struct DissectedPartition DissectedPartition; typedef struct DecryptedImage DecryptedImage; -typedef struct MountOptions MountOptions; -typedef struct VeritySettings VeritySettings; -typedef struct ImageFilter ImageFilter; -typedef struct ImagePolicy ImagePolicy; -typedef struct ExtensionReleaseData ExtensionReleaseData; -struct DissectedPartition { +typedef struct DissectedPartition { bool found:1; bool ignored:1; bool rw:1; @@ -42,7 +29,7 @@ struct DissectedPartition { uint64_t offset; uint64_t gpt_flags; int fsmount_fd; -}; +} DissectedPartition; #define DISSECTED_PARTITION_NULL \ ((DissectedPartition) { \ @@ -96,7 +83,7 @@ typedef enum DissectImageFlags { DISSECT_IMAGE_IDENTITY_UID = 1 << 29, /* Explicitly request an identity UID range mapping */ } DissectImageFlags; -struct DissectedImage { +typedef struct DissectedImage { bool encrypted:1; bool has_verity:1; /* verity available in image, but not necessarily used */ bool has_verity_sig:1; /* pkcs#7 signature embedded in image */ @@ -123,15 +110,15 @@ struct DissectedImage { char **confext_release; char **sysext_release; int has_init_system; -}; +} DissectedImage; -struct MountOptions { +typedef struct MountOptions { PartitionDesignator partition_designator; char *options; LIST_FIELDS(MountOptions, mount_options); -}; +} MountOptions; -struct VeritySettings { +typedef struct VeritySettings { /* Binary root hash for the Verity Merkle tree */ void *root_hash; size_t root_hash_size; @@ -145,24 +132,24 @@ struct VeritySettings { /* PARTITION_ROOT or PARTITION_USR, depending on what these Verity settings are for */ PartitionDesignator designator; -}; +} VeritySettings; #define VERITY_SETTINGS_DEFAULT (VeritySettings) { \ .designator = _PARTITION_DESIGNATOR_INVALID \ } -struct ImageFilter { +typedef struct ImageFilter { /* A per designator glob matching against the partition label */ char *pattern[_PARTITION_DESIGNATOR_MAX]; -}; +} ImageFilter; -struct ExtensionReleaseData { +typedef struct ExtensionReleaseData { char *os_release_id; char *os_release_version_id; char *os_release_sysext_level; char *os_release_confext_level; char *os_release_extension_scope; -}; +} ExtensionReleaseData; MountOptions* mount_options_free_all(MountOptions *options); DEFINE_TRIVIAL_CLEANUP_FUNC(MountOptions*, mount_options_free_all); @@ -200,13 +187,8 @@ static inline bool dissected_image_is_bootable_uefi(DissectedImage *m) { return m && m->partitions[PARTITION_ESP].found && dissected_image_is_bootable_os(m); } -static inline bool dissected_image_is_portable(DissectedImage *m) { - return m && strv_env_pairs_get(m->os_release, "PORTABLE_PREFIXES"); -} - -static inline bool dissected_image_is_initrd(DissectedImage *m) { - return m && !strv_isempty(m->initrd_release); -} +bool dissected_image_is_portable(DissectedImage *m); +bool dissected_image_is_initrd(DissectedImage *m); DecryptedImage* decrypted_image_ref(DecryptedImage *p); DecryptedImage* decrypted_image_unref(DecryptedImage *p); diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index a310438b3ce..c9788989d83 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -6,16 +6,17 @@ #include #include "alloc-util.h" +#include "dns-def.h" #include "dns-domain.h" #include "glyph-util.h" -#include "hashmap.h" +#include "hash-funcs.h" #include "hexdecoct.h" #include "hostname-util.h" #include "idn-util.h" #include "in-addr-util.h" #include "log.h" -#include "macro.h" #include "parse-util.h" +#include "siphash24.h" #include "string-util.h" #include "strv.h" #include "utf8.h" @@ -291,6 +292,10 @@ int dns_label_escape_new(const char *p, size_t l, char **ret) { return r; } +int dns_name_parent(const char **name) { + return dns_label_unescape(name, NULL, DNS_LABEL_MAX, 0); +} + #if HAVE_LIBIDN int dns_label_apply_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max) { _cleanup_free_ uint32_t *input = NULL; diff --git a/src/shared/dns-domain.h b/src/shared/dns-domain.h index edfb2f00ca3..6b8070d0ce9 100644 --- a/src/shared/dns-domain.h +++ b/src/shared/dns-domain.h @@ -1,14 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include - -#include "dns-def.h" -#include "hashmap.h" -#include "in-addr-util.h" +#include "forward.h" typedef enum DNSLabelFlags { DNS_LABEL_LDH = 1 << 0, /* Follow the "LDH" rule — only letters, digits, and internal hyphens. */ @@ -21,9 +14,7 @@ int dns_label_unescape_suffix(const char *name, const char **label_end, char *de int dns_label_escape(const char *p, size_t l, char *dest, size_t sz); int dns_label_escape_new(const char *p, size_t l, char **ret); -static inline int dns_name_parent(const char **name) { - return dns_label_unescape(name, NULL, DNS_LABEL_MAX, 0); -} +int dns_name_parent(const char **name); #if HAVE_LIBIDN int dns_label_apply_idna(const char *encoded, size_t encoded_size, char *decoded, size_t decoded_max); diff --git a/src/shared/dropin.c b/src/shared/dropin.c index 2e285f8eb62..f540f489339 100644 --- a/src/shared/dropin.c +++ b/src/shared/dropin.c @@ -1,26 +1,20 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include -#include #include "alloc-util.h" #include "chase.h" #include "conf-files.h" -#include "dirent-util.h" #include "dropin.h" #include "escape.h" -#include "fd-util.h" #include "fileio.h" -#include "hashmap.h" #include "log.h" -#include "macro.h" -#include "mkdir.h" #include "path-util.h" #include "set.h" +#include "stdio-util.h" #include "string-util.h" #include "strv.h" +#include "unit-def.h" #include "unit-name.h" int drop_in_file( diff --git a/src/shared/dropin.h b/src/shared/dropin.h index 8107944de91..ffd47571777 100644 --- a/src/shared/dropin.h +++ b/src/shared/dropin.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "hashmap.h" -#include "macro.h" -#include "set.h" -#include "unit-name.h" +#include "forward.h" int drop_in_file( const char *dir, diff --git a/src/shared/edit-util.c b/src/shared/edit-util.c index becb9c54b76..c352994e4e0 100644 --- a/src/shared/edit-util.c +++ b/src/shared/edit-util.c @@ -1,7 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include +#include +#include #include "alloc-util.h" #include "copy.h" diff --git a/src/shared/edit-util.h b/src/shared/edit-util.h index 89b30fe1990..5bcdaeba16e 100644 --- a/src/shared/edit-util.h +++ b/src/shared/edit-util.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "forward.h" #define DROPIN_MARKER_START "### Anything between here and the comment below will become the contents of the drop-in file" #define DROPIN_MARKER_END "### Edits below this comment will be discarded" diff --git a/src/shared/efi-api.c b/src/shared/efi-api.c index 4454b444bb6..11165cdb9ac 100644 --- a/src/shared/efi-api.c +++ b/src/shared/efi-api.c @@ -13,10 +13,9 @@ #include "sort-util.h" #include "stat-util.h" #include "stdio-util.h" +#include "string-util.h" #include "utf8.h" -#if ENABLE_EFI - #define LOAD_OPTION_ACTIVE 0x00000001 #define MEDIA_DEVICE_PATH 0x04 #define MEDIA_HARDDRIVE_DP 0x01 @@ -65,41 +64,7 @@ struct device_path device_path__contents; struct device_path__packed device_path__contents _packed_; assert_cc(sizeof(struct device_path) == sizeof(struct device_path__packed)); -int efi_reboot_to_firmware_supported(void) { - _cleanup_free_ void *v = NULL; - static int cache = -1; - uint64_t b; - size_t s; - int r; - - if (cache > 0) - return 0; - if (cache == 0) - return -EOPNOTSUPP; - - if (!is_efi_boot()) - goto not_supported; - - r = efi_get_variable(EFI_GLOBAL_VARIABLE_STR("OsIndicationsSupported"), NULL, &v, &s); - if (r == -ENOENT) - goto not_supported; /* variable doesn't exist? it's not supported then */ - if (r < 0) - return r; - if (s != sizeof(uint64_t)) - return -EINVAL; - - b = *(uint64_t*) v; - if (!(b & EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) - goto not_supported; /* bit unset? it's not supported then */ - - cache = 1; - return 0; - -not_supported: - cache = 0; - return -EOPNOTSUPP; -} - +#if ENABLE_EFI static int get_os_indications(uint64_t *ret) { static struct stat cache_stat = {}; _cleanup_free_ void *v = NULL; @@ -150,7 +115,94 @@ static int get_os_indications(uint64_t *ret) { return 0; } +static ssize_t utf16_size(const uint16_t *s, size_t buf_len_bytes) { + size_t l = 0; + + /* Returns the size of the string in bytes without the terminating two zero bytes */ + + while (l < buf_len_bytes / sizeof(uint16_t)) { + if (s[l] == 0) + return (l + 1) * sizeof(uint16_t); + l++; + } + + return -EINVAL; /* The terminator was not found */ +} + +static void to_utf16(uint16_t *dest, const char *src) { + int i; + + for (i = 0; src[i] != '\0'; i++) + dest[i] = src[i]; + dest[i] = '\0'; +} + +static uint16_t *tilt_slashes(uint16_t *s) { + for (uint16_t *p = s; *p; p++) + if (*p == '/') + *p = '\\'; + + return s; +} + +static int boot_id_hex(const char s[static 4]) { + int id = 0; + + assert(s); + + for (int i = 0; i < 4; i++) + if (s[i] >= '0' && s[i] <= '9') + id |= (s[i] - '0') << (3 - i) * 4; + else if (s[i] >= 'A' && s[i] <= 'F') + id |= (s[i] - 'A' + 10) << (3 - i) * 4; + else + return -EINVAL; + + return id; +} +#endif + +int efi_reboot_to_firmware_supported(void) { +#if ENABLE_EFI + _cleanup_free_ void *v = NULL; + static int cache = -1; + uint64_t b; + size_t s; + int r; + + if (cache > 0) + return 0; + if (cache == 0) + return -EOPNOTSUPP; + + if (!is_efi_boot()) + goto not_supported; + + r = efi_get_variable(EFI_GLOBAL_VARIABLE_STR("OsIndicationsSupported"), NULL, &v, &s); + if (r == -ENOENT) + goto not_supported; /* variable doesn't exist? it's not supported then */ + if (r < 0) + return r; + if (s != sizeof(uint64_t)) + return -EINVAL; + + b = *(uint64_t*) v; + if (!(b & EFI_OS_INDICATIONS_BOOT_TO_FW_UI)) + goto not_supported; /* bit unset? it's not supported then */ + + cache = 1; + return 0; + +not_supported: + cache = 0; + return -EOPNOTSUPP; +#else + return -EOPNOTSUPP; +#endif +} + int efi_get_reboot_to_firmware(void) { +#if ENABLE_EFI int r; uint64_t b; @@ -159,9 +211,13 @@ int efi_get_reboot_to_firmware(void) { return r; return !!(b & EFI_OS_INDICATIONS_BOOT_TO_FW_UI); +#else + return -EOPNOTSUPP; +#endif } int efi_set_reboot_to_firmware(bool value) { +#if ENABLE_EFI int r; uint64_t b, b_new; @@ -176,20 +232,9 @@ int efi_set_reboot_to_firmware(bool value) { return efi_set_variable(EFI_GLOBAL_VARIABLE_STR("OsIndications"), &b_new, sizeof(uint64_t)); return 0; -} - -static ssize_t utf16_size(const uint16_t *s, size_t buf_len_bytes) { - size_t l = 0; - - /* Returns the size of the string in bytes without the terminating two zero bytes */ - - while (l < buf_len_bytes / sizeof(uint16_t)) { - if (s[l] == 0) - return (l + 1) * sizeof(uint16_t); - l++; - } - - return -EINVAL; /* The terminator was not found */ +#else + return -EOPNOTSUPP; +#endif } int efi_get_boot_option( @@ -198,7 +243,7 @@ int efi_get_boot_option( sd_id128_t *ret_part_uuid, char **ret_path, bool *ret_active) { - +#if ENABLE_EFI char variable[STRLEN(EFI_GLOBAL_VARIABLE_STR("Boot")) + 4 + 1]; _cleanup_free_ uint8_t *buf = NULL; size_t l; @@ -293,22 +338,9 @@ int efi_get_boot_option( *ret_active = header->attr & LOAD_OPTION_ACTIVE; return 0; -} - -static void to_utf16(uint16_t *dest, const char *src) { - int i; - - for (i = 0; src[i] != '\0'; i++) - dest[i] = src[i]; - dest[i] = '\0'; -} - -static uint16_t *tilt_slashes(uint16_t *s) { - for (uint16_t *p = s; *p; p++) - if (*p == '/') - *p = '\\'; - - return s; +#else + return -EOPNOTSUPP; +#endif } int efi_add_boot_option( @@ -319,7 +351,7 @@ int efi_add_boot_option( uint64_t psize, sd_id128_t part_uuid, const char *path) { - +#if ENABLE_EFI size_t size, title_len, path_len; _cleanup_free_ char *buf = NULL; struct boot_option *option; @@ -378,9 +410,13 @@ int efi_add_boot_option( xsprintf(variable, EFI_GLOBAL_VARIABLE_STR("Boot%04X"), id); return efi_set_variable(variable, buf, size); +#else + return -EOPNOTSUPP; +#endif } int efi_remove_boot_option(uint16_t id) { +#if ENABLE_EFI char variable[STRLEN(EFI_GLOBAL_VARIABLE_STR("Boot")) + 4 + 1]; if (!is_efi_boot()) @@ -388,9 +424,13 @@ int efi_remove_boot_option(uint16_t id) { xsprintf(variable, EFI_GLOBAL_VARIABLE_STR("Boot%04X"), id); return efi_set_variable(variable, NULL, 0); +#else + return -EOPNOTSUPP; +#endif } int efi_get_boot_order(uint16_t **ret_order) { +#if ENABLE_EFI _cleanup_free_ void *buf = NULL; size_t l; int r; @@ -413,33 +453,24 @@ int efi_get_boot_order(uint16_t **ret_order) { *ret_order = TAKE_PTR(buf); return (int) (l / sizeof(uint16_t)); +#else + return -EOPNOTSUPP; +#endif } int efi_set_boot_order(const uint16_t *order, size_t n) { - +#if ENABLE_EFI if (!is_efi_boot()) return -EOPNOTSUPP; return efi_set_variable(EFI_GLOBAL_VARIABLE_STR("BootOrder"), order, n * sizeof(uint16_t)); -} - -static int boot_id_hex(const char s[static 4]) { - int id = 0; - - assert(s); - - for (int i = 0; i < 4; i++) - if (s[i] >= '0' && s[i] <= '9') - id |= (s[i] - '0') << (3 - i) * 4; - else if (s[i] >= 'A' && s[i] <= 'F') - id |= (s[i] - 'A' + 10) << (3 - i) * 4; - else - return -EINVAL; - - return id; +#else + return -EOPNOTSUPP; +#endif } int efi_get_boot_options(uint16_t **ret_options) { +#if ENABLE_EFI _cleanup_closedir_ DIR *dir = NULL; _cleanup_free_ uint16_t *list = NULL; int count = 0; @@ -480,9 +511,13 @@ int efi_get_boot_options(uint16_t **ret_options) { *ret_options = TAKE_PTR(list); return count; +#else + return -EOPNOTSUPP; +#endif } bool efi_has_tpm2(void) { +#if ENABLE_EFI static int cache = -1; int r; @@ -521,9 +556,10 @@ bool efi_has_tpm2(void) { log_debug_errno(errno, "Unable to test whether /sys/kernel/security/tpm0/binary_bios_measurements exists, assuming it doesn't: %m"); return (cache = false); -} - +#else + return -EOPNOTSUPP; #endif +} sd_id128_t efi_guid_to_id128(const void *guid) { const EFI_GUID *uuid = ASSERT_PTR(guid); /* cast is safe, because struct efi_guid is packed */ diff --git a/src/shared/efi-api.h b/src/shared/efi-api.h index bce5275ba07..206e6136de4 100644 --- a/src/shared/efi-api.h +++ b/src/shared/efi-api.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "efivars.h" -#include "efivars-fundamental.h" -#include "string-util.h" +#include "sd-id128.h" -/* Various calls for interfacing with EFI variables from the official UEFI specs. */ +#include "forward.h" -#if ENABLE_EFI +/* Various calls for interfacing with EFI variables from the official UEFI specs. */ int efi_reboot_to_firmware_supported(void); int efi_get_reboot_to_firmware(void); @@ -22,49 +20,5 @@ int efi_get_boot_options(uint16_t **ret_options); bool efi_has_tpm2(void); -#else - -static inline int efi_reboot_to_firmware_supported(void) { - return -EOPNOTSUPP; -} - -static inline int efi_get_reboot_to_firmware(void) { - return -EOPNOTSUPP; -} - -static inline int efi_set_reboot_to_firmware(bool value) { - return -EOPNOTSUPP; -} - -static inline int efi_get_boot_option(uint16_t nr, char **ret_title, sd_id128_t *ret_part_uuid, char **ret_path, bool *ret_active) { - return -EOPNOTSUPP; -} - -static inline int efi_add_boot_option(uint16_t id, const char *title, uint32_t part, uint64_t pstart, uint64_t psize, sd_id128_t part_uuid, const char *path) { - return -EOPNOTSUPP; -} - -static inline int efi_remove_boot_option(uint16_t id) { - return -EOPNOTSUPP; -} - -static inline int efi_get_boot_order(uint16_t **ret_order) { - return -EOPNOTSUPP; -} - -static inline int efi_set_boot_order(const uint16_t *order, size_t n) { - return -EOPNOTSUPP; -} - -static inline int efi_get_boot_options(uint16_t **ret_options) { - return -EOPNOTSUPP; -} - -static inline bool efi_has_tpm2(void) { - return false; -} - -#endif - sd_id128_t efi_guid_to_id128(const void *guid); void efi_id128_to_guid(sd_id128_t id, void *ret_guid); diff --git a/src/shared/efi-loader.c b/src/shared/efi-loader.c index 75d935847ac..1f4fc665c03 100644 --- a/src/shared/efi-loader.c +++ b/src/shared/efi-loader.c @@ -3,17 +3,19 @@ #include "alloc-util.h" #include "efi-api.h" #include "efi-loader.h" +#include "efivars.h" #include "env-util.h" #include "log.h" #include "parse-util.h" #include "path-util.h" #include "stat-util.h" +#include "string-util.h" #include "strv.h" +#include "time-util.h" #include "tpm2-pcr.h" #include "utf8.h" #if ENABLE_EFI - static int read_usec(const char *variable, usec_t *ret) { _cleanup_free_ char *j = NULL; uint64_t x = 0; @@ -34,7 +36,16 @@ static int read_usec(const char *variable, usec_t *ret) { return 0; } +static int get_device_part_uuid(const char *variable, sd_id128_t *ret) { + if (!is_efi_boot()) + return -EOPNOTSUPP; + + return efi_get_variable_id128(variable, ret); +} +#endif + int efi_loader_get_boot_usec(usec_t *ret_firmware, usec_t *ret_loader) { +#if ENABLE_EFI uint64_t x, y; int r; @@ -60,24 +71,29 @@ int efi_loader_get_boot_usec(usec_t *ret_firmware, usec_t *ret_loader) { *ret_firmware = x; *ret_loader = y; return 0; -} - -static int get_device_part_uuid(const char *variable, sd_id128_t *ret) { - if (!is_efi_boot()) - return -EOPNOTSUPP; - - return efi_get_variable_id128(variable, ret); +#else + return -EOPNOTSUPP; +#endif } int efi_loader_get_device_part_uuid(sd_id128_t *ret) { +#if ENABLE_EFI return get_device_part_uuid(EFI_LOADER_VARIABLE_STR("LoaderDevicePartUUID"), ret); +#else + return -EOPNOTSUPP; +#endif } int efi_stub_get_device_part_uuid(sd_id128_t *ret) { +#if ENABLE_EFI return get_device_part_uuid(EFI_LOADER_VARIABLE_STR("StubDevicePartUUID"), ret); +#else + return -EOPNOTSUPP; +#endif } int efi_loader_get_entries(char ***ret) { +#if ENABLE_EFI _cleanup_free_ char16_t *entries = NULL; _cleanup_strv_free_ char **l = NULL; size_t size; @@ -135,9 +151,13 @@ int efi_loader_get_entries(char ***ret) { *ret = TAKE_PTR(l); return 0; +#else + return -EOPNOTSUPP; +#endif } int efi_loader_get_features(uint64_t *ret) { +#if ENABLE_EFI _cleanup_free_ void *v = NULL; size_t s; int r; @@ -186,9 +206,13 @@ int efi_loader_get_features(uint64_t *ret) { memcpy(ret, v, sizeof(uint64_t)); return 0; +#else + return -EOPNOTSUPP; +#endif } int efi_stub_get_features(uint64_t *ret) { +#if ENABLE_EFI _cleanup_free_ void *v = NULL; size_t s; int r; @@ -234,9 +258,13 @@ int efi_stub_get_features(uint64_t *ret) { memcpy(ret, v, sizeof(uint64_t)); return 0; +#else + return -EOPNOTSUPP; +#endif } int efi_measured_uki(int log_level) { +#if ENABLE_EFI _cleanup_free_ char *pcr_string = NULL; static int cached = -1; unsigned pcr_nr; @@ -279,9 +307,13 @@ int efi_measured_uki(int log_level) { pcr_nr, TPM2_PCR_KERNEL_BOOT); return (cached = 1); +#else + return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP), "Compiled without support for EFI"); +#endif } int efi_loader_get_config_timeout_one_shot(usec_t *ret) { +#if ENABLE_EFI _cleanup_free_ char *v = NULL; static struct stat cache_stat = {}; struct stat new_stat; @@ -313,9 +345,13 @@ int efi_loader_get_config_timeout_one_shot(usec_t *ret) { cache_stat = new_stat; *ret = cache = sec * USEC_PER_SEC; /* return in μs */ return 0; +#else + return -EOPNOTSUPP; +#endif } int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat) { +#if ENABLE_EFI _cleanup_free_ char *v = NULL; struct stat new_stat; int r; @@ -341,9 +377,13 @@ int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat free_and_replace(*cache, v); return 0; +#else + return -EOPNOTSUPP; +#endif } int efi_get_variable_id128(const char *variable, sd_id128_t *ret) { +#if ENABLE_EFI int r; assert(variable); @@ -357,9 +397,10 @@ int efi_get_variable_id128(const char *variable, sd_id128_t *ret) { return r; return sd_id128_from_string(p, ret); -} - +#else + return -EOPNOTSUPP; #endif +} bool efi_loader_entry_name_valid(const char *s) { if (!filename_is_valid(s)) /* Make sure entry names fit in filenames */ diff --git a/src/shared/efi-loader.h b/src/shared/efi-loader.h index 0d924e5dc3a..346f3b5d8b1 100644 --- a/src/shared/efi-loader.h +++ b/src/shared/efi-loader.h @@ -1,16 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "efivars.h" -#include "efivars-fundamental.h" -#include "log.h" +#include "forward.h" /* Various calls that interface with EFI variables implementing https://systemd.io/BOOT_LOADER_INTERFACE */ -#if ENABLE_EFI - int efi_loader_get_device_part_uuid(sd_id128_t *ret); int efi_stub_get_device_part_uuid(sd_id128_t *ret); int efi_loader_get_boot_usec(usec_t *ret_firmware, usec_t *ret_loader); @@ -27,49 +21,4 @@ int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat int efi_get_variable_id128(const char *variable, sd_id128_t *ret); -#else - -static inline int efi_loader_get_device_part_uuid(sd_id128_t *u) { - return -EOPNOTSUPP; -} - -static inline int efi_stub_get_device_part_uuid(sd_id128_t *ret) { - return -EOPNOTSUPP; -} - -static inline int efi_loader_get_boot_usec(usec_t *firmware, usec_t *loader) { - return -EOPNOTSUPP; -} - -static inline int efi_loader_get_entries(char ***ret) { - return -EOPNOTSUPP; -} - -static inline int efi_loader_get_features(uint64_t *ret) { - return -EOPNOTSUPP; -} - -static inline int efi_stub_get_features(uint64_t *ret) { - return -EOPNOTSUPP; -} - -static inline int efi_measured_uki(int log_level) { - return log_full_errno(log_level, SYNTHETIC_ERRNO(EOPNOTSUPP), - "Compiled without support for EFI"); -} - -static inline int efi_loader_get_config_timeout_one_shot(usec_t *ret) { - return -EOPNOTSUPP; -} - -static inline int efi_loader_update_entry_one_shot_cache(char **cache, struct stat *cache_stat) { - return -EOPNOTSUPP; -} - -static inline int efi_get_variable_id128(const char *variable, sd_id128_t *ret) { - return -EOPNOTSUPP; -} - -#endif - bool efi_loader_entry_name_valid(const char *s); diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c index edc2e82d362..73a910575de 100644 --- a/src/shared/elf-util.c +++ b/src/shared/elf-util.c @@ -1,16 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #if HAVE_ELFUTILS - #include #include #include #include +#endif #include -#include -#include #include +#include "sd-json.h" + #include "alloc-util.h" #include "dlfcn-util.h" #include "elf-util.h" @@ -19,14 +19,12 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" -#include "hexdecoct.h" #include "io-util.h" #include "log.h" -#include "macro.h" #include "memstream-util.h" #include "path-util.h" #include "process-util.h" -#include "rlimit-util.h" +#include "set.h" #include "string-util.h" #define FRAMES_MAX 64 @@ -36,6 +34,8 @@ /* The amount of data we're willing to write to each of the output pipes. */ #define COREDUMP_PIPE_MAX (1024*1024U) +#if HAVE_ELFUTILS + static void *dw_dl = NULL; static void *elf_dl = NULL; @@ -761,7 +761,10 @@ static int parse_elf(int fd, const char *executable, const char *root, char **re return 0; } +#endif + int parse_elf_object(int fd, const char *executable, const char *root, bool fork_disable_dump, char **ret, sd_json_variant **ret_package_metadata) { +#if HAVE_ELFUTILS _cleanup_close_pair_ int error_pipe[2] = EBADF_PAIR, return_pipe[2] = EBADF_PAIR, json_pipe[2] = EBADF_PAIR; @@ -912,6 +915,7 @@ int parse_elf_object(int fd, const char *executable, const char *root, bool fork *ret_package_metadata = TAKE_PTR(package_metadata); return 0; -} - +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "elfutils disabled, parsing ELF objects not supported"); #endif +} diff --git a/src/shared/elf-util.h b/src/shared/elf-util.h index 426a05ac42b..2a3251c28b0 100644 --- a/src/shared/elf-util.h +++ b/src/shared/elf-util.h @@ -1,20 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-json.h" - -#include "log.h" +#include "forward.h" #if HAVE_ELFUTILS int dlopen_dw(void); int dlopen_elf(void); +#endif /* Parse an ELF object in a forked process, so that errors while iterating over * untrusted and potentially malicious data do not propagate to the main caller's process. * If fork_disable_dump, the child process will not dump core if it crashes. */ int parse_elf_object(int fd, const char *executable, const char *root, bool fork_disable_dump, char **ret, sd_json_variant **ret_package_metadata); -#else -static inline int parse_elf_object(int fd, const char *executable, const char *root, bool fork_disable_dump, char **ret, sd_json_variant **ret_package_metadata) { - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "elfutils disabled, parsing ELF objects not supported"); -} -#endif diff --git a/src/shared/enable-mempool.c b/src/shared/enable-mempool.c index fd582c0e78f..1529959922a 100644 --- a/src/shared/enable-mempool.c +++ b/src/shared/enable-mempool.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "env-util.h" #include "mempool.h" #include "process-util.h" diff --git a/src/shared/env-file-label.h b/src/shared/env-file-label.h index 5ba45e40057..5309eabff4e 100644 --- a/src/shared/env-file-label.h +++ b/src/shared/env-file-label.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "forward.h" + /* These functions are split out of fileio.h (and not for example just flags to the functions they wrap) in order to * optimize linking: This way, -lselinux is needed only for the callers of these functions that need selinux, but not * for all */ diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index 85fd2a09734..bf0095a5ff6 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -1,13 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include #include #include "alloc-util.h" #include "conf-parser.h" +#include "errno-util.h" +#include "ether-addr-util.h" #include "ethtool-util.h" #include "extract-word.h" #include "fd-util.h" @@ -17,8 +18,10 @@ #include "parse-util.h" #include "socket-util.h" #include "string-table.h" +#include "string-util.h" #include "strv.h" #include "strxcpyx.h" +#include "time-util.h" static const char* const duplex_table[_DUP_MAX] = { [DUP_FULL] = "full", diff --git a/src/shared/ethtool-util.h b/src/shared/ethtool-util.h index c363aed23f6..eea27fb381d 100644 --- a/src/shared/ethtool-util.h +++ b/src/shared/ethtool-util.h @@ -2,12 +2,9 @@ #pragma once #include -#include -#include -#include "conf-parser.h" -#include "ether-addr-util.h" -#include "time-util.h" +#include "conf-parser-forward.h" +#include "forward.h" #define N_ADVERTISE 4 diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index acd476c692e..83dbc6cbab5 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include -#include -#include +#include #include #include "alloc-util.h" @@ -18,18 +15,16 @@ #include "fd-util.h" #include "fileio.h" #include "hashmap.h" -#include "macro.h" -#include "missing_syscall.h" +#include "log.h" #include "path-util.h" #include "process-util.h" #include "serialize.h" -#include "set.h" -#include "signal-util.h" #include "stat-util.h" #include "string-table.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" +#include "time-util.h" #define EXIT_SKIP_REMAINING 77 diff --git a/src/shared/exec-util.h b/src/shared/exec-util.h index 52acf342c33..fcc1ad065fd 100644 --- a/src/shared/exec-util.h +++ b/src/shared/exec-util.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "time-util.h" +#include "forward.h" typedef int (*gather_stdout_callback_t) (int fd, void *arg); diff --git a/src/shared/exit-status.c b/src/shared/exit-status.c index 0ac688b7635..d7567dc026f 100644 --- a/src/shared/exit-status.c +++ b/src/shared/exit-status.c @@ -5,9 +5,7 @@ #include #include "exit-status.h" -#include "macro.h" #include "parse-util.h" -#include "set.h" #include "string-util.h" const ExitStatusMapping exit_status_mappings[256] = { diff --git a/src/shared/exit-status.h b/src/shared/exit-status.h index c22cba05b2a..920caf51758 100644 --- a/src/shared/exit-status.h +++ b/src/shared/exit-status.h @@ -1,11 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - #include "bitmap.h" -#include "hashmap.h" -#include "macro.h" +#include "forward.h" /* This defines pretty names for the LSB 'start' verb exit codes. Note that they shouldn't be confused with * the LSB 'status' verb exit codes which are defined very differently. For details see: diff --git a/src/shared/extension-util.c b/src/shared/extension-util.c index d8b16b94e16..afaea7e3ae9 100644 --- a/src/shared/extension-util.c +++ b/src/shared/extension-util.c @@ -7,6 +7,7 @@ #include "extension-util.h" #include "log.h" #include "os-util.h" +#include "string-util.h" #include "strv.h" int extension_release_validate( diff --git a/src/shared/extension-util.h b/src/shared/extension-util.h index 3cad219d51b..8bc0359820a 100644 --- a/src/shared/extension-util.h +++ b/src/shared/extension-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "os-util.h" +#include "forward.h" /* Given an image name (for logging purposes), a set of os-release values from the host and a key-value pair * vector of extension-release variables, check that the distro and (system extension level or distro diff --git a/src/shared/factory-reset.c b/src/shared/factory-reset.c index 82f22d696f8..46a103eeebd 100644 --- a/src/shared/factory-reset.c +++ b/src/shared/factory-reset.c @@ -1,11 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "sd-json.h" #include "alloc-util.h" #include "efivars.h" #include "env-util.h" #include "factory-reset.h" +#include "log.h" #include "os-util.h" #include "proc-cmdline.h" #include "string-table.h" diff --git a/src/shared/factory-reset.h b/src/shared/factory-reset.h index 49ae7007b06..06903fca182 100644 --- a/src/shared/factory-reset.h +++ b/src/shared/factory-reset.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "errno-list.h" -#include "macro.h" +#include "forward.h" typedef enum FactoryResetMode { FACTORY_RESET_UNSUPPORTED, /* feature not available on this OS */ diff --git a/src/shared/fdisk-util.c b/src/shared/fdisk-util.c index bca81b30a0f..2a0b7d765b3 100644 --- a/src/shared/fdisk-util.c +++ b/src/shared/fdisk-util.c @@ -8,6 +8,7 @@ #include "fdisk-util.h" #include "log.h" #include "parse-util.h" +#include "string-util.h" #if HAVE_LIBFDISK diff --git a/src/shared/fdisk-util.h b/src/shared/fdisk-util.h index 316a763b0d3..eb4b3231a04 100644 --- a/src/shared/fdisk-util.h +++ b/src/shared/fdisk-util.h @@ -3,11 +3,9 @@ #if HAVE_LIBFDISK -#include +#include /* IWYU pragma: export */ -#include "sd-id128.h" - -#include "memory-util.h" +#include "forward.h" DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_context*, fdisk_unref_context, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct fdisk_partition*, fdisk_unref_partition, NULL); diff --git a/src/shared/fdset.c b/src/shared/fdset.c index 7f4b15b1790..832e7fda607 100644 --- a/src/shared/fdset.c +++ b/src/shared/fdset.c @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include #include #include "sd-daemon.h" @@ -13,11 +11,10 @@ #include "fd-util.h" #include "fdset.h" #include "log.h" -#include "macro.h" #include "parse-util.h" -#include "path-util.h" #include "set.h" #include "stat-util.h" +#include "string-util.h" #define MAKE_SET(s) ((Set*) s) #define MAKE_FDSET(s) ((FDSet*) s) diff --git a/src/shared/fdset.h b/src/shared/fdset.h index 3e69d32146c..96a17c78350 100644 --- a/src/shared/fdset.h +++ b/src/shared/fdset.h @@ -1,13 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "hashmap.h" -#include "macro.h" -#include "set.h" - -typedef struct FDSet FDSet; +#include "forward.h" +#include "iterator.h" FDSet* fdset_new(void); FDSet* fdset_free(FDSet *s); diff --git a/src/shared/fido2-util.c b/src/shared/fido2-util.c index b0ec7ec4100..06c74a4851a 100644 --- a/src/shared/fido2-util.c +++ b/src/shared/fido2-util.c @@ -1,8 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "alloc-util.h" #include "fido2-util.h" #include "fileio.h" +#include "iovec-util.h" #include "libfido2-util.h" #include "log.h" #include "random-util.h" diff --git a/src/shared/fido2-util.h b/src/shared/fido2-util.h index 73f39b43caf..8eccf2cc0db 100644 --- a/src/shared/fido2-util.h +++ b/src/shared/fido2-util.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "iovec-util.h" +#include "forward.h" int fido2_generate_salt(struct iovec *ret_salt); int fido2_read_salt_file(const char *filename, uint64_t offset, const char *client, const char *node, struct iovec *ret_salt); diff --git a/src/shared/find-esp.c b/src/shared/find-esp.c index e0550a7a09c..639076384ea 100644 --- a/src/shared/find-esp.c +++ b/src/shared/find-esp.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include +#include #include "sd-device.h" +#include "sd-gpt.h" #include "sd-id128.h" #include "alloc-util.h" @@ -16,12 +19,12 @@ #include "errno-util.h" #include "fd-util.h" #include "find-esp.h" -#include "gpt.h" #include "mount-util.h" #include "parse-util.h" #include "path-util.h" #include "stat-util.h" #include "string-util.h" +#include "strv.h" #include "virt.h" typedef enum VerifyESPFlags { diff --git a/src/shared/find-esp.h b/src/shared/find-esp.h index 2e132a74aa0..1dd0f486008 100644 --- a/src/shared/find-esp.h +++ b/src/shared/find-esp.h @@ -2,11 +2,7 @@ #pragma once -#include -#include -#include - -#include "sd-id128.h" +#include "forward.h" int find_esp_and_warn_at(int rfd, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid); int find_esp_and_warn(const char *root, const char *path, int unprivileged_mode, char **ret_path, uint32_t *ret_part, uint64_t *ret_pstart, uint64_t *ret_psize, sd_id128_t *ret_uuid, dev_t *ret_devid); diff --git a/src/shared/firewall-util-iptables.c b/src/shared/firewall-util-iptables.c index 35b4c24e2de..1e5b59f0ddb 100644 --- a/src/shared/firewall-util-iptables.c +++ b/src/shared/firewall-util-iptables.c @@ -1,23 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include #include -#include #include #include #include -#include -#include #include #include "alloc-util.h" #include "dlfcn-util.h" -#include "firewall-util.h" #include "firewall-util-private.h" #include "in-addr-util.h" -#include "macro.h" +#include "log.h" #include "socket-util.h" static DLSYM_PROTOTYPE(iptc_check_entry) = NULL; diff --git a/src/shared/firewall-util-nft.c b/src/shared/firewall-util-nft.c index f8273f340c9..66c0665d666 100644 --- a/src/shared/firewall-util-nft.c +++ b/src/shared/firewall-util-nft.c @@ -1,14 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include #include #include #include #include -#include +#include #include #include "sd-netlink.h" @@ -19,12 +16,12 @@ #include "firewall-util.h" #include "firewall-util-private.h" #include "in-addr-util.h" -#include "macro.h" +#include "log.h" #include "netlink-internal.h" -#include "netlink-util.h" #include "parse-util.h" #include "socket-util.h" #include "string-table.h" +#include "string-util.h" #include "time-util.h" #define NFT_SYSTEMD_DNAT_MAP_NAME "map_port_ipport" diff --git a/src/shared/firewall-util-private.h b/src/shared/firewall-util-private.h index 2e9a2317110..7e965494c8d 100644 --- a/src/shared/firewall-util-private.h +++ b/src/shared/firewall-util-private.h @@ -1,13 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "sd-netlink.h" - #include "firewall-util.h" -#include "in-addr-util.h" +#include "forward.h" typedef enum FirewallBackend { FW_BACKEND_NONE, diff --git a/src/shared/firewall-util.c b/src/shared/firewall-util.c index e96b24a72d8..c8dfad5d336 100644 --- a/src/shared/firewall-util.c +++ b/src/shared/firewall-util.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include +#include #include #include "alloc-util.h" @@ -10,6 +9,7 @@ #include "log.h" #include "netlink-util.h" #include "string-table.h" +#include "string-util.h" static const char * const firewall_backend_table[_FW_BACKEND_MAX] = { [FW_BACKEND_NONE] = "none", diff --git a/src/shared/firewall-util.h b/src/shared/firewall-util.h index 2c79ab40817..d4acac55eed 100644 --- a/src/shared/firewall-util.h +++ b/src/shared/firewall-util.h @@ -1,11 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "conf-parser.h" -#include "in-addr-util.h" +#include "conf-parser-forward.h" +#include "forward.h" typedef struct FirewallContext FirewallContext; diff --git a/src/shared/fork-journal.c b/src/shared/fork-journal.c index 883d9b5195d..6e4a0300fff 100644 --- a/src/shared/fork-journal.c +++ b/src/shared/fork-journal.c @@ -1,20 +1,20 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include #include "build-path.h" #include "escape.h" #include "event-util.h" #include "exit-status.h" -#include "fd-util.h" #include "fork-journal.h" #include "log.h" #include "notify-recv.h" #include "parse-util.h" +#include "pidref.h" #include "process-util.h" +#include "runtime-scope.h" #include "signal-util.h" -#include "socket-util.h" #include "strv.h" static int on_child_exit(sd_event_source *s, const siginfo_t *si, void *userdata) { diff --git a/src/shared/fork-journal.h b/src/shared/fork-journal.h index 1825a7f5eb7..a53a452b26a 100644 --- a/src/shared/fork-journal.h +++ b/src/shared/fork-journal.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "macro.h" -#include "pidref.h" -#include "runtime-scope.h" -#include "set.h" +#include "forward.h" int journal_fork(RuntimeScope scope, char * const *units, PidRef *ret_pidref); diff --git a/src/shared/format-table.c b/src/shared/format-table.c index 7c3539abaa5..c672be326d2 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -1,28 +1,22 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include "sd-id128.h" #include "alloc-util.h" #include "devnum-util.h" -#include "fd-util.h" #include "fileio.h" #include "format-ifname.h" #include "format-table.h" #include "format-util.h" -#include "fs-util.h" #include "glyph-util.h" #include "gunicode.h" -#include "id128-util.h" #include "in-addr-util.h" -#include "log.h" #include "memory-util.h" #include "memstream-util.h" #include "pager.h" -#include "parse-util.h" #include "path-util.h" #include "pretty-print.h" #include "process-util.h" diff --git a/src/shared/format-table.h b/src/shared/format-table.h index 1a4cd56f4d3..beea0cbe1b4 100644 --- a/src/shared/format-table.h +++ b/src/shared/format-table.h @@ -1,14 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - #include "sd-json.h" -#include "macro.h" -#include "memory-util.h" +#include "forward.h" +#include "log.h" #include "pager.h" typedef enum TableDataType { diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index 82458536c57..57ab68deb67 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include @@ -11,7 +10,7 @@ #include "fstab-util.h" #include "initrd-util.h" #include "libmount-util.h" -#include "macro.h" +#include "log.h" #include "nulstr-util.h" #include "parse-util.h" #include "path-util.h" @@ -393,6 +392,10 @@ char* fstab_node_to_udev_node(const char *p) { return strdup(p); } +const char* fstab_path(void) { + return secure_getenv("SYSTEMD_FSTAB") ?: "/etc/fstab"; +} + bool fstab_is_bind(const char *options, const char *fstype) { if (fstab_test_option(options, "bind\0" "rbind\0")) diff --git a/src/shared/fstab-util.h b/src/shared/fstab-util.h index cf909c60f83..59d909d44f6 100644 --- a/src/shared/fstab-util.h +++ b/src/shared/fstab-util.h @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - -#include "assert-util.h" -#include "macro.h" +#include "forward.h" bool fstab_enabled_full(int enabled); static inline bool fstab_enabled(void) { @@ -53,8 +48,6 @@ int fstab_find_pri(const char *opts, int *ret); char* fstab_node_to_udev_node(const char *p); -static inline const char* fstab_path(void) { - return secure_getenv("SYSTEMD_FSTAB") ?: "/etc/fstab"; -} +const char* fstab_path(void); bool fstab_is_bind(const char *options, const char *fstype); diff --git a/src/shared/generator.c b/src/shared/generator.c index 86fcced0984..3a9d10ad69d 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include +#include #include #include "alloc-util.h" @@ -14,12 +15,10 @@ #include "generator.h" #include "initrd-util.h" #include "log.h" -#include "macro.h" #include "mkdir-label.h" #include "mountpoint-util.h" #include "parse-util.h" #include "path-util.h" -#include "process-util.h" #include "special.h" #include "specifier.h" #include "string-util.h" diff --git a/src/shared/generator.h b/src/shared/generator.h index 68ea9b376ff..8a1f55cc906 100644 --- a/src/shared/generator.h +++ b/src/shared/generator.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "errno-list.h" -#include "macro.h" +#include "forward.h" #include "main-func.h" int generator_open_unit_file_full(const char *dest, const char *source, const char *name, FILE **ret_file, char **ret_final_path, char **ret_temp_path); diff --git a/src/shared/geneve-util.h b/src/shared/geneve-util.h index 96a1eeaf6aa..b40c4ced0e5 100644 --- a/src/shared/geneve-util.h +++ b/src/shared/geneve-util.h @@ -3,7 +3,7 @@ #include -#include "conf-parser.h" +#include "forward.h" typedef enum GeneveDF { NETDEV_GENEVE_DF_UNSET = GENEVE_DF_UNSET, diff --git a/src/shared/gpt.c b/src/shared/gpt.c index a443cc5e993..9bb66b7c403 100644 --- a/src/shared/gpt.c +++ b/src/shared/gpt.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "gpt.h" #include "string-table.h" #include "string-util.h" diff --git a/src/shared/gpt.h b/src/shared/gpt.h index 7a67eddebee..309bb32bc22 100644 --- a/src/shared/gpt.h +++ b/src/shared/gpt.h @@ -1,13 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-gpt.h" +#include "sd-gpt.h" /* IWYU pragma: export */ #include "sd-id128.h" #include "architecture.h" -#include "id128-util.h" +#include "forward.h" #include "sparse-endian.h" /* maximum length of gpt label */ diff --git a/src/shared/group-record.c b/src/shared/group-record.c index f7dd3b73a40..85433b15374 100644 --- a/src/shared/group-record.c +++ b/src/shared/group-record.c @@ -5,6 +5,7 @@ #include "group-record.h" #include "json-util.h" #include "log.h" +#include "string-util.h" #include "strv.h" #include "uid-classification.h" #include "user-util.h" diff --git a/src/shared/group-record.h b/src/shared/group-record.h index bc45166b652..c450fd1a2e5 100644 --- a/src/shared/group-record.h +++ b/src/shared/group-record.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-json.h" - +#include "forward.h" #include "user-record.h" typedef struct GroupRecord { diff --git a/src/shared/hibernate-util.c b/src/shared/hibernate-util.c index 55ca4d5cf09..de1fdfe9b5b 100644 --- a/src/shared/hibernate-util.c +++ b/src/shared/hibernate-util.c @@ -3,19 +3,16 @@ Copyright © 2018 Dell Inc. ***/ +#include #include -#include #include -#include #include "alloc-util.h" #include "blockdev-util.h" #include "btrfs-util.h" -#include "device-util.h" #include "devnum-util.h" #include "efivars.h" #include "env-util.h" -#include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "hibernate-util.h" @@ -25,8 +22,6 @@ #include "path-util.h" #include "proc-cmdline.h" #include "stat-util.h" -#include "string-util.h" -#include "strv.h" #define HIBERNATION_SWAP_THRESHOLD 0.98 diff --git a/src/shared/hibernate-util.h b/src/shared/hibernate-util.h index 966cc39f1dd..719e2c0554c 100644 --- a/src/shared/hibernate-util.h +++ b/src/shared/hibernate-util.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - -#include "assert-util.h" +#include "forward.h" /* represents values for /sys/power/resume & /sys/power/resume_offset and the corresponding path */ typedef struct HibernationDevice { diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c index 33b6a05ad86..bb942838b7e 100644 --- a/src/shared/hostname-setup.c +++ b/src/shared/hostname-setup.c @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include #include #include @@ -18,7 +16,6 @@ #include "hostname-util.h" #include "initrd-util.h" #include "log.h" -#include "macro.h" #include "proc-cmdline.h" #include "siphash24.h" #include "string-table.h" diff --git a/src/shared/hostname-setup.h b/src/shared/hostname-setup.h index 526ea0b7ebd..d3cb59b3fcc 100644 --- a/src/shared/hostname-setup.h +++ b/src/shared/hostname-setup.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - -#include "macro.h" +#include "forward.h" typedef enum HostnameSource { HOSTNAME_STATIC, /* from /etc/hostname */ diff --git a/src/shared/hwdb-util.c b/src/shared/hwdb-util.c index 72946b8cb00..10d6e8ee48e 100644 --- a/src/shared/hwdb-util.c +++ b/src/shared/hwdb-util.c @@ -3,10 +3,10 @@ #include #include #include +#include #include "alloc-util.h" #include "conf-files.h" -#include "env-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -21,6 +21,7 @@ #include "strbuf.h" #include "string-util.h" #include "strv.h" +#include "time-util.h" #include "tmpfile-util.h" #include "verbs.h" diff --git a/src/shared/hwdb-util.h b/src/shared/hwdb-util.h index 00610b18d49..6e41b8b5887 100644 --- a/src/shared/hwdb-util.h +++ b/src/shared/hwdb-util.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "sd-hwdb.h" /* IWYU pragma: export */ -#include "sd-hwdb.h" +#include "forward.h" bool hwdb_should_reload(sd_hwdb *hwdb); int hwdb_update(const char *root, const char *hwdb_bin_dir, bool strict, bool compat); diff --git a/src/shared/id128-print.c b/src/shared/id128-print.c index 788be8089ae..3656da142a5 100644 --- a/src/shared/id128-print.c +++ b/src/shared/id128-print.c @@ -8,7 +8,6 @@ #include "id128-print.h" #include "log.h" #include "pretty-print.h" -#include "terminal-util.h" int id128_pretty_print_sample(const char *name, sd_id128_t id) { _cleanup_free_ char *man_link = NULL, *mod_link = NULL; diff --git a/src/shared/id128-print.h b/src/shared/id128-print.h index 4e3b9ba4d1a..0048e957293 100644 --- a/src/shared/id128-print.h +++ b/src/shared/id128-print.h @@ -2,11 +2,10 @@ #pragma once -#include -#include - #include "sd-id128.h" +#include "forward.h" + typedef enum Id128PrettyPrintMode { ID128_PRINT_ID128, ID128_PRINT_UUID, diff --git a/src/shared/idn-util.c b/src/shared/idn-util.c index ccb2db411f0..6613023754f 100644 --- a/src/shared/idn-util.c +++ b/src/shared/idn-util.c @@ -7,7 +7,6 @@ # include #endif -#include "alloc-util.h" #include "dlfcn-util.h" #include "idn-util.h" #include "log.h" diff --git a/src/shared/idn-util.h b/src/shared/idn-util.h index 986f2cfd9e3..734ec9d999c 100644 --- a/src/shared/idn-util.h +++ b/src/shared/idn-util.h @@ -8,8 +8,7 @@ # include #endif -#include -#include +#include "forward.h" #if HAVE_LIBIDN2 || HAVE_LIBIDN #include "dlfcn-util.h" diff --git a/src/shared/ima-util.h b/src/shared/ima-util.h index 922db786e68..fb864f6063f 100644 --- a/src/shared/ima-util.h +++ b/src/shared/ima-util.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" bool use_ima(void); diff --git a/src/shared/image-policy.c b/src/shared/image-policy.c index e08fbba9664..16fc91e1fe9 100644 --- a/src/shared/image-policy.c +++ b/src/shared/image-policy.c @@ -3,6 +3,7 @@ #include "alloc-util.h" #include "extract-word.h" #include "image-policy.h" +#include "log.h" #include "logarithm.h" #include "sort-util.h" #include "string-util.h" @@ -774,6 +775,10 @@ int image_policy_intersect(const ImagePolicy *a, const ImagePolicy *b, ImagePoli return 0; } +ImagePolicy* image_policy_free(ImagePolicy *p) { + return mfree(p); +} + int image_policy_ignore_designators(const ImagePolicy *p, const PartitionDesignator table[], size_t n_table, ImagePolicy **ret) { assert(p); assert(table || n_table == 0); diff --git a/src/shared/image-policy.h b/src/shared/image-policy.h index afb0d4fe9e9..6f5c1d23d6d 100644 --- a/src/shared/image-policy.h +++ b/src/shared/image-policy.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "conf-parser.h" -#include "dissect-image.h" -#include "errno-list.h" +#include "conf-parser-forward.h" +#include "forward.h" +#include "gpt.h" typedef enum PartitionPolicyFlags { /* Not all policy flags really make sense on all partition types, see comments. But even if they @@ -96,9 +96,7 @@ int image_policy_equivalent(const ImagePolicy *a, const ImagePolicy *b); /* ch int image_policy_intersect(const ImagePolicy *a, const ImagePolicy *b, ImagePolicy **ret); -static inline ImagePolicy* image_policy_free(ImagePolicy *p) { - return mfree(p); -} +ImagePolicy* image_policy_free(ImagePolicy *p); DEFINE_TRIVIAL_CLEANUP_FUNC(ImagePolicy*, image_policy_free); diff --git a/src/shared/import-util.c b/src/shared/import-util.c index 0c61ea449f5..50794a86ba9 100644 --- a/src/shared/import-util.c +++ b/src/shared/import-util.c @@ -1,16 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" #include "btrfs-util.h" #include "chattr-util.h" #include "errno-util.h" #include "import-util.h" #include "log.h" -#include "macro.h" #include "nulstr-util.h" -#include "path-util.h" #include "string-table.h" #include "string-util.h" diff --git a/src/shared/import-util.h b/src/shared/import-util.h index 91bc3083e46..8779293cdff 100644 --- a/src/shared/import-util.h +++ b/src/shared/import-util.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "macro.h" +#include "forward.h" typedef enum ImportType { IMPORT_RAW, diff --git a/src/shared/in-addr-prefix-util.c b/src/shared/in-addr-prefix-util.c index edccca5a5b9..0f4dcfb3614 100644 --- a/src/shared/in-addr-prefix-util.c +++ b/src/shared/in-addr-prefix-util.c @@ -2,8 +2,12 @@ #include "alloc-util.h" #include "extract-word.h" +#include "hash-funcs.h" #include "hostname-util.h" #include "in-addr-prefix-util.h" +#include "log.h" +#include "set.h" +#include "siphash24.h" #include "string-util.h" /* 0.0.0.0/0 */ diff --git a/src/shared/in-addr-prefix-util.h b/src/shared/in-addr-prefix-util.h index 53aaad356cd..b18609a1212 100644 --- a/src/shared/in-addr-prefix-util.h +++ b/src/shared/in-addr-prefix-util.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "conf-parser.h" +#include "conf-parser-forward.h" +#include "forward.h" #include "in-addr-util.h" -#include "set.h" struct in_addr_prefix { int family; diff --git a/src/shared/initreq.h b/src/shared/initreq.h index 205a3be44a3..8d2e08c6c9f 100644 --- a/src/shared/initreq.h +++ b/src/shared/initreq.h @@ -6,7 +6,7 @@ #pragma once -#include +#include "forward.h" #if defined(__FreeBSD_kernel__) # define INIT_FIFO "/etc/.initctl" diff --git a/src/shared/install-file.c b/src/shared/install-file.c index ea8cbbf928e..c3de84f5790 100644 --- a/src/shared/install-file.c +++ b/src/shared/install-file.c @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include +#include #include "btrfs-util.h" #include "chattr-util.h" @@ -9,7 +11,6 @@ #include "fs-util.h" #include "install-file.h" #include "log.h" -#include "missing_syscall.h" #include "rm-rf.h" #include "sync-util.h" diff --git a/src/shared/install-file.h b/src/shared/install-file.h index af07ab29d22..e72dac3e971 100644 --- a/src/shared/install-file.h +++ b/src/shared/install-file.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "forward.h" + typedef enum InstallFileFlags { INSTALL_REPLACE = 1 << 0, /* Replace an existing inode */ INSTALL_READ_ONLY = 1 << 1, /* Call fs_make_very_read_only() to make the inode comprehensively read-only */ diff --git a/src/shared/install-printf.c b/src/shared/install-printf.c index 501338f188a..81a5e4a73e6 100644 --- a/src/shared/install-printf.c +++ b/src/shared/install-printf.c @@ -1,18 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include -#include - #include "alloc-util.h" -#include "format-util.h" #include "install.h" #include "install-printf.h" -#include "macro.h" #include "specifier.h" #include "string-util.h" #include "unit-name.h" -#include "user-util.h" static int specifier_prefix_and_instance(char specifier, const void *data, const char *root, const void *userdata, char **ret) { const InstallInfo *i = ASSERT_PTR(userdata); diff --git a/src/shared/install-printf.h b/src/shared/install-printf.h index 8c7842ba2c0..f88449ffe1d 100644 --- a/src/shared/install-printf.h +++ b/src/shared/install-printf.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "install.h" -#include "unit-name.h" +#include "forward.h" int install_name_printf( RuntimeScope scope, diff --git a/src/shared/install.c b/src/shared/install.c index 30f2de388e0..8c6909ddf2e 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -1,12 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include -#include -#include #include -#include #include #include "alloc-util.h" @@ -16,17 +12,16 @@ #include "conf-parser.h" #include "constants.h" #include "dirent-util.h" -#include "errno-list.h" +#include "errno-util.h" #include "extract-word.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "glyph-util.h" #include "hashmap.h" #include "install.h" #include "install-printf.h" -#include "locale-util.h" #include "log.h" -#include "macro.h" #include "mkdir-label.h" #include "path-lookup.h" #include "path-util.h" @@ -38,6 +33,7 @@ #include "string-util.h" #include "strv.h" #include "unit-file.h" +#include "unit-name.h" #define UNIT_FILE_FOLLOW_SYMLINK_MAX 64 diff --git a/src/shared/install.h b/src/shared/install.h index 56e4d0f742c..0f9b0798aa8 100644 --- a/src/shared/install.h +++ b/src/shared/install.h @@ -1,32 +1,19 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -typedef enum UnitFilePresetMode UnitFilePresetMode; -typedef enum InstallChangeType InstallChangeType; -typedef enum UnitFileFlags UnitFileFlags; -typedef enum InstallMode InstallMode; -typedef struct InstallChange InstallChange; -typedef struct UnitFileList UnitFileList; -typedef struct InstallInfo InstallInfo; - -#include "hashmap.h" -#include "macro.h" -#include "path-lookup.h" -#include "strv.h" +#include "forward.h" +#include "runtime-scope.h" #include "unit-file.h" -#include "unit-name.h" -enum UnitFilePresetMode { +typedef enum UnitFilePresetMode { UNIT_FILE_PRESET_FULL, UNIT_FILE_PRESET_ENABLE_ONLY, UNIT_FILE_PRESET_DISABLE_ONLY, _UNIT_FILE_PRESET_MODE_MAX, _UNIT_FILE_PRESET_MODE_INVALID = -EINVAL, -}; +} UnitFilePresetMode; -enum InstallChangeType { +typedef enum InstallChangeType { INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, INSTALL_CHANGE_IS_MASKED, @@ -37,31 +24,31 @@ enum InstallChangeType { _INSTALL_CHANGE_TYPE_MAX, _INSTALL_CHANGE_INVALID = -EINVAL, _INSTALL_CHANGE_ERRNO_MAX = -ERRNO_MAX, /* Ensure this type covers the whole negative errno range */ -}; +} InstallChangeType; static inline bool INSTALL_CHANGE_TYPE_VALID(InstallChangeType t) { return t >= _INSTALL_CHANGE_ERRNO_MAX && t < _INSTALL_CHANGE_TYPE_MAX; } -enum UnitFileFlags { +typedef enum UnitFileFlags { UNIT_FILE_RUNTIME = 1 << 0, /* Public API via DBUS, do not change */ UNIT_FILE_FORCE = 1 << 1, /* Public API via DBUS, do not change */ UNIT_FILE_PORTABLE = 1 << 2, /* Public API via DBUS, do not change */ UNIT_FILE_DRY_RUN = 1 << 3, UNIT_FILE_IGNORE_AUXILIARY_FAILURE = 1 << 4, _UNIT_FILE_FLAGS_MASK_PUBLIC = UNIT_FILE_RUNTIME|UNIT_FILE_PORTABLE|UNIT_FILE_FORCE, -}; +} UnitFileFlags; /* type can be either one of the INSTALL_CHANGE_SYMLINK, INSTALL_CHANGE_UNLINK, … listed above, or a negative * errno value. * * If source is specified, it should be the contents of the path symlink. In case of an error, source should * be the existing symlink contents or NULL. */ -struct InstallChange { +typedef struct InstallChange { int type; /* INSTALL_CHANGE_SYMLINK, … if positive, errno if negative */ char *path; char *source; -}; +} InstallChange; static inline bool install_changes_have_modification(const InstallChange *changes, size_t n_changes) { FOREACH_ARRAY(i, changes, n_changes) @@ -70,21 +57,21 @@ static inline bool install_changes_have_modification(const InstallChange *change return false; } -struct UnitFileList { +typedef struct UnitFileList { char *path; UnitFileState state; -}; +} UnitFileList; -enum InstallMode { +typedef enum InstallMode { INSTALL_MODE_REGULAR, INSTALL_MODE_LINKED, INSTALL_MODE_ALIAS, INSTALL_MODE_MASKED, _INSTALL_MODE_MAX, _INSTALL_MODE_INVALID = -EINVAL, -}; +} InstallMode; -struct InstallInfo { +typedef struct InstallInfo { char *name; char *path; char *root; @@ -100,7 +87,7 @@ struct InstallInfo { InstallMode install_mode; bool auxiliary; -}; +} InstallInfo; int unit_file_enable( RuntimeScope scope, diff --git a/src/shared/ip-protocol-list.c b/src/shared/ip-protocol-list.c index 606d2b2dbee..676ef3bf5a6 100644 --- a/src/shared/ip-protocol-list.c +++ b/src/shared/ip-protocol-list.c @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include - #include "alloc-util.h" #include "ip-protocol-list.h" -#include "macro.h" #include "parse-util.h" #include "string-util.h" diff --git a/src/shared/ip-protocol-list.h b/src/shared/ip-protocol-list.h index b8715701320..cb8599787bf 100644 --- a/src/shared/ip-protocol-list.h +++ b/src/shared/ip-protocol-list.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" const char* ip_protocol_to_name(int id); int ip_protocol_from_name(const char *name); diff --git a/src/shared/ipvlan-util.c b/src/shared/ipvlan-util.c index 1f2e2ffe7b5..1906c8026f4 100644 --- a/src/shared/ipvlan-util.c +++ b/src/shared/ipvlan-util.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "ipvlan-util.h" #include "string-table.h" diff --git a/src/shared/ipvlan-util.h b/src/shared/ipvlan-util.h index bc286d9d881..c96201742b5 100644 --- a/src/shared/ipvlan-util.h +++ b/src/shared/ipvlan-util.h @@ -1,11 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include #include -#include -#include "macro.h" +#include "forward.h" typedef enum IPVlanMode { NETDEV_IPVLAN_MODE_L2 = IPVLAN_MODE_L2, diff --git a/src/shared/journal-file-util.c b/src/shared/journal-file-util.c index 74f85fadced..ce799e9256e 100644 --- a/src/shared/journal-file-util.c +++ b/src/shared/journal-file-util.c @@ -3,20 +3,17 @@ #include #include +#include "sd-event.h" + #include "alloc-util.h" #include "chattr-util.h" #include "copy.h" #include "errno-util.h" -#include "fd-util.h" -#include "format-util.h" #include "journal-authenticate.h" #include "journal-file-util.h" #include "log.h" -#include "path-util.h" -#include "random-util.h" #include "set.h" -#include "stat-util.h" -#include "sync-util.h" +#include "string-util.h" #define PAYLOAD_BUFFER_SIZE (16U * 1024U) #define MINIMUM_HOLE_SIZE (1U * 1024U * 1024U / 2U) diff --git a/src/shared/journal-file-util.h b/src/shared/journal-file-util.h index 780fe5368ea..978ff1c1605 100644 --- a/src/shared/journal-file-util.h +++ b/src/shared/journal-file-util.h @@ -1,7 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "journal-file.h" +#include "journal-file.h" /* IWYU pragma: export */ +#include "forward.h" int journal_file_set_offline(JournalFile *f, bool wait); bool journal_file_is_offlining(JournalFile *f); diff --git a/src/shared/journal-importer.c b/src/shared/journal-importer.c index a7b491f024e..43681f5d227 100644 --- a/src/shared/journal-importer.c +++ b/src/shared/journal-importer.c @@ -1,17 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include "alloc-util.h" #include "errno-util.h" #include "escape.h" #include "fd-util.h" -#include "io-util.h" #include "journal-file.h" #include "journal-importer.h" -#include "journal-util.h" #include "log.h" #include "parse-util.h" #include "string-util.h" diff --git a/src/shared/journal-importer.h b/src/shared/journal-importer.h index 50d378f7675..13f699ae4d3 100644 --- a/src/shared/journal-importer.h +++ b/src/shared/journal-importer.h @@ -2,13 +2,9 @@ #pragma once -#include -#include -#include - #include "sd-id128.h" -#include "io-util.h" +#include "forward.h" #include "iovec-wrapper.h" #include "time-util.h" diff --git a/src/shared/journal-util.c b/src/shared/journal-util.c index 73c582475e3..e30bd522bbe 100644 --- a/src/shared/journal-util.c +++ b/src/shared/journal-util.c @@ -1,5 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" +#include "sd-journal.h" + #include "acl-util.h" #include "alloc-util.h" #include "bus-error.h" @@ -112,7 +115,7 @@ int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_use HASHMAP_FOREACH_KEY(path, code, j->errors) { int err; - err = abs(PTR_TO_INT(code)); + err = ABS(PTR_TO_INT(code)); switch (err) { case EACCES: diff --git a/src/shared/journal-util.h b/src/shared/journal-util.h index 5bd8e340b2e..2805ae19763 100644 --- a/src/shared/journal-util.h +++ b/src/shared/journal-util.h @@ -1,10 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "sd-journal.h" /* IWYU pragma: export */ -#include "sd-journal.h" +#include "forward.h" int journal_access_blocked(sd_journal *j); int journal_access_check_and_warn(sd_journal *j, bool quiet, bool want_other_users); diff --git a/src/shared/kbd-util.h b/src/shared/kbd-util.h index a8e365e3ca4..35ae976baaf 100644 --- a/src/shared/kbd-util.h +++ b/src/shared/kbd-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int keymap_directories(char ***ret); int get_keymaps(char ***ret); diff --git a/src/shared/kernel-config.c b/src/shared/kernel-config.c index c1a0a952f53..9bc984e9190 100644 --- a/src/shared/kernel-config.c +++ b/src/shared/kernel-config.c @@ -1,13 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" #include "conf-parser.h" #include "kernel-config.h" -#include "macro.h" #include "path-util.h" -#include "strv.h" int load_kernel_install_conf( const char *root, diff --git a/src/shared/kernel-config.h b/src/shared/kernel-config.h index 568187061cf..2c149ba3bd1 100644 --- a/src/shared/kernel-config.h +++ b/src/shared/kernel-config.h @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "forward.h" + int load_kernel_install_conf( const char *root, const char *conf_root, diff --git a/src/shared/kernel-image.c b/src/shared/kernel-image.c index 3e31ec92ef2..73a78a920ce 100644 --- a/src/shared/kernel-image.c +++ b/src/shared/kernel-image.c @@ -3,13 +3,11 @@ #include "alloc-util.h" #include "env-file.h" #include "fd-util.h" -#include "fileio.h" #include "kernel-image.h" #include "log.h" -#include "os-util.h" -#include "parse-util.h" #include "pe-binary.h" #include "string-table.h" +#include "string-util.h" #define PE_SECTION_READ_MAX (16U*1024U) diff --git a/src/shared/kernel-image.h b/src/shared/kernel-image.h index e9526e87eba..0474728050c 100644 --- a/src/shared/kernel-image.h +++ b/src/shared/kernel-image.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "macro.h" +#include "forward.h" typedef enum KernelImageType { KERNEL_IMAGE_TYPE_UNKNOWN, diff --git a/src/shared/killall.c b/src/shared/killall.c index 9d853fd566b..5db307560f1 100644 --- a/src/shared/killall.c +++ b/src/shared/killall.c @@ -3,26 +3,22 @@ Copyright © 2010 ProFUSION embedded systems ***/ -#include #include #include -#include #include "alloc-util.h" -#include "constants.h" -#include "dirent-util.h" #include "errno-util.h" #include "fd-util.h" #include "format-util.h" #include "initrd-util.h" #include "killall.h" #include "log.h" -#include "parse-util.h" +#include "pidref.h" #include "process-util.h" #include "set.h" -#include "stdio-util.h" #include "string-util.h" #include "terminal-util.h" +#include "time-util.h" static int argv_has_at(const PidRef *pid) { int r; diff --git a/src/shared/killall.h b/src/shared/killall.h index d8ef96f7d1c..1eb198acec4 100644 --- a/src/shared/killall.h +++ b/src/shared/killall.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "time-util.h" +#include "forward.h" int broadcast_signal(int sig, bool wait_for_exit, bool send_sighup, usec_t timeout); diff --git a/src/shared/label-util.c b/src/shared/label-util.c index a7723438662..b4d5d4505a8 100644 --- a/src/shared/label-util.c +++ b/src/shared/label-util.c @@ -1,15 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include "btrfs-util.h" #include "errno-util.h" #include "fs-util.h" -#include "label.h" #include "label-util.h" -#include "macro.h" #include "selinux-util.h" #include "smack-util.h" diff --git a/src/shared/label-util.h b/src/shared/label-util.h index 5a19a4cd433..b135c0f1ab7 100644 --- a/src/shared/label-util.h +++ b/src/shared/label-util.h @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include +#include "forward.h" +#include "label.h" /* IWYU pragma: export */ typedef enum LabelFixFlags { LABEL_IGNORE_ENOENT = 1 << 0, diff --git a/src/shared/libarchive-util.c b/src/shared/libarchive-util.c index 9c341504772..dcc9efa810d 100644 --- a/src/shared/libarchive-util.c +++ b/src/shared/libarchive-util.c @@ -1,7 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "libarchive-util.h" -#include "log.h" #if HAVE_LIBARCHIVE static void *libarchive_dl = NULL; diff --git a/src/shared/libarchive-util.h b/src/shared/libarchive-util.h index 2695b18a7fb..aeda1ecb4cb 100644 --- a/src/shared/libarchive-util.h +++ b/src/shared/libarchive-util.h @@ -1,15 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "dlfcn-util.h" +#include "forward.h" #if HAVE_LIBARCHIVE -#include -#include +#include /* IWYU pragma: export */ +#include /* IWYU pragma: export */ -#include "memory-util.h" +#include "dlfcn-util.h" extern DLSYM_PROTOTYPE(archive_entry_free); extern DLSYM_PROTOTYPE(archive_entry_new); diff --git a/src/shared/libaudit-util.c b/src/shared/libaudit-util.c index da85c84d203..eb738d22748 100644 --- a/src/shared/libaudit-util.c +++ b/src/shared/libaudit-util.c @@ -1,11 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include #include +#include "errno-util.h" #include "fd-util.h" #include "iovec-util.h" #include "libaudit-util.h" diff --git a/src/shared/libaudit-util.h b/src/shared/libaudit-util.h index 1887e180c22..bd91a1cb938 100644 --- a/src/shared/libaudit-util.h +++ b/src/shared/libaudit-util.h @@ -2,10 +2,10 @@ #pragma once #if HAVE_AUDIT -# include +# include /* IWYU pragma: export */ #endif -#include +#include "forward.h" bool use_audit(void); diff --git a/src/shared/libcrypt-util.c b/src/shared/libcrypt-util.c index c04c0eeea86..7c48b5e0d30 100644 --- a/src/shared/libcrypt-util.c +++ b/src/shared/libcrypt-util.c @@ -15,16 +15,12 @@ # include #endif -#include #include #include "alloc-util.h" #include "errno-util.h" #include "libcrypt-util.h" #include "log.h" -#include "macro.h" -#include "memory-util.h" -#include "random-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/libcrypt-util.h b/src/shared/libcrypt-util.h index 8abaec2112c..25790f9ad3f 100644 --- a/src/shared/libcrypt-util.h +++ b/src/shared/libcrypt-util.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "forward.h" int make_salt(char **ret); int hash_password_full(const char *password, void **cd_data, int *cd_size, char **ret); diff --git a/src/shared/libfido2-util.c b/src/shared/libfido2-util.c index f01b0016d48..0cc64c8674e 100644 --- a/src/shared/libfido2-util.c +++ b/src/shared/libfido2-util.c @@ -10,7 +10,7 @@ #include "dlfcn-util.h" #include "format-table.h" #include "glyph-util.h" -#include "memory-util.h" +#include "iovec-util.h" #include "plymouth-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/libfido2-util.h b/src/shared/libfido2-util.h index 18aec372a7f..dbb4f1fc922 100644 --- a/src/shared/libfido2-util.h +++ b/src/shared/libfido2-util.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "iovec-util.h" -#include "macro.h" +#include "forward.h" #define FIDO2_SALT_SIZE 32U diff --git a/src/shared/libmount-util.c b/src/shared/libmount-util.c index 2e7b28caa52..aada5a7eb53 100644 --- a/src/shared/libmount-util.c +++ b/src/shared/libmount-util.c @@ -2,6 +2,7 @@ #include +#include "fstab-util.h" #include "libmount-util.h" #include "log.h" @@ -40,6 +41,13 @@ int libmount_parse_full( return 0; } +int libmount_parse_fstab( + struct libmnt_table **ret_table, + struct libmnt_iter **ret_iter) { + + return libmount_parse_full(fstab_path(), NULL, ret_table, ret_iter); +} + int libmount_is_leaf( struct libmnt_table *table, struct libmnt_fs *fs) { diff --git a/src/shared/libmount-util.h b/src/shared/libmount-util.h index b559fa59758..b6bd7f1d592 100644 --- a/src/shared/libmount-util.h +++ b/src/shared/libmount-util.h @@ -2,11 +2,9 @@ #pragma once /* This needs to be after sys/mount.h */ -#include +#include /* IWYU pragma: export */ -#include "fstab-util.h" -#include "macro.h" -#include "memory-util.h" +#include "forward.h" DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct libmnt_table*, mnt_free_table, NULL); DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(struct libmnt_iter*, mnt_free_iter, NULL); @@ -32,12 +30,7 @@ static inline int libmount_parse_with_utab( return libmount_parse_full(NULL, NULL, ret_table, ret_iter); } -static inline int libmount_parse_fstab( - struct libmnt_table **ret_table, - struct libmnt_iter **ret_iter) { - - return libmount_parse_full(fstab_path(), NULL, ret_table, ret_iter); -} +int libmount_parse_fstab(struct libmnt_table **ret_table, struct libmnt_iter **ret_iter); int libmount_is_leaf( struct libmnt_table *table, diff --git a/src/shared/local-addresses.c b/src/shared/local-addresses.c index 85269d4d709..35b99c2aa03 100644 --- a/src/shared/local-addresses.c +++ b/src/shared/local-addresses.c @@ -1,15 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "sd-netlink.h" #include "alloc-util.h" #include "fd-util.h" #include "local-addresses.h" #include "log.h" -#include "macro.h" #include "netlink-util.h" +#include "socket-util.h" #include "sort-util.h" static int address_compare(const struct local_address *a, const struct local_address *b) { diff --git a/src/shared/local-addresses.h b/src/shared/local-addresses.h index 9e8374fa6f3..ed8aa055ce6 100644 --- a/src/shared/local-addresses.h +++ b/src/shared/local-addresses.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-netlink.h" - +#include "forward.h" #include "in-addr-util.h" struct local_address { diff --git a/src/shared/locale-setup.c b/src/shared/locale-setup.c index 3f23741bd77..4a2f21e4e18 100644 --- a/src/shared/locale-setup.c +++ b/src/shared/locale-setup.c @@ -1,7 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include +#include #include "alloc-util.h" #include "env-file.h" @@ -10,8 +11,10 @@ #include "errno-util.h" #include "fd-util.h" #include "locale-setup.h" +#include "log.h" #include "proc-cmdline.h" #include "stat-util.h" +#include "string-util.h" #include "strv.h" void locale_context_clear(LocaleContext *c) { diff --git a/src/shared/locale-setup.h b/src/shared/locale-setup.h index 537acc72df8..ae32219aa4b 100644 --- a/src/shared/locale-setup.h +++ b/src/shared/locale-setup.h @@ -3,6 +3,7 @@ #include +#include "forward.h" #include "locale-util.h" typedef struct LocaleContext { diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 270fe2bc345..cf2fba29854 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -1,10 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include -#include -#include #include #include @@ -14,22 +10,21 @@ #include "sd-messages.h" #include "alloc-util.h" -#include "fd-util.h" #include "format-util.h" #include "glyph-util.h" #include "hashmap.h" -#include "hostname-util.h" #include "id128-util.h" -#include "io-util.h" #include "journal-internal.h" #include "journal-util.h" #include "locale-util.h" #include "log.h" #include "logs-show.h" -#include "macro.h" #include "output-mode.h" #include "parse-util.h" #include "pretty-print.h" +#include "rlimit-util.h" +#include "set.h" +#include "sigbus.h" #include "sparse-endian.h" #include "stdio-util.h" #include "string-table.h" @@ -434,7 +429,7 @@ static int output_timestamp_realtime( if (IN_SET(mode, OUTPUT_SHORT_ISO, OUTPUT_SHORT_ISO_PRECISE)) { int h = tm.tm_gmtoff / 60 / 60, - m = abs((int) ((tm.tm_gmtoff / 60) % 60)); + m = ABS((int) ((tm.tm_gmtoff / 60) % 60)); assert_se(snprintf_ok(buf + tail, sizeof(buf) - tail, "%+03d:%02d", h, m)); } @@ -2316,3 +2311,11 @@ int journal_get_log_ids( *ret_n_ids = n_ids; return n_ids > 0; } + +void journal_browse_prepare(void) { + /* Increase max number of open files if we can, we might needs this when browsing journal files, + * which might be split up into many files. */ + (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); + + sigbus_install(); +} diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index 4156c9c2830..7d1fe67f889 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -1,20 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include - #include "sd-id128.h" -#include "sd-journal.h" -#include "macro.h" -#include "output-mode.h" -#include "rlimit-util.h" -#include "set.h" -#include "sigbus.h" -#include "time-util.h" +#include "forward.h" typedef struct LogId { sd_id128_t id; /* boot ID or invocation ID */ @@ -135,10 +124,4 @@ static inline int journal_get_boots( ret_ids, ret_n_ids); } -static inline void journal_browse_prepare(void) { - /* Increase max number of open files if we can, we might needs this when browsing journal files, - * which might be split up into many files. */ - (void) rlimit_nofile_bump(HIGH_RLIMIT_NOFILE); - - sigbus_install(); -} +void journal_browse_prepare(void); diff --git a/src/shared/loop-util.c b/src/shared/loop-util.c index 71bc6e725cf..78180631a53 100644 --- a/src/shared/loop-util.c +++ b/src/shared/loop-util.c @@ -4,9 +4,7 @@ #include #endif -#include #include -#include #include #include #include @@ -26,13 +24,13 @@ #include "fileio.h" #include "fs-util.h" #include "loop-util.h" -#include "missing_fs.h" #include "parse-util.h" #include "path-util.h" #include "random-util.h" #include "stat-util.h" #include "stdio-util.h" #include "string-util.h" +#include "time-util.h" static void cleanup_clear_loop_close(int *fd) { if (*fd < 0) diff --git a/src/shared/loop-util.h b/src/shared/loop-util.h index 0f9b76e91e3..fe9b3f10534 100644 --- a/src/shared/loop-util.h +++ b/src/shared/loop-util.h @@ -1,18 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-device.h" - -#include "memory-util.h" -#include "time-util.h" - -typedef struct LoopDevice LoopDevice; +#include "forward.h" /* Some helpers for setting up loopback block devices */ -struct LoopDevice { +typedef struct LoopDevice { unsigned n_ref; int fd; int lock_fd; @@ -28,7 +21,7 @@ struct LoopDevice { uint64_t diskseq; /* Block device sequence number, monothonically incremented by the kernel on create/attach, or 0 if we don't know */ uint32_t sector_size; uint64_t device_size; -}; +} LoopDevice; /* Returns true if LoopDevice object is not actually a loopback device but some other block device we just wrap */ #define LOOP_DEVICE_IS_FOREIGN(d) ((d)->nr < 0) diff --git a/src/shared/loopback-setup.c b/src/shared/loopback-setup.c index f1eb0fb1138..a2fd14d5070 100644 --- a/src/shared/loopback-setup.c +++ b/src/shared/loopback-setup.c @@ -1,14 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include "sd-netlink.h" +#include "errno-util.h" #include "log.h" #include "loopback-setup.h" #include "missing_network.h" -#include "netlink-util.h" #include "time-util.h" #define LOOPBACK_SETUP_TIMEOUT_USEC (5 * USEC_PER_SEC) diff --git a/src/shared/machine-credential.c b/src/shared/machine-credential.c index 6f02babe144..ae7db4b01cd 100644 --- a/src/shared/machine-credential.c +++ b/src/shared/machine-credential.c @@ -7,7 +7,6 @@ #include "fileio.h" #include "log.h" #include "machine-credential.h" -#include "macro.h" #include "memory-util.h" #include "path-util.h" #include "string-util-fundamental.h" diff --git a/src/shared/machine-credential.h b/src/shared/machine-credential.h index f2235864501..9734e528781 100644 --- a/src/shared/machine-credential.h +++ b/src/shared/machine-credential.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "forward.h" typedef struct MachineCredential { char *id; diff --git a/src/shared/machine-id-setup.c b/src/shared/machine-id-setup.c index 979799f8252..b6c67510892 100644 --- a/src/shared/machine-id-setup.c +++ b/src/shared/machine-id-setup.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include @@ -12,13 +11,12 @@ #include "chase.h" #include "creds-util.h" #include "fd-util.h" +#include "fs-util.h" #include "id128-util.h" #include "initrd-util.h" #include "io-util.h" #include "log.h" #include "machine-id-setup.h" -#include "macro.h" -#include "mkdir.h" #include "mount-util.h" #include "mountpoint-util.h" #include "namespace-util.h" @@ -26,6 +24,7 @@ #include "process-util.h" #include "stat-util.h" #include "string-util.h" +#include "strv.h" #include "sync-util.h" #include "umask-util.h" #include "virt.h" diff --git a/src/shared/machine-id-setup.h b/src/shared/machine-id-setup.h index 595b1d15702..a5100766a44 100644 --- a/src/shared/machine-id-setup.h +++ b/src/shared/machine-id-setup.h @@ -1,10 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - #include "sd-id128.h" +#include "forward.h" + typedef enum MachineIdSetupFlags { MACHINE_ID_SETUP_FORCE_TRANSIENT = 1 << 0, MACHINE_ID_SETUP_FORCE_FIRMWARE = 1 << 1, diff --git a/src/shared/machine-pool.c b/src/shared/machine-pool.c index 8fa17540eb5..8744ec3d5da 100644 --- a/src/shared/machine-pool.c +++ b/src/shared/machine-pool.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include "sd-bus.h" #include "btrfs-util.h" #include "label-util.h" diff --git a/src/shared/machine-pool.h b/src/shared/machine-pool.h index dfc553f8b6b..0719ba011fe 100644 --- a/src/shared/machine-pool.h +++ b/src/shared/machine-pool.h @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "sd-bus.h" +#include "forward.h" int setup_machine_directory(sd_bus_error *error, bool use_btrfs_subvol, bool use_btrfs_quota); diff --git a/src/shared/macvlan-util.c b/src/shared/macvlan-util.c index 11dffe99b2a..2fb3d0c5bf7 100644 --- a/src/shared/macvlan-util.c +++ b/src/shared/macvlan-util.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "conf-parser.h" #include "macvlan-util.h" #include "string-table.h" diff --git a/src/shared/macvlan-util.h b/src/shared/macvlan-util.h index c8d7c77cc43..f2e5e458c36 100644 --- a/src/shared/macvlan-util.h +++ b/src/shared/macvlan-util.h @@ -1,10 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include #include -#include "macro.h" +#include "forward.h" typedef enum MacVlanMode { NETDEV_MACVLAN_MODE_PRIVATE = MACVLAN_MODE_PRIVATE, diff --git a/src/shared/main-func.c b/src/shared/main-func.c index c8612183634..d16b6f1b9d8 100644 --- a/src/shared/main-func.c +++ b/src/shared/main-func.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #if HAVE_VALGRIND_VALGRIND_H # include #endif @@ -14,6 +15,7 @@ #include "polkit-agent.h" #include "selinux-util.h" #include "signal-util.h" +#include "string-util.h" void main_prepare(int argc, char *argv[]) { assert_se(argc > 0 && !isempty(argv[0])); @@ -48,3 +50,11 @@ int raise_or_exit_status(int ret) { /* exit with failure if raise() does not immediately abort the program. */ return EXIT_FAILURE; } + +int exit_failure_if_negative(int result) { + return result < 0 ? EXIT_FAILURE : EXIT_SUCCESS; +} + +int exit_failure_if_nonzero(int result) { + return result < 0 ? EXIT_FAILURE : result; +} diff --git a/src/shared/main-func.h b/src/shared/main-func.h index 0faaba60883..eca4c765a05 100644 --- a/src/shared/main-func.h +++ b/src/shared/main-func.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - +#include "forward.h" #include "static-destruct.h" void main_prepare(int argc, char *argv[]); @@ -20,18 +19,14 @@ void main_finalize(int r, int exit_status); return result_to_return_value(r); \ } -static inline int exit_failure_if_negative(int result) { - return result < 0 ? EXIT_FAILURE : EXIT_SUCCESS; -} +int exit_failure_if_negative(int result); /* Negative return values from impl are mapped to EXIT_FAILURE, and * everything else means success! */ #define DEFINE_MAIN_FUNCTION(impl) \ _DEFINE_MAIN_FUNCTION(,impl(argc, argv), exit_failure_if_negative, exit_failure_if_negative) -static inline int exit_failure_if_nonzero(int result) { - return result < 0 ? EXIT_FAILURE : result; -} +int exit_failure_if_nonzero(int result); /* Zero is mapped to EXIT_SUCCESS, negative values are mapped to EXIT_FAILURE, * and positive values are propagated. diff --git a/src/shared/meson.build b/src/shared/meson.build index 3039e5e29e4..79789e5b536 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -51,6 +51,8 @@ shared_sources = files( 'coredump-util.c', 'cpu-set-util.c', 'creds-util.c', + 'cryptsetup-fido2.c', + 'cryptsetup-tpm2.c', 'cryptsetup-util.c', 'daemon-util.c', 'data-fd-util.c', @@ -160,6 +162,7 @@ shared_sources = files( 'resize-fs.c', 'resolve-util.c', 'rm-rf.c', + 'seccomp-util.c', 'securebits-util.c', 'selinux-util.c', 'serialize.c', @@ -237,16 +240,12 @@ syscall_list_inc = custom_target( capture : true) generated_sources += syscall_list_inc +shared_sources += syscall_list_inc if conf.get('ENABLE_UTMP') == 1 shared_sources += files('utmp-wtmp.c') endif -if conf.get('HAVE_SECCOMP') == 1 - shared_sources += files('seccomp-util.c') - shared_sources += syscall_list_inc -endif - if conf.get('HAVE_LIBIPTC') == 1 shared_sources += files('firewall-util-iptables.c') endif @@ -259,14 +258,6 @@ if conf.get('HAVE_PAM') == 1 shared_sources += files('pam-util.c') endif -if conf.get('HAVE_LIBFIDO2') == 1 and conf.get('HAVE_LIBCRYPTSETUP') == 1 - shared_sources += files('cryptsetup-fido2.c') -endif - -if conf.get('HAVE_TPM2') == 1 and conf.get('HAVE_LIBCRYPTSETUP') == 1 - shared_sources += files('cryptsetup-tpm2.c') -endif - generate_ip_protocol_list = find_program('generate-ip-protocol-list.sh') ip_protocol_list_txt = custom_target( 'ip-protocol-list.txt', diff --git a/src/shared/mkdir-label.c b/src/shared/mkdir-label.c index e3afc2b666c..71ecdffaa28 100644 --- a/src/shared/mkdir-label.c +++ b/src/shared/mkdir-label.c @@ -3,10 +3,10 @@ #include #include "errno-util.h" +#include "label-util.h" #include "mkdir-label.h" #include "selinux-util.h" #include "smack-util.h" -#include "user-util.h" int mkdirat_label(int dirfd, const char *path, mode_t mode) { int r; diff --git a/src/shared/mkdir-label.h b/src/shared/mkdir-label.h index a9a8ce3a59e..ef5722d035f 100644 --- a/src/shared/mkdir-label.h +++ b/src/shared/mkdir-label.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - +#include "forward.h" #include "mkdir.h" int mkdirat_label(int dirfd, const char *path, mode_t mode); diff --git a/src/shared/mkfs-util.c b/src/shared/mkfs-util.c index c7385dac9af..d0ecb391d60 100644 --- a/src/shared/mkfs-util.c +++ b/src/shared/mkfs-util.c @@ -1,13 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include -#include "dirent-util.h" #include "fd-util.h" #include "fileio.h" +#include "format-util.h" #include "fs-util.h" -#include "id128-util.h" #include "log.h" #include "mkfs-util.h" #include "mount-util.h" @@ -19,6 +19,7 @@ #include "stat-util.h" #include "stdio-util.h" #include "string-util.h" +#include "strv.h" #include "tmpfile-util.h" #include "utf8.h" diff --git a/src/shared/mkfs-util.h b/src/shared/mkfs-util.h index 165862e7e1d..e20d9dc63e1 100644 --- a/src/shared/mkfs-util.h +++ b/src/shared/mkfs-util.h @@ -1,11 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - #include "sd-id128.h" -#include "strv.h" +#include "forward.h" int mkfs_exists(const char *fstype); diff --git a/src/shared/module-util.c b/src/shared/module-util.c index 56e93e87323..dcdc122ffbb 100644 --- a/src/shared/module-util.c +++ b/src/shared/module-util.c @@ -1,7 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include +#include "log.h" #include "module-util.h" #include "proc-cmdline.h" #include "strv.h" diff --git a/src/shared/module-util.h b/src/shared/module-util.h index 8fd6a7f8e6b..e98e0049b6e 100644 --- a/src/shared/module-util.h +++ b/src/shared/module-util.h @@ -1,14 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "dlfcn-util.h" +#include "forward.h" #if HAVE_KMOD -#include +#include /* IWYU pragma: export */ -#include "macro.h" -#include "memory-util.h" +#include "dlfcn-util.h" extern DLSYM_PROTOTYPE(kmod_list_next); extern DLSYM_PROTOTYPE(kmod_load_resources); diff --git a/src/shared/mount-setup.c b/src/shared/mount-setup.c index 02f77cbf1c0..564ab038ec1 100644 --- a/src/shared/mount-setup.c +++ b/src/shared/mount-setup.c @@ -1,36 +1,27 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include -#include #include #include "alloc-util.h" -#include "bus-util.h" -#include "cgroup-setup.h" -#include "cgroup-util.h" #include "conf-files.h" #include "dev-setup.h" -#include "dirent-util.h" -#include "efi-loader.h" +#include "efivars.h" +#include "errno-util.h" #include "fd-util.h" #include "fileio.h" -#include "fs-util.h" #include "label-util.h" #include "log.h" -#include "macro.h" #include "mkdir-label.h" #include "mount-setup.h" #include "mount-util.h" #include "mountpoint-util.h" -#include "nulstr-util.h" #include "path-util.h" #include "recurse-dir.h" -#include "set.h" #include "smack-util.h" +#include "string-util.h" #include "strv.h" -#include "user-util.h" +#include "time-util.h" #include "virt.h" typedef enum MountMode { diff --git a/src/shared/mount-setup.h b/src/shared/mount-setup.h index 58a1b7619c8..5d505c17dc9 100644 --- a/src/shared/mount-setup.h +++ b/src/shared/mount-setup.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" bool mount_point_is_api(const char *path); bool mount_point_ignore(const char *path); diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 10868be08eb..9a1cc31fac6 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -1,26 +1,22 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include #include -#include #include #include "alloc-util.h" #include "chase.h" #include "dissect-image.h" -#include "exec-util.h" +#include "errno-util.h" #include "extract-word.h" #include "fd-util.h" #include "fileio.h" +#include "format-util.h" #include "fs-util.h" #include "fstab-util.h" #include "glyph-util.h" #include "hashmap.h" -#include "initrd-util.h" -#include "label-util.h" #include "libmount-util.h" #include "log.h" #include "missing_syscall.h" @@ -28,14 +24,13 @@ #include "mount-util.h" #include "mountpoint-util.h" #include "namespace-util.h" -#include "parse-util.h" +#include "os-util.h" #include "path-util.h" +#include "pidref.h" #include "process-util.h" #include "set.h" #include "sort-util.h" #include "stat-util.h" -#include "stdio-util.h" -#include "string-table.h" #include "string-util.h" #include "strv.h" #include "tmpfile-util.h" @@ -1873,6 +1868,25 @@ int make_fsmount( return TAKE_FD(mnt_fd); } +char* umount_and_rmdir_and_free(char *p) { + if (!p) + return NULL; + + PROTECT_ERRNO; + (void) umount_recursive(p, 0); + (void) rmdir(p); + return mfree(p); +} + +char* umount_and_free(char *p) { + if (!p) + return NULL; + + PROTECT_ERRNO; + (void) umount_recursive(p, 0); + return mfree(p); +} + char* umount_and_unlink_and_free(char *p) { if (!p) return NULL; diff --git a/src/shared/mount-util.h b/src/shared/mount-util.h index 005ea93ec9f..92ce4c5816c 100644 --- a/src/shared/mount-util.h +++ b/src/shared/mount-util.h @@ -2,15 +2,8 @@ #pragma once #include -#include -#include -#include -#include "alloc-util.h" -#include "dissect-image.h" -#include "errno-util.h" -#include "macro.h" -#include "pidref.h" +#include "forward.h" typedef struct SubMount { char *path; @@ -94,25 +87,10 @@ int mode_to_inaccessible_node(const char *runtime_dir, mode_t mode, char **dest) int mount_flags_to_string(unsigned long flags, char **ret); /* Useful for usage with _cleanup_(), unmounts, removes a directory and frees the pointer */ -static inline char* umount_and_rmdir_and_free(char *p) { - if (!p) - return NULL; - - PROTECT_ERRNO; - (void) umount_recursive(p, 0); - (void) rmdir(p); - return mfree(p); -} +char* umount_and_rmdir_and_free(char *p); DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_rmdir_and_free); -static inline char* umount_and_free(char *p) { - if (!p) - return NULL; - - PROTECT_ERRNO; - (void) umount_recursive(p, 0); - return mfree(p); -} +char* umount_and_free(char *p); DEFINE_TRIVIAL_CLEANUP_FUNC(char*, umount_and_free); char* umount_and_unlink_and_free(char *p); diff --git a/src/shared/net-condition.c b/src/shared/net-condition.c index 67a088f7c8d..52b9374ff09 100644 --- a/src/shared/net-condition.c +++ b/src/shared/net-condition.c @@ -1,17 +1,19 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include + +#include "sd-device.h" #include "alloc-util.h" #include "condition.h" #include "env-util.h" +#include "extract-word.h" #include "log.h" #include "net-condition.h" #include "netif-util.h" -#include "network-util.h" +#include "set.h" #include "socket-util.h" -#include "string-table.h" +#include "string-util.h" #include "strv.h" #include "wifi-util.h" diff --git a/src/shared/net-condition.h b/src/shared/net-condition.h index 0884d43f460..ff3f2a36b5a 100644 --- a/src/shared/net-condition.h +++ b/src/shared/net-condition.h @@ -2,13 +2,9 @@ #pragma once #include -#include -#include "sd-device.h" - -#include "conf-parser.h" -#include "ether-addr-util.h" -#include "set.h" +#include "conf-parser-forward.h" +#include "forward.h" typedef struct NetMatch { Set *hw_addr; diff --git a/src/shared/netif-naming-scheme.c b/src/shared/netif-naming-scheme.c index c51e5a01ddd..afa5b9d842f 100644 --- a/src/shared/netif-naming-scheme.c +++ b/src/shared/netif-naming-scheme.c @@ -1,9 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "sd-device.h" #include "alloc-util.h" #include "device-private.h" +#include "log.h" #include "netif-naming-scheme.h" #include "proc-cmdline.h" #include "string-table.h" diff --git a/src/shared/netif-naming-scheme.h b/src/shared/netif-naming-scheme.h index 5ead1f85d78..18696726c3d 100644 --- a/src/shared/netif-naming-scheme.h +++ b/src/shared/netif-naming-scheme.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-device.h" - -#include "macro.h" +#include "forward.h" /* So here's the deal: net_id is supposed to be an exercise in providing stable names for network devices. However, we * also want to keep updating the naming scheme used in future versions of net_id. These two goals of course are diff --git a/src/shared/netif-sriov.c b/src/shared/netif-sriov.c index a4ec8666d02..f621a9dde7e 100644 --- a/src/shared/netif-sriov.c +++ b/src/shared/netif-sriov.c @@ -1,11 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-device.h" +#include "sd-netlink.h" + #include "alloc-util.h" +#include "conf-parser.h" #include "device-util.h" +#include "ether-addr-util.h" #include "netif-sriov.h" -#include "netlink-util.h" #include "parse-util.h" #include "set.h" +#include "siphash24.h" #include "stdio-util.h" #include "string-table.h" #include "string-util.h" diff --git a/src/shared/netif-sriov.h b/src/shared/netif-sriov.h index 49e05fa2858..7fc7393bd30 100644 --- a/src/shared/netif-sriov.h +++ b/src/shared/netif-sriov.h @@ -2,13 +2,10 @@ #pragma once #include +#include -#include "sd-device.h" -#include "sd-netlink.h" - -#include "conf-parser.h" -#include "ether-addr-util.h" -#include "hashmap.h" +#include "conf-parser-forward.h" +#include "forward.h" typedef enum SRIOVAttribute { SR_IOV_VF_MAC, diff --git a/src/shared/netif-util.c b/src/shared/netif-util.c index 47cf4df98de..74daf1facc8 100644 --- a/src/shared/netif-util.c +++ b/src/shared/netif-util.c @@ -3,9 +3,13 @@ #include #include +#include "sd-device.h" +#include "sd-id128.h" + #include "alloc-util.h" #include "arphrd-util.h" #include "device-util.h" +#include "ether-addr-util.h" #include "hexdecoct.h" #include "log-link.h" #include "memory-util.h" @@ -13,6 +17,7 @@ #include "netif-util.h" #include "siphash24.h" #include "sparse-endian.h" +#include "string-util.h" #include "strv.h" #define SHORTEN_IFNAME_HASH_KEY SD_ID128_MAKE(e1,90,a4,04,a8,ef,4b,51,8c,cc,c3,3a,9f,11,fc,a2) diff --git a/src/shared/netif-util.h b/src/shared/netif-util.h index 1fe0de9c30f..5b2ba1d11d8 100644 --- a/src/shared/netif-util.h +++ b/src/shared/netif-util.h @@ -1,13 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "sd-device.h" -#include "sd-id128.h" - -#include "ether-addr-util.h" +#include "forward.h" bool netif_has_carrier(uint8_t operstate, unsigned flags); int net_get_type_string(sd_device *device, uint16_t iftype, char **ret); diff --git a/src/shared/notify-recv.c b/src/shared/notify-recv.c index 0169a6220c8..1bc320af41b 100644 --- a/src/shared/notify-recv.c +++ b/src/shared/notify-recv.c @@ -1,13 +1,19 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-event.h" + +#include "alloc-util.h" #include "async.h" +#include "constants.h" +#include "errno-util.h" #include "fd-util.h" +#include "fdset.h" #include "log.h" #include "notify-recv.h" +#include "pidref.h" #include "process-util.h" #include "socket-util.h" #include "strv.h" -#include "user-util.h" int notify_socket_prepare( sd_event *event, diff --git a/src/shared/notify-recv.h b/src/shared/notify-recv.h index 9035ad4872c..4306439b6f7 100644 --- a/src/shared/notify-recv.h +++ b/src/shared/notify-recv.h @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-event.h" - -#include "fdset.h" -#include "pidref.h" +#include "forward.h" int notify_socket_prepare( sd_event *event, diff --git a/src/shared/nsflags.c b/src/shared/nsflags.c index 17ffb979fe7..e14aa098102 100644 --- a/src/shared/nsflags.c +++ b/src/shared/nsflags.c @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" #include "extract-word.h" -#include "log.h" #include "namespace-util.h" #include "nsflags.h" #include "string-util.h" diff --git a/src/shared/nsflags.h b/src/shared/nsflags.h index 7c6214a3bb4..9839d47dc77 100644 --- a/src/shared/nsflags.h +++ b/src/shared/nsflags.h @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "forward.h" #include "missing_sched.h" /* The combination of all namespace flags defined by the kernel. The right type for this isn't clear. setns() and diff --git a/src/shared/nsresource.c b/src/shared/nsresource.c index e76f5ab47e5..e74e5fcc700 100644 --- a/src/shared/nsresource.c +++ b/src/shared/nsresource.c @@ -4,6 +4,7 @@ #include "sd-varlink.h" +#include "alloc-util.h" #include "fd-util.h" #include "format-util.h" #include "json-util.h" @@ -12,6 +13,7 @@ #include "namespace-util.h" #include "nsresource.h" #include "process-util.h" +#include "string-util.h" static int make_pid_name(char **ret) { char comm[TASK_COMM_LEN]; diff --git a/src/shared/nsresource.h b/src/shared/nsresource.h index 48274fd1a53..55937fd4830 100644 --- a/src/shared/nsresource.h +++ b/src/shared/nsresource.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int nsresource_allocate_userns(const char *name, uint64_t size); int nsresource_register_userns(const char *name, int userns_fd); diff --git a/src/shared/numa-util.c b/src/shared/numa-util.c index 8cc315061de..88f02bc5595 100644 --- a/src/shared/numa-util.c +++ b/src/shared/numa-util.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include "alloc-util.h" @@ -9,7 +8,6 @@ #include "fd-util.h" #include "fileio.h" #include "log.h" -#include "macro.h" #include "missing_syscall.h" #include "numa-util.h" #include "parse-util.h" diff --git a/src/shared/numa-util.h b/src/shared/numa-util.h index 2f736c9c350..065df9b9a40 100644 --- a/src/shared/numa-util.h +++ b/src/shared/numa-util.h @@ -2,6 +2,7 @@ #pragma once #include "cpu-set-util.h" +#include "forward.h" #include "missing_syscall.h" static inline bool mpol_is_valid(int t) { diff --git a/src/shared/open-file.c b/src/shared/open-file.c index a06a78a4a7b..7dfce2d9771 100644 --- a/src/shared/open-file.c +++ b/src/shared/open-file.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" #include "escape.h" #include "extract-word.h" diff --git a/src/shared/open-file.h b/src/shared/open-file.h index d6cab523591..7c1621e6298 100644 --- a/src/shared/open-file.h +++ b/src/shared/open-file.h @@ -1,11 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - +#include "forward.h" #include "list.h" -#include "macro.h" -#include "memory-util.h" typedef enum OpenFileFlag { OPENFILE_READ_ONLY = 1 << 0, diff --git a/src/shared/openssl-util.c b/src/shared/openssl-util.c index 4bbe708757b..656278b52b2 100644 --- a/src/shared/openssl-util.c +++ b/src/shared/openssl-util.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" #include "ask-password-api.h" #include "fd-util.h" diff --git a/src/shared/openssl-util.h b/src/shared/openssl-util.h index a32e19d37d7..8b051435e65 100644 --- a/src/shared/openssl-util.h +++ b/src/shared/openssl-util.h @@ -2,8 +2,8 @@ #pragma once #include "ask-password-api.h" +#include "forward.h" #include "iovec-util.h" -#include "memory-util.h" #include "sha256.h" typedef enum CertificateSourceType { @@ -30,26 +30,26 @@ int parse_openssl_key_source_argument(const char *argument, char **private_key_s #define X509_FINGERPRINT_SIZE SHA256_DIGEST_SIZE #if HAVE_OPENSSL -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ # ifndef OPENSSL_VERSION_MAJOR /* OPENSSL_VERSION_MAJOR macro was added in OpenSSL 3. Thus, if it doesn't exist, we must be before OpenSSL 3. */ # define OPENSSL_VERSION_MAJOR 1 # endif # if OPENSSL_VERSION_MAJOR >= 3 -# include -# include -# include -# include -# include +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ # endif DEFINE_TRIVIAL_CLEANUP_FUNC_FULL_MACRO(void*, OPENSSL_free, NULL); diff --git a/src/shared/osc-context.c b/src/shared/osc-context.c index 9d5e875fc3d..00cdd609e49 100644 --- a/src/shared/osc-context.c +++ b/src/shared/osc-context.c @@ -3,6 +3,7 @@ #include #include "escape.h" +#include "format-util.h" #include "hostname-setup.h" #include "id128-util.h" #include "osc-context.h" diff --git a/src/shared/osc-context.h b/src/shared/osc-context.h index 6c9882c8944..8f80b2932b5 100644 --- a/src/shared/osc-context.h +++ b/src/shared/osc-context.h @@ -3,8 +3,7 @@ #include "sd-id128.h" -#include "assert-util.h" -#include "macro.h" +#include "forward.h" int osc_context_open_boot(char **ret_seq); int osc_context_open_container(const char *name, char **ret_seq, sd_id128_t *ret_context_id); diff --git a/src/shared/output-mode.c b/src/shared/output-mode.c index c8c6a27a59b..2aa588d34eb 100644 --- a/src/shared/output-mode.c +++ b/src/shared/output-mode.c @@ -1,5 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-json.h" + #include "output-mode.h" #include "string-table.h" diff --git a/src/shared/output-mode.h b/src/shared/output-mode.h index 36dc85c175a..ffd2e4fe809 100644 --- a/src/shared/output-mode.h +++ b/src/shared/output-mode.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-json.h" - -#include "macro.h" +#include "forward.h" typedef enum OutputMode { OUTPUT_SHORT, diff --git a/src/shared/pager.c b/src/shared/pager.c index f1043ec1326..3797adbb7cc 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include -#include #include #include -#include #include #include "sd-login.h" @@ -17,10 +13,8 @@ #include "io-util.h" #include "locale-util.h" #include "log.h" -#include "macro.h" #include "pager.h" #include "process-util.h" -#include "rlimit-util.h" #include "signal-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/pager.h b/src/shared/pager.h index 9a9d4c53c38..bbd92a2bbaa 100644 --- a/src/shared/pager.h +++ b/src/shared/pager.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "macro.h" +#include "forward.h" typedef enum PagerFlags { PAGER_DISABLE = 1 << 0, diff --git a/src/shared/pam-util.c b/src/shared/pam-util.c index 8cb4b9b1eb1..a2f2126cbc6 100644 --- a/src/shared/pam-util.c +++ b/src/shared/pam-util.c @@ -1,16 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-internal.h" #include "errno-util.h" #include "fd-util.h" #include "format-util.h" #include "log.h" -#include "macro.h" #include "pam-util.h" #include "process-util.h" #include "stdio-util.h" diff --git a/src/shared/pam-util.h b/src/shared/pam-util.h index 699648d43bd..f48a170c483 100644 --- a/src/shared/pam-util.h +++ b/src/shared/pam-util.h @@ -1,12 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include /* IWYU pragma: export */ #include -#include "sd-bus.h" - -#include "macro.h" +#include "forward.h" void pam_log_setup(void); diff --git a/src/shared/parse-argument.c b/src/shared/parse-argument.c index 701802ec0ca..1575962d44a 100644 --- a/src/shared/parse-argument.c +++ b/src/shared/parse-argument.c @@ -7,7 +7,6 @@ #include "parse-util.h" #include "path-util.h" #include "signal-util.h" -#include "stdio-util.h" #include "string-table.h" #include "string-util.h" diff --git a/src/shared/parse-argument.h b/src/shared/parse-argument.h index bd577033b8f..06c47d90442 100644 --- a/src/shared/parse-argument.h +++ b/src/shared/parse-argument.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-json.h" +#include "forward.h" int parse_boolean_argument(const char *optname, const char *s, bool *ret); int parse_tristate_argument(const char *optname, const char *s, int *ret); diff --git a/src/shared/parse-helpers.h b/src/shared/parse-helpers.h index 29ab60fe9f0..c686b9cebbf 100644 --- a/src/shared/parse-helpers.h +++ b/src/shared/parse-helpers.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" typedef enum PathSimplifyWarnFlags { PATH_CHECK_FATAL = 1 << 0, /* If not set, then error message is appended with 'ignoring'. */ diff --git a/src/shared/password-quality-util-passwdqc.c b/src/shared/password-quality-util-passwdqc.c index 21ffb2c5191..004203d17e3 100644 --- a/src/shared/password-quality-util-passwdqc.c +++ b/src/shared/password-quality-util-passwdqc.c @@ -3,7 +3,6 @@ #include "dlfcn-util.h" #include "errno-util.h" #include "log.h" -#include "macro.h" #include "memory-util.h" #include "password-quality-util.h" #include "strv.h" diff --git a/src/shared/password-quality-util-passwdqc.h b/src/shared/password-quality-util-passwdqc.h index 90a6b3fe895..121b75c5019 100644 --- a/src/shared/password-quality-util-passwdqc.h +++ b/src/shared/password-quality-util-passwdqc.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "macro.h" +#include "forward.h" #if HAVE_PASSWDQC #include diff --git a/src/shared/password-quality-util-pwquality.c b/src/shared/password-quality-util-pwquality.c index f4aabd3510b..ac46ac8430e 100644 --- a/src/shared/password-quality-util-pwquality.c +++ b/src/shared/password-quality-util-pwquality.c @@ -1,13 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include #include #include "alloc-util.h" #include "dlfcn-util.h" #include "errno-util.h" #include "log.h" -#include "macro.h" -#include "memory-util.h" #include "password-quality-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/password-quality-util-pwquality.h b/src/shared/password-quality-util-pwquality.h index 68aa8db4824..dbea6d24cad 100644 --- a/src/shared/password-quality-util-pwquality.h +++ b/src/shared/password-quality-util-pwquality.h @@ -1,15 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "macro.h" +#include "forward.h" #if HAVE_PWQUALITY -/* pwquality.h uses size_t but doesn't include sys/types.h on its own */ #include -#include #include "dlfcn-util.h" -#include "memory-util.h" extern DLSYM_PROTOTYPE(pwquality_check); extern DLSYM_PROTOTYPE(pwquality_default_settings); diff --git a/src/shared/password-quality-util.h b/src/shared/password-quality-util.h index f838ba73efe..1f0c2686dc0 100644 --- a/src/shared/password-quality-util.h +++ b/src/shared/password-quality-util.h @@ -5,11 +5,11 @@ #if HAVE_PASSWDQC -#include "password-quality-util-passwdqc.h" +#include "password-quality-util-passwdqc.h" /* IWYU pragma: export */ #elif HAVE_PWQUALITY -#include "password-quality-util-pwquality.h" +#include "password-quality-util-pwquality.h" /* IWYU pragma: export */ #else diff --git a/src/shared/pcre2-util.c b/src/shared/pcre2-util.c index 1c7834b2906..7a80ddd9fae 100644 --- a/src/shared/pcre2-util.c +++ b/src/shared/pcre2-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "dlfcn-util.h" +#include "hash-funcs.h" #include "log.h" #include "pcre2-util.h" diff --git a/src/shared/pcre2-util.h b/src/shared/pcre2-util.h index e9ce0b21d8e..b1c9f24f142 100644 --- a/src/shared/pcre2-util.h +++ b/src/shared/pcre2-util.h @@ -1,15 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "hash-funcs.h" -#include "macro.h" +#include "forward.h" #if HAVE_PCRE2 #include "dlfcn-util.h" #define PCRE2_CODE_UNIT_WIDTH 8 -#include +#include /* IWYU pragma: export */ extern DLSYM_PROTOTYPE(pcre2_match_data_create); extern DLSYM_PROTOTYPE(pcre2_match_data_free); diff --git a/src/shared/pcrextend-util.c b/src/shared/pcrextend-util.c index dcd9b4ce914..0b8f17174ed 100644 --- a/src/shared/pcrextend-util.c +++ b/src/shared/pcrextend-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "sd-device.h" +#include "sd-id128.h" #include "alloc-util.h" #include "blkid-util.h" @@ -12,6 +13,7 @@ #include "log.h" #include "mountpoint-util.h" #include "pcrextend-util.h" +#include "string-util.h" #include "strv.h" static int device_get_file_system_word( diff --git a/src/shared/pe-binary.h b/src/shared/pe-binary.h index 14200189b23..2daaf7eea9f 100644 --- a/src/shared/pe-binary.h +++ b/src/shared/pe-binary.h @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "macro-fundamental.h" #include "openssl-util.h" #include "sparse-endian.h" #include "uki.h" diff --git a/src/shared/pkcs11-util.c b/src/shared/pkcs11-util.c index 1104e1e33a2..2c32f6bb20c 100644 --- a/src/shared/pkcs11-util.c +++ b/src/shared/pkcs11-util.c @@ -1,20 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" #include "ask-password-api.h" #include "dlfcn-util.h" #include "env-util.h" #include "escape.h" -#include "fd-util.h" #include "format-table.h" -#include "io-util.h" #include "log.h" #include "memory-util.h" -#if HAVE_OPENSSL #include "openssl-util.h" -#endif #include "pkcs11-util.h" #include "random-util.h" #include "string-util.h" @@ -62,33 +56,6 @@ DLSYM_PROTOTYPE(p11_kit_uri_message) = NULL; DLSYM_PROTOTYPE(p11_kit_uri_new) = NULL; DLSYM_PROTOTYPE(p11_kit_uri_parse) = NULL; -int dlopen_p11kit(void) { - ELF_NOTE_DLOPEN("p11-kit", - "Support for PKCS11 hardware tokens", - ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, - "libp11-kit.so.0"); - - return dlopen_many_sym_or_warn( - &p11kit_dl, - "libp11-kit.so.0", LOG_DEBUG, - DLSYM_ARG(p11_kit_module_get_name), - DLSYM_ARG(p11_kit_modules_finalize_and_release), - DLSYM_ARG(p11_kit_modules_load_and_initialize), - DLSYM_ARG(p11_kit_strerror), - DLSYM_ARG(p11_kit_uri_format), - DLSYM_ARG(p11_kit_uri_free), - DLSYM_ARG(p11_kit_uri_get_attributes), - DLSYM_ARG(p11_kit_uri_get_attribute), - DLSYM_ARG(p11_kit_uri_set_attribute), - DLSYM_ARG(p11_kit_uri_get_module_info), - DLSYM_ARG(p11_kit_uri_get_slot_info), - DLSYM_ARG(p11_kit_uri_get_token_info), - DLSYM_ARG(p11_kit_uri_match_token_info), - DLSYM_ARG(p11_kit_uri_message), - DLSYM_ARG(p11_kit_uri_new), - DLSYM_ARG(p11_kit_uri_parse)); -} - int uri_from_string(const char *p, P11KitUri **ret) { _cleanup_(sym_p11_kit_uri_freep) P11KitUri *uri = NULL; int r; @@ -1823,6 +1790,37 @@ static int list_callback( } #endif +int dlopen_p11kit(void) { +#if HAVE_P11KIT + ELF_NOTE_DLOPEN("p11-kit", + "Support for PKCS11 hardware tokens", + ELF_NOTE_DLOPEN_PRIORITY_SUGGESTED, + "libp11-kit.so.0"); + + return dlopen_many_sym_or_warn( + &p11kit_dl, + "libp11-kit.so.0", LOG_DEBUG, + DLSYM_ARG(p11_kit_module_get_name), + DLSYM_ARG(p11_kit_modules_finalize_and_release), + DLSYM_ARG(p11_kit_modules_load_and_initialize), + DLSYM_ARG(p11_kit_strerror), + DLSYM_ARG(p11_kit_uri_format), + DLSYM_ARG(p11_kit_uri_free), + DLSYM_ARG(p11_kit_uri_get_attributes), + DLSYM_ARG(p11_kit_uri_get_attribute), + DLSYM_ARG(p11_kit_uri_set_attribute), + DLSYM_ARG(p11_kit_uri_get_module_info), + DLSYM_ARG(p11_kit_uri_get_slot_info), + DLSYM_ARG(p11_kit_uri_get_token_info), + DLSYM_ARG(p11_kit_uri_match_token_info), + DLSYM_ARG(p11_kit_uri_message), + DLSYM_ARG(p11_kit_uri_new), + DLSYM_ARG(p11_kit_uri_parse)); +#else + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "p11kit support is not compiled in."); +#endif +} + int pkcs11_list_tokens(void) { #if HAVE_P11KIT _cleanup_(table_unrefp) Table *t = NULL; diff --git a/src/shared/pkcs11-util.h b/src/shared/pkcs11-util.h index c9ba1a507d1..43203ce6bb2 100644 --- a/src/shared/pkcs11-util.h +++ b/src/shared/pkcs11-util.h @@ -3,20 +3,16 @@ #if HAVE_OPENSSL # include -# include #endif -#include #if HAVE_P11KIT -# include -# include +# include /* IWYU pragma: export */ +# include /* IWYU pragma: export */ #endif #include "ask-password-api.h" #include "dlfcn-util.h" -#include "log.h" -#include "memory-util.h" -#include "time-util.h" +#include "forward.h" bool pkcs11_uri_valid(const char *uri); @@ -97,16 +93,10 @@ int pkcs11_crypt_device_callback( P11KitUri *uri, void *userdata); -int dlopen_p11kit(void); - -#else - -static inline int dlopen_p11kit(void) { - return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "p11kit support is not compiled in."); -} - #endif +int dlopen_p11kit(void); + typedef struct { const char *friendly_name; usec_t until; diff --git a/src/shared/plymouth-util.c b/src/shared/plymouth-util.c index 72f282f9bd7..aaf604afd54 100644 --- a/src/shared/plymouth-util.c +++ b/src/shared/plymouth-util.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "fd-util.h" #include "io-util.h" #include "log.h" diff --git a/src/shared/plymouth-util.h b/src/shared/plymouth-util.h index 9949e5dc83e..86c9ec6cb85 100644 --- a/src/shared/plymouth-util.h +++ b/src/shared/plymouth-util.h @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - #include "errno-util.h" +#include "forward.h" int plymouth_connect(int flags); int plymouth_send_raw(const void *raw, size_t size, int flags); diff --git a/src/shared/polkit-agent.c b/src/shared/polkit-agent.c index a652b465b9f..491b494b1e7 100644 --- a/src/shared/polkit-agent.c +++ b/src/shared/polkit-agent.c @@ -1,20 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include -#include #include +#include "bus-util.h" #include "exec-util.h" #include "fd-util.h" #include "io-util.h" #include "log.h" -#include "macro.h" #include "polkit-agent.h" #include "process-util.h" #include "stdio-util.h" -#include "time-util.h" #if ENABLE_POLKIT static pid_t agent_pid = 0; diff --git a/src/shared/polkit-agent.h b/src/shared/polkit-agent.h index 325dfdde466..3ed13f9ba5f 100644 --- a/src/shared/polkit-agent.h +++ b/src/shared/polkit-agent.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "bus-util.h" +#include "forward.h" int polkit_agent_open(void); void polkit_agent_close(void); diff --git a/src/shared/portable-util.c b/src/shared/portable-util.c index c472c2fea6e..8ec6e8880b1 100644 --- a/src/shared/portable-util.c +++ b/src/shared/portable-util.c @@ -2,7 +2,6 @@ #include "alloc-util.h" #include "fs-util.h" -#include "log.h" #include "nulstr-util.h" #include "portable-util.h" #include "string-util.h" diff --git a/src/shared/portable-util.h b/src/shared/portable-util.h index 2c89fe3eb8c..b19e470452c 100644 --- a/src/shared/portable-util.h +++ b/src/shared/portable-util.h @@ -2,7 +2,7 @@ #pragma once #include "constants.h" -#include "macro.h" +#include "forward.h" #define PORTABLE_PROFILE_DIRS CONF_PATHS_NULSTR("systemd/portable/profile") diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index cb13a244ab4..8be99a8d3f4 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include +#include #include "alloc-util.h" #include "color-util.h" @@ -13,7 +13,6 @@ #include "fd-util.h" #include "fileio.h" #include "log.h" -#include "pager.h" #include "path-util.h" #include "pretty-print.h" #include "string-util.h" diff --git a/src/shared/pretty-print.h b/src/shared/pretty-print.h index e64eed5a9f1..fc0ba5355f8 100644 --- a/src/shared/pretty-print.h +++ b/src/shared/pretty-print.h @@ -1,13 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include #include #include "ansi-color.h" -#include "assert-util.h" #include "fileio.h" +#include "forward.h" #include "glyph-util.h" -#include "terminal-util.h" #define CYLON_BUFFER_EXTRA (2*STRLEN(ANSI_RED) + STRLEN(ANSI_HIGHLIGHT_RED) + 2*STRLEN(ANSI_NORMAL)) diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index affa3ba37ca..53d3d31131a 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -1,16 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include #include -#include -#include -#include #include -#include #include -#include #include #include @@ -24,9 +17,9 @@ #include "fd-util.h" #include "io-util.h" #include "log.h" -#include "macro.h" #include "ptyfwd.h" #include "stat-util.h" +#include "string-util.h" #include "strv.h" #include "terminal-util.h" #include "time-util.h" diff --git a/src/shared/ptyfwd.h b/src/shared/ptyfwd.h index 1f1b771a399..e7b5210cc7a 100644 --- a/src/shared/ptyfwd.h +++ b/src/shared/ptyfwd.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-event.h" - -#include "memory-util.h" +#include "forward.h" typedef struct PTYForward PTYForward; diff --git a/src/shared/qrcode-util.c b/src/shared/qrcode-util.c index ff93a25a97e..5e61e84a9e2 100644 --- a/src/shared/qrcode-util.c +++ b/src/shared/qrcode-util.c @@ -4,6 +4,7 @@ #if HAVE_QRENCODE #include +#include #include "ansi-color.h" #include "dlfcn-util.h" diff --git a/src/shared/qrcode-util.h b/src/shared/qrcode-util.h index ff73b01ef81..7c9bb498931 100644 --- a/src/shared/qrcode-util.h +++ b/src/shared/qrcode-util.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include +#include "forward.h" #if HAVE_QRENCODE int dlopen_qrencode(void); diff --git a/src/shared/quota-util.c b/src/shared/quota-util.c index a698129adfe..a592b2fb001 100644 --- a/src/shared/quota-util.c +++ b/src/shared/quota-util.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include diff --git a/src/shared/quota-util.h b/src/shared/quota-util.h index ad97eede017..5e878a5d398 100644 --- a/src/shared/quota-util.h +++ b/src/shared/quota-util.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include +#include /* IWYU pragma: export */ + +#include "forward.h" /* Wrapper around the QCMD() macro of linux/quota.h that removes some undefined behaviour. A typical quota * command such as QCMD(Q_GETQUOTA, USRQUOTA) cannot be resolved on platforms where "int" is 32-bit, as it is diff --git a/src/shared/reboot-util.c b/src/shared/reboot-util.c index 20fbff7b5b0..f82c0654dc5 100644 --- a/src/shared/reboot-util.c +++ b/src/shared/reboot-util.c @@ -1,9 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include #include #include #include +#include #include #if HAVE_XENCTRL diff --git a/src/shared/reboot-util.h b/src/shared/reboot-util.h index 92189bee881..55419dfb149 100644 --- a/src/shared/reboot-util.h +++ b/src/shared/reboot-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" bool reboot_parameter_is_valid(const char *parameter); int update_reboot_parameter_and_warn(const char *parameter, bool keep); diff --git a/src/shared/recovery-key.c b/src/shared/recovery-key.c index 6c733700765..df8c7e8b23a 100644 --- a/src/shared/recovery-key.c +++ b/src/shared/recovery-key.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" -#include "memory-util.h" #include "random-util.h" #include "recovery-key.h" diff --git a/src/shared/recovery-key.h b/src/shared/recovery-key.h index 68e8051a936..ec7090a1c22 100644 --- a/src/shared/recovery-key.h +++ b/src/shared/recovery-key.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "forward.h" + /* 256 bit keys = 32 bytes */ #define RECOVERY_KEY_MODHEX_RAW_LENGTH 32 diff --git a/src/shared/resize-fs.c b/src/shared/resize-fs.c index 0f28869ea06..481c2de1e5d 100644 --- a/src/shared/resize-fs.c +++ b/src/shared/resize-fs.c @@ -5,14 +5,13 @@ #include #include -#include "blockdev-util.h" -#include "fs-util.h" -#include "log.h" #include "missing_fs.h" #include "missing_magic.h" #include "missing_xfs.h" #include "resize-fs.h" #include "stat-util.h" +#include "stdio-util.h" +#include "string-util-fundamental.h" int resize_fs(int fd, uint64_t sz, uint64_t *ret_size) { struct statfs sfs; diff --git a/src/shared/resize-fs.h b/src/shared/resize-fs.h index bacaec748d1..8cfda566963 100644 --- a/src/shared/resize-fs.h +++ b/src/shared/resize-fs.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - +#include "forward.h" #include "stat-util.h" int resize_fs(int fd, uint64_t sz, uint64_t *ret_size); diff --git a/src/shared/resolve-util.c b/src/shared/resolve-util.c index e01578fbcb0..26df7ba7dfb 100644 --- a/src/shared/resolve-util.c +++ b/src/shared/resolve-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "conf-parser.h" +#include "in-addr-util.h" #include "resolve-util.h" #include "string-table.h" diff --git a/src/shared/resolve-util.h b/src/shared/resolve-util.h index 2d210f9af75..a8f7fd41efd 100644 --- a/src/shared/resolve-util.h +++ b/src/shared/resolve-util.h @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "conf-parser.h" -#include "in-addr-util.h" -#include "macro.h" +#include "conf-parser-forward.h" +#include "forward.h" /* 127.0.0.53 in native endian (The IP address we listen on with the full DNS stub, i.e. that does LLMNR/mDNS, and stuff) */ #define INADDR_DNS_STUB ((in_addr_t) 0x7f000035U) @@ -14,30 +13,24 @@ /* 127.0.0.2 is an address we always map to the local hostname. This is different from 127.0.0.1 which maps to "localhost" */ #define INADDR_LOCALADDRESS ((in_addr_t) 0x7f000002U) -typedef enum DnsCacheMode DnsCacheMode; - -enum DnsCacheMode { +typedef enum DnsCacheMode { DNS_CACHE_MODE_NO, DNS_CACHE_MODE_YES, DNS_CACHE_MODE_NO_NEGATIVE, _DNS_CACHE_MODE_MAX, _DNS_CACHE_MODE_INVALID = -EINVAL, -}; - -typedef enum ResolveSupport ResolveSupport; -typedef enum DnssecMode DnssecMode; -typedef enum DnsOverTlsMode DnsOverTlsMode; +} DnsCacheMode; /* Do not change the order, see link_get_llmnr_support() or link_get_mdns_support(). */ -enum ResolveSupport { +typedef enum ResolveSupport { RESOLVE_SUPPORT_NO, RESOLVE_SUPPORT_RESOLVE, RESOLVE_SUPPORT_YES, _RESOLVE_SUPPORT_MAX, _RESOLVE_SUPPORT_INVALID = -EINVAL, -}; +} ResolveSupport; -enum DnssecMode { +typedef enum DnssecMode { /* No DNSSEC validation is done */ DNSSEC_NO, @@ -53,9 +46,9 @@ enum DnssecMode { _DNSSEC_MODE_MAX, _DNSSEC_MODE_INVALID = -EINVAL, -}; +} DnssecMode; -enum DnsOverTlsMode { +typedef enum DnsOverTlsMode { /* No connection is made for DNS-over-TLS */ DNS_OVER_TLS_NO, @@ -68,7 +61,7 @@ enum DnsOverTlsMode { _DNS_OVER_TLS_MODE_MAX, _DNS_OVER_TLS_MODE_INVALID = -EINVAL, -}; +} DnsOverTlsMode; CONFIG_PARSER_PROTOTYPE(config_parse_resolve_support); CONFIG_PARSER_PROTOTYPE(config_parse_dnssec_mode); diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c index 08c76a384ea..71466c8574e 100644 --- a/src/shared/rm-rf.c +++ b/src/shared/rm-rf.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include #include #include "alloc-util.h" @@ -13,7 +10,6 @@ #include "fd-util.h" #include "fs-util.h" #include "log.h" -#include "macro.h" #include "missing_magic.h" #include "mountpoint-util.h" #include "path-util.h" diff --git a/src/shared/rm-rf.h b/src/shared/rm-rf.h index a965df5f8e3..abad164e21c 100644 --- a/src/shared/rm-rf.h +++ b/src/shared/rm-rf.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "memory-util.h" +#include "forward.h" typedef enum RemoveFlags { REMOVE_ONLY_DIRECTORIES = 1 << 0, /* Only remove empty directories, no files */ diff --git a/src/shared/seccomp-util.c b/src/shared/seccomp-util.c index 07a59830545..571a91bbfa4 100644 --- a/src/shared/seccomp-util.c +++ b/src/shared/seccomp-util.c @@ -1,35 +1,30 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include -#include +#include #include #include #include #include -/* clang-format off */ -/* include missing_syscall_def.h earlier to make __SNR_foo mapped to __NR_foo. */ -#include "missing_syscall_def.h" -#include -/* clang-format on */ - #include "af-list.h" #include "alloc-util.h" #include "env-util.h" #include "errno-list.h" #include "log.h" -#include "macro.h" #include "namespace-util.h" #include "nsflags.h" #include "nulstr-util.h" +#include "parse-util.h" #include "process-util.h" #include "seccomp-util.h" #include "set.h" #include "string-util.h" #include "strv.h" +#if HAVE_SECCOMP + /* This array will be modified at runtime as seccomp_restrict_archs is called. */ uint32_t seccomp_local_archs[] = { @@ -2525,3 +2520,21 @@ int seccomp_suppress_sync(void) { return 0; } + +#endif + +bool seccomp_errno_or_action_is_valid(int n) { + return n == SECCOMP_ERROR_NUMBER_KILL || errno_is_valid(n); +} + +int seccomp_parse_errno_or_action(const char *p) { + if (streq_ptr(p, "kill")) + return SECCOMP_ERROR_NUMBER_KILL; + return parse_errno(p); +} + +const char* seccomp_errno_or_action_to_string(int num) { + if (num == SECCOMP_ERROR_NUMBER_KILL) + return "kill"; + return errno_to_name(num); +} diff --git a/src/shared/seccomp-util.h b/src/shared/seccomp-util.h index 64deb5fd5dd..bd8f1a18770 100644 --- a/src/shared/seccomp-util.h +++ b/src/shared/seccomp-util.h @@ -2,16 +2,11 @@ #pragma once #if HAVE_SECCOMP -#include +#include /* IWYU pragma: export */ #endif -#include -#include -#include "errno-list.h" #include "errno-util.h" -#include "parse-util.h" -#include "set.h" -#include "string-util.h" +#include "forward.h" #if HAVE_SECCOMP @@ -164,18 +159,8 @@ enum { SECCOMP_ERROR_NUMBER_KILL = INT_MAX - 1, }; -static inline bool seccomp_errno_or_action_is_valid(int n) { - return n == SECCOMP_ERROR_NUMBER_KILL || errno_is_valid(n); -} +bool seccomp_errno_or_action_is_valid(int n); -static inline int seccomp_parse_errno_or_action(const char *p) { - if (streq_ptr(p, "kill")) - return SECCOMP_ERROR_NUMBER_KILL; - return parse_errno(p); -} +int seccomp_parse_errno_or_action(const char *p); -static inline const char* seccomp_errno_or_action_to_string(int num) { - if (num == SECCOMP_ERROR_NUMBER_KILL) - return "kill"; - return errno_to_name(num); -} +const char* seccomp_errno_or_action_to_string(int num); diff --git a/src/shared/securebits-util.c b/src/shared/securebits-util.c index c867807bec7..92c7415337e 100644 --- a/src/shared/securebits-util.c +++ b/src/shared/securebits-util.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include "alloc-util.h" diff --git a/src/shared/securebits-util.h b/src/shared/securebits-util.h index ee25c9330cb..19b836b4e7b 100644 --- a/src/shared/securebits-util.h +++ b/src/shared/securebits-util.h @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include #include -#include + +#include "forward.h" int secure_bits_to_string_alloc(int i, char **s); int secure_bits_from_string(const char *s); diff --git a/src/shared/selinux-util.c b/src/shared/selinux-util.c index c0c0e332e25..6a4f502fc21 100644 --- a/src/shared/selinux-util.c +++ b/src/shared/selinux-util.c @@ -1,12 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include #include +#include #include -#include -#include #include #include @@ -21,12 +18,11 @@ #include "errno-util.h" #include "fd-util.h" #include "label.h" +#include "label-util.h" #include "log.h" -#include "macro.h" #include "mallinfo-util.h" #include "path-util.h" #include "selinux-util.h" -#include "stdio-util.h" #include "string-util.h" #include "time-util.h" diff --git a/src/shared/selinux-util.h b/src/shared/selinux-util.h index 979c3f5be9a..9c5707f9fad 100644 --- a/src/shared/selinux-util.h +++ b/src/shared/selinux-util.h @@ -1,19 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include - -#include "assert-util.h" -#include "label-util.h" -#include "macro.h" +#include "forward.h" #if HAVE_SELINUX -#include - -#include "memory-util.h" +#include /* IWYU pragma: export */ DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(char*, freecon, NULL); #else diff --git a/src/shared/serialize.c b/src/shared/serialize.c index 2f5802ee668..4d0be059bd1 100644 --- a/src/shared/serialize.c +++ b/src/shared/serialize.c @@ -2,19 +2,29 @@ #include +#include "sd-id128.h" + #include "alloc-util.h" #include "env-util.h" #include "escape.h" +#include "extract-word.h" #include "fd-util.h" +#include "fdset.h" #include "fileio.h" +#include "format-util.h" #include "hexdecoct.h" +#include "image-policy.h" +#include "log.h" #include "memfd-util.h" #include "missing_mman.h" -#include "missing_syscall.h" #include "parse-util.h" -#include "process-util.h" +#include "pidref.h" +#include "ratelimit.h" #include "serialize.h" +#include "set.h" +#include "string-util.h" #include "strv.h" +#include "time-util.h" int serialize_item(FILE *f, const char *key, const char *value) { assert(f); diff --git a/src/shared/serialize.h b/src/shared/serialize.h index e9fe3c276c0..45bd710d731 100644 --- a/src/shared/serialize.h +++ b/src/shared/serialize.h @@ -1,18 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-id128.h" - -#include "fdset.h" -#include "image-policy.h" -#include "macro.h" -#include "pidref.h" -#include "ratelimit.h" -#include "set.h" -#include "string-util.h" -#include "time-util.h" +#include "forward.h" int serialize_item(FILE *f, const char *key, const char *value); int serialize_item_escaped(FILE *f, const char *key, const char *value); diff --git a/src/shared/service-util.c b/src/shared/service-util.c index 81d004d0030..2645fe2c40b 100644 --- a/src/shared/service-util.c +++ b/src/shared/service-util.c @@ -5,10 +5,10 @@ #include "alloc-util.h" #include "build.h" +#include "bus-object.h" #include "log.h" #include "pretty-print.h" #include "service-util.h" -#include "terminal-util.h" static int help(const char *program_path, const char *service, const char *description, bool bus_introspect) { _cleanup_free_ char *link = NULL; diff --git a/src/shared/service-util.h b/src/shared/service-util.h index 360341fb2f4..af36354e80e 100644 --- a/src/shared/service-util.h +++ b/src/shared/service-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "bus-object.h" +#include "forward.h" int service_parse_argv( const char *service, diff --git a/src/shared/shift-uid.c b/src/shared/shift-uid.c index 96f22cdf502..1b1af554844 100644 --- a/src/shared/shift-uid.c +++ b/src/shared/shift-uid.c @@ -1,16 +1,19 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include "acl-util.h" #include "alloc-util.h" #include "dirent-util.h" #include "fd-util.h" #include "fileio.h" +#include "fs-util.h" #include "log.h" #include "missing_magic.h" #include "shift-uid.h" #include "stat-util.h" +#include "string-util.h" #include "user-util.h" /* While we are chmod()ing a directory tree, we set the top-level UID base to this "busy" base, so that we can always diff --git a/src/shared/shift-uid.h b/src/shared/shift-uid.h index 5c7349bc733..59435c748d2 100644 --- a/src/shared/shift-uid.h +++ b/src/shared/shift-uid.h @@ -2,6 +2,6 @@ #pragma once -#include +#include "forward.h" int path_patch_uid(const char *path, uid_t shift, uid_t range); diff --git a/src/shared/sleep-config.c b/src/shared/sleep-config.c index 53f90aae273..9a6e258bd8b 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -4,20 +4,11 @@ #include "alloc-util.h" #include "conf-parser.h" -#include "constants.h" -#include "device-util.h" -#include "devnum-util.h" -#include "errno-util.h" #include "extract-word.h" -#include "fd-util.h" #include "fileio.h" #include "hibernate-util.h" #include "log.h" -#include "macro.h" -#include "path-util.h" #include "sleep-config.h" -#include "stat-util.h" -#include "stdio-util.h" #include "string-table.h" #include "string-util.h" #include "strv.h" @@ -190,6 +181,18 @@ int parse_sleep_config(SleepConfig **ret) { return 0; } +bool SLEEP_NEEDS_MEM_SLEEP(const SleepConfig *sc, SleepOperation operation) { + assert(sc); + assert(operation >= 0 && operation < _SLEEP_OPERATION_CONFIG_MAX); + + /* As per https://docs.kernel.org/admin-guide/pm/sleep-states.html#basic-sysfs-interfaces-for-system-suspend-and-hibernation, + * /sys/power/mem_sleep is honored if /sys/power/state is set to "mem" (common for suspend) + * or /sys/power/disk is set to "suspend" (hybrid-sleep). */ + + return strv_contains(sc->states[operation], "mem") || + strv_contains(sc->modes[operation], "suspend"); +} + int sleep_state_supported(char * const *states) { _cleanup_free_ char *supported_sysfs = NULL; const char *found; diff --git a/src/shared/sleep-config.h b/src/shared/sleep-config.h index b05efaea95e..07d9848db2c 100644 --- a/src/shared/sleep-config.h +++ b/src/shared/sleep-config.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "strv.h" -#include "time-util.h" +#include "forward.h" typedef enum SleepOperation { SLEEP_SUSPEND, @@ -42,17 +41,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(SleepConfig*, sleep_config_free); int parse_sleep_config(SleepConfig **sleep_config); -static inline bool SLEEP_NEEDS_MEM_SLEEP(const SleepConfig *sc, SleepOperation operation) { - assert(sc); - assert(operation >= 0 && operation < _SLEEP_OPERATION_CONFIG_MAX); - - /* As per https://docs.kernel.org/admin-guide/pm/sleep-states.html#basic-sysfs-interfaces-for-system-suspend-and-hibernation, - * /sys/power/mem_sleep is honored if /sys/power/state is set to "mem" (common for suspend) - * or /sys/power/disk is set to "suspend" (hybrid-sleep). */ - - return strv_contains(sc->states[operation], "mem") || - strv_contains(sc->modes[operation], "suspend"); -} +bool SLEEP_NEEDS_MEM_SLEEP(const SleepConfig *sc, SleepOperation operation); typedef enum SleepSupport { SLEEP_SUPPORTED, diff --git a/src/shared/smack-util.c b/src/shared/smack-util.c index 961bc1e0d62..653e73fb94f 100644 --- a/src/shared/smack-util.c +++ b/src/shared/smack-util.c @@ -5,10 +5,8 @@ Author: Auke Kok ***/ -#include #include #include -#include #include #include "alloc-util.h" @@ -16,29 +14,32 @@ #include "fd-util.h" #include "fileio.h" #include "label.h" +#include "label-util.h" #include "log.h" -#include "macro.h" #include "path-util.h" #include "process-util.h" #include "smack-util.h" -#include "stdio-util.h" #include "string-table.h" #include "xattr-util.h" -#if ENABLE_SMACK - #define SMACK_FLOOR_LABEL "_" #define SMACK_STAR_LABEL "*" bool mac_smack_use(void) { +#if ENABLE_SMACK static int cached_use = -1; if (cached_use < 0) cached_use = access("/sys/fs/smackfs/", F_OK) >= 0; return cached_use; +#else + return false; +#endif } +#if ENABLE_SMACK + static const char* const smack_attr_table[_SMACK_ATTR_MAX] = { [SMACK_ATTR_ACCESS] = "security.SMACK64", [SMACK_ATTR_EXEC] = "security.SMACK64EXEC", @@ -50,7 +51,10 @@ static const char* const smack_attr_table[_SMACK_ATTR_MAX] = { DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(smack_attr, SmackAttr); +#endif + int mac_smack_read_at(int fd, const char *path, SmackAttr attr, char **ret) { +#if ENABLE_SMACK assert(fd >= 0 || fd == AT_FDCWD); assert(attr >= 0 && attr < _SMACK_ATTR_MAX); assert(ret); @@ -61,9 +65,13 @@ int mac_smack_read_at(int fd, const char *path, SmackAttr attr, char **ret) { } return getxattr_at_malloc(fd, path, smack_attr_to_string(attr), /* at_flags = */ 0, ret, /* ret_size= */ NULL); +#else +return -EOPNOTSUPP; +#endif } int mac_smack_apply_at(int fd, const char *path, SmackAttr attr, const char *label) { +#if ENABLE_SMACK assert(fd >= 0 || fd == AT_FDCWD); assert(attr >= 0 && attr < _SMACK_ATTR_MAX); @@ -74,9 +82,13 @@ int mac_smack_apply_at(int fd, const char *path, SmackAttr attr, const char *lab return xremovexattr(fd, path, /* at_flags = */ 0, smack_attr_to_string(attr)); return xsetxattr(fd, path, /* at_flags = */ 0, smack_attr_to_string(attr), label); +#else + return 0; +#endif } int mac_smack_apply_pid(pid_t pid, const char *label) { +#if ENABLE_SMACK const char *p; assert(pid >= 0); @@ -87,8 +99,13 @@ int mac_smack_apply_pid(pid_t pid, const char *label) { p = procfs_file_alloca(pid, "attr/current"); return write_string_file(p, label, WRITE_STRING_FILE_DISABLE_BUFFER); +#else + return 0; +#endif } +#if ENABLE_SMACK + static int smack_fix_fd( int fd, const char *label_path, @@ -146,12 +163,15 @@ static int smack_fix_fd( return 0; } +#endif + int mac_smack_fix_full( int atfd, const char *inode_path, const char *label_path, LabelFixFlags flags) { +#if ENABLE_SMACK _cleanup_close_ int opened_fd = -EBADF; _cleanup_free_ char *p = NULL; int r, inode_fd; @@ -186,8 +206,14 @@ int mac_smack_fix_full( } return smack_fix_fd(inode_fd, label_path, flags); -} +#else + return 0; #endif +} + +int mac_smack_fix(const char *path, LabelFixFlags flags) { + return mac_smack_fix_full(AT_FDCWD, path, path, flags); +} int renameat_and_apply_smack_floor_label(int fdf, const char *from, int fdt, const char *to) { diff --git a/src/shared/smack-util.h b/src/shared/smack-util.h index 5bd2cea38bc..b7788898426 100644 --- a/src/shared/smack-util.h +++ b/src/shared/smack-util.h @@ -7,12 +7,7 @@ Author: Auke Kok ***/ -#include -#include -#include - -#include "label-util.h" -#include "macro.h" +#include "forward.h" typedef enum SmackAttr { SMACK_ATTR_ACCESS, @@ -25,7 +20,6 @@ typedef enum SmackAttr { _SMACK_ATTR_INVALID = -EINVAL, } SmackAttr; -#if ENABLE_SMACK bool mac_smack_use(void); int mac_smack_read_at(int fd, const char *path, SmackAttr attr, char **ret); @@ -34,27 +28,6 @@ int mac_smack_apply_at(int fd, const char *path, SmackAttr attr, const char *lab int mac_smack_apply_pid(pid_t pid, const char *label); int mac_smack_fix_full(int atfd, const char *inode_path, const char *label_path, LabelFixFlags flags); -#else -static inline bool mac_smack_use(void) { - return false; -} - -static inline int mac_smack_read_at(int fd, const char *path, SmackAttr attr, char **ret) { - return -EOPNOTSUPP; -} - -static inline int mac_smack_apply_at(int fd, const char *path, SmackAttr attr, const char *label) { - return 0; -} - -static inline int mac_smack_apply_pid(pid_t pid, const char *label) { - return 0; -} - -static inline int mac_smack_fix_full(int atfd, const char *inode_path, const char *label_path, LabelFixFlags flags) { - return 0; -} -#endif int mac_smack_init(void); @@ -72,9 +45,7 @@ static inline int mac_smack_apply_fd(int fd, SmackAttr attr, const char *label) return mac_smack_apply_at(fd, NULL, attr, label); } -static inline int mac_smack_fix(const char *path, LabelFixFlags flags) { - return mac_smack_fix_full(AT_FDCWD, path, path, flags); -} +int mac_smack_fix(const char *path, LabelFixFlags flags); int renameat_and_apply_smack_floor_label(int fdf, const char *from, int fdt, const char *to); static inline int rename_and_apply_smack_floor_label(const char *from, const char *to) { diff --git a/src/shared/smbios11.c b/src/shared/smbios11.c index bd095992e9b..1c6968d21fc 100644 --- a/src/shared/smbios11.c +++ b/src/shared/smbios11.c @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + #include "alloc-util.h" -#include "assert-util.h" #include "fileio.h" -#include "macro.h" #include "smbios11.h" #include "virt.h" diff --git a/src/shared/smbios11.h b/src/shared/smbios11.h index ca8fe452605..1d097c0af43 100644 --- a/src/shared/smbios11.h +++ b/src/shared/smbios11.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" int read_smbios11_field(unsigned i, size_t max_size, char **ret_data, size_t *ret_size); diff --git a/src/shared/socket-label.c b/src/shared/socket-label.c index b86a6adbb96..0e41f2674e1 100644 --- a/src/shared/socket-label.c +++ b/src/shared/socket-label.c @@ -1,19 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include -#include -#include #include -#include "alloc-util.h" +#include "errno-util.h" #include "fd-util.h" #include "fs-util.h" #include "log.h" -#include "macro.h" -#include "missing_socket.h" #include "mkdir-label.h" #include "selinux-util.h" #include "socket-util.h" diff --git a/src/shared/socket-netlink.c b/src/shared/socket-netlink.c index a810e1c1f3d..79184bba3dd 100644 --- a/src/shared/socket-netlink.c +++ b/src/shared/socket-netlink.c @@ -1,21 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include -#include #include #include #include "sd-netlink.h" #include "alloc-util.h" -#include "errno-util.h" #include "extract-word.h" #include "fd-util.h" #include "log.h" -#include "memory-util.h" #include "namespace-util.h" #include "netlink-sock-diag.h" #include "netlink-util.h" diff --git a/src/shared/socket-netlink.h b/src/shared/socket-netlink.h index 88b9c7688bf..c9b71d5100b 100644 --- a/src/shared/socket-netlink.h +++ b/src/shared/socket-netlink.h @@ -1,9 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "forward.h" #include "in-addr-util.h" -#include "macro.h" -#include "socket-util.h" int make_socket_fd(int log_level, const char* address, int type, int flags); diff --git a/src/shared/specifier.c b/src/shared/specifier.c index 950b848d40c..62b036a74ef 100644 --- a/src/shared/specifier.c +++ b/src/shared/specifier.c @@ -1,26 +1,21 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include -#include -#include #include +#include #include "sd-id128.h" #include "alloc-util.h" #include "architecture.h" #include "chase.h" -#include "fd-util.h" #include "format-util.h" #include "fs-util.h" #include "hostname-setup.h" #include "hostname-util.h" #include "id128-util.h" -#include "macro.h" #include "os-util.h" -#include "path-lookup.h" #include "path-util.h" +#include "runtime-scope.h" #include "specifier.h" #include "string-util.h" #include "strv.h" @@ -428,6 +423,10 @@ int specifier_var_tmp_dir(char specifier, const void *data, const char *root, co return strdup_to(ret, p); } +char* specifier_escape(const char *string) { + return strreplace(string, "%", "%%"); +} + int specifier_escape_strv(char **l, char ***ret) { _cleanup_strv_free_ char **z = NULL; char **p, **q; diff --git a/src/shared/specifier.h b/src/shared/specifier.h index df72bdc39b1..3b9d43cd85d 100644 --- a/src/shared/specifier.h +++ b/src/shared/specifier.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "string-util.h" +#include "forward.h" typedef int (*SpecifierCallback)(char specifier, const void *data, const char *root, const void *userdata, char **ret); @@ -98,9 +98,7 @@ int specifier_var_tmp_dir(char specifier, const void *data, const char *root, co { 'T', specifier_tmp_dir, NULL }, \ { 'V', specifier_var_tmp_dir, NULL } -static inline char* specifier_escape(const char *string) { - return strreplace(string, "%", "%%"); -} +char* specifier_escape(const char *string); int specifier_escape_strv(char **l, char ***ret); diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 9e55141eedc..288280c3d19 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -1,9 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include #include #include #include @@ -11,21 +8,16 @@ #include "alloc-util.h" #include "base-filesystem.h" #include "chase.h" -#include "creds-util.h" +#include "errno-util.h" #include "fd-util.h" -#include "initrd-util.h" #include "log.h" #include "missing_syscall.h" #include "mkdir-label.h" #include "mount-util.h" #include "mountpoint-util.h" -#include "path-util.h" #include "rm-rf.h" -#include "stdio-util.h" -#include "string-util.h" -#include "strv.h" +#include "stat-util.h" #include "switch-root.h" -#include "user-util.h" int switch_root(const char *new_root, const char *old_root_after, /* path below the new root, where to place the old root after the transition; may be NULL to unmount it */ diff --git a/src/shared/switch-root.h b/src/shared/switch-root.h index ba0d280eba4..2b8e143251d 100644 --- a/src/shared/switch-root.h +++ b/src/shared/switch-root.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" typedef enum SwitchRootFlags { SWITCH_ROOT_DESTROY_OLD_ROOT = 1 << 0, /* rm -rf old root when switching – under the condition diff --git a/src/shared/test-tables.h b/src/shared/test-tables.h index bf8c9134378..41b719ccce5 100644 --- a/src/shared/test-tables.h +++ b/src/shared/test-tables.h @@ -1,12 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include -#include - +#include "forward.h" #include "string-util.h" #define _test_table(type, name, lookup, reverse, size, sparse) \ diff --git a/src/shared/tests.c b/src/shared/tests.c index 66e1ae88cd6..bc80d153ac7 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -1,15 +1,16 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include -#include +#include #include #include "sd-bus.h" +#include "sd-daemon.h" #include "alloc-util.h" +#include "argv-util.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-util.h" @@ -18,15 +19,17 @@ #include "cgroup-util.h" #include "env-file.h" #include "env-util.h" +#include "errno-util.h" +#include "extract-word.h" #include "fd-util.h" #include "fs-util.h" #include "hexdecoct.h" #include "log.h" -#include "mountpoint-util.h" #include "namespace-util.h" #include "path-util.h" #include "process-util.h" #include "random-util.h" +#include "rlimit-util.h" #include "strv.h" #include "tests.h" #include "tmpfile-util.h" diff --git a/src/shared/tests.h b/src/shared/tests.h index f339e25aef0..33acbb7cdf1 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -1,24 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include - -#include "sd-daemon.h" - -#include "argv-util.h" #include "errno-util.h" -#include "extract-word.h" #include "forward.h" #include "log.h" -#include "macro.h" -#include "process-util.h" -#include "rlimit-util.h" -#include "signal-util.h" #include "static-destruct.h" +#include "signal-util.h" #include "stdio-util.h" -#include "strv.h" +#include "string-util.h" static inline void log_set_assert_return_is_criticalp(bool *p) { log_set_assert_return_is_critical(*p); diff --git a/src/shared/tmpfile-util-label.h b/src/shared/tmpfile-util-label.h index 68ab0755a97..4189b286815 100644 --- a/src/shared/tmpfile-util-label.h +++ b/src/shared/tmpfile-util-label.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include +#include "forward.h" /* These functions are split out of tmpfile-util.h (and not for example just flags to the functions they * wrap) in order to optimize linking: this way, -lselinux is needed only for the callers of these functions diff --git a/src/shared/tomoyo-util.h b/src/shared/tomoyo-util.h index a6ee7d4b26b..d5c0fe8e66a 100644 --- a/src/shared/tomoyo-util.h +++ b/src/shared/tomoyo-util.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" bool mac_tomoyo_use(void); diff --git a/src/shared/tpm2-event-log.h b/src/shared/tpm2-event-log.h index a33448fb858..76890fe1585 100644 --- a/src/shared/tpm2-event-log.h +++ b/src/shared/tpm2-event-log.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - +#include "forward.h" #include "tpm2-util.h" /* Definitions as per "TCG PC Client Specific Platform Firmware Profile Specification" diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index d400d562eb4..18d28015157 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include +#include #include "alloc-util.h" #include "ansi-color.h" @@ -21,24 +22,24 @@ #include "initrd-util.h" #include "io-util.h" #include "json-util.h" -#include "lock-util.h" #include "log.h" #include "logarithm.h" #include "memory-util.h" #include "mkdir.h" -#include "nulstr-util.h" -#include "parse-util.h" +#include "ordered-set.h" #include "random-util.h" #include "recurse-dir.h" -#include "sha256.h" +#include "siphash24.h" #include "sort-util.h" #include "sparse-endian.h" #include "stat-util.h" #include "string-table.h" +#include "string-util.h" +#include "strv.h" #include "sync-util.h" #include "time-util.h" +#include "tpm2-pcr.h" #include "tpm2-util.h" -#include "user-util.h" #include "virt.h" #if HAVE_OPENSSL diff --git a/src/shared/tpm2-util.h b/src/shared/tpm2-util.h index c9b0c43ae5a..a428ee04a0a 100644 --- a/src/shared/tpm2-util.h +++ b/src/shared/tpm2-util.h @@ -1,17 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-json.h" - #include "bitfield.h" -#include "io-util.h" -#include "macro.h" +#include "forward.h" #include "openssl-util.h" -#include "ordered-set.h" -#include "sha256.h" -#include "tpm2-pcr.h" typedef enum TPM2Flags { TPM2_FLAGS_USE_PIN = 1 << 0, @@ -49,9 +41,9 @@ static inline bool TPM2_PCR_MASK_VALID(uint32_t pcr_mask) { #if HAVE_TPM2 -#include -#include -#include +#include /* IWYU pragma: export */ +#include /* IWYU pragma: export */ +#include /* IWYU pragma: export */ int dlopen_tpm2(void); diff --git a/src/shared/udev-util.c b/src/shared/udev-util.c index 6b931a60d83..c63b956deaf 100644 --- a/src/shared/udev-util.c +++ b/src/shared/udev-util.c @@ -1,22 +1,20 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include +#include #include +#include "sd-event.h" +#include "sd-id128.h" + #include "alloc-util.h" #include "device-nodes.h" #include "device-private.h" #include "device-util.h" -#include "env-file.h" #include "errno-util.h" -#include "fd-util.h" -#include "id128-util.h" +#include "hashmap.h" #include "log.h" -#include "macro.h" -#include "parse-util.h" #include "path-util.h" -#include "signal-util.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" diff --git a/src/shared/udev-util.h b/src/shared/udev-util.h index c21c4c158ca..95992f6345c 100644 --- a/src/shared/udev-util.h +++ b/src/shared/udev-util.h @@ -1,11 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "sd-device.h" - #include "conf-parser.h" -#include "hashmap.h" -#include "time-util.h" +#include "forward.h" int udev_parse_config_full(const ConfigTableItem config_table[]); int udev_parse_config(void); diff --git a/src/shared/unit-file.c b/src/shared/unit-file.c index c0f695b9bb4..2833b5be68c 100644 --- a/src/shared/unit-file.c +++ b/src/shared/unit-file.c @@ -7,16 +7,19 @@ #include "dirent-util.h" #include "fd-util.h" #include "fs-util.h" +#include "glyph-util.h" #include "initrd-util.h" #include "log.h" -#include "macro.h" #include "path-lookup.h" #include "set.h" +#include "siphash24.h" #include "special.h" #include "stat-util.h" #include "string-util.h" #include "strv.h" +#include "time-util.h" #include "unit-file.h" +#include "unit-name.h" int unit_symlink_name_compatible(const char *symlink, const char *target, bool instance_propagation) { _cleanup_free_ char *template = NULL; diff --git a/src/shared/unit-file.h b/src/shared/unit-file.h index dd7dc57d15e..bfb6b740cc9 100644 --- a/src/shared/unit-file.h +++ b/src/shared/unit-file.h @@ -1,16 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" +#include "unit-def.h" -#include "hashmap.h" -#include "path-lookup.h" -#include "time-util.h" -#include "unit-name.h" - -typedef enum UnitFileState UnitFileState; - -enum UnitFileState { +typedef enum UnitFileState { UNIT_FILE_ENABLED, UNIT_FILE_ENABLED_RUNTIME, UNIT_FILE_LINKED, @@ -26,7 +20,7 @@ enum UnitFileState { UNIT_FILE_BAD, _UNIT_FILE_STATE_MAX, _UNIT_FILE_STATE_INVALID = -EINVAL, -}; +} UnitFileState; static inline bool unit_type_may_alias(UnitType type) { return IN_SET(type, diff --git a/src/shared/user-record-nss.c b/src/shared/user-record-nss.c index c2ad11a0c20..10a5a75e9fe 100644 --- a/src/shared/user-record-nss.c +++ b/src/shared/user-record-nss.c @@ -1,11 +1,19 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include + +#include "sd-json.h" + #include "alloc-util.h" #include "errno-util.h" #include "format-util.h" +#include "group-record.h" #include "libcrypt-util.h" #include "log.h" +#include "string-util.h" #include "strv.h" +#include "time-util.h" +#include "user-record.h" #include "user-record-nss.h" #include "user-util.h" #include "utf8.h" diff --git a/src/shared/user-record-nss.h b/src/shared/user-record-nss.h index 22ab04d6eec..c2f2faf16c8 100644 --- a/src/shared/user-record-nss.h +++ b/src/shared/user-record-nss.h @@ -1,13 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include -#include -#include - -#include "group-record.h" -#include "user-record.h" +#include "forward.h" /* Synthesize UserRecord and GroupRecord objects from NSS data */ diff --git a/src/shared/user-record-show.c b/src/shared/user-record-show.c index 11af68a72ef..0dea12d4ca2 100644 --- a/src/shared/user-record-show.c +++ b/src/shared/user-record-show.c @@ -1,20 +1,22 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "alloc-util.h" #include "cap-list.h" #include "format-util.h" -#include "fs-util.h" #include "glyph-util.h" #include "hashmap.h" #include "hexdecoct.h" -#include "log.h" #include "path-util.h" #include "percent-util.h" #include "pretty-print.h" #include "process-util.h" #include "rlimit-util.h" #include "sha256.h" +#include "string-util.h" #include "strv.h" -#include "terminal-util.h" +#include "time-util.h" +#include "user-record.h" +#include "group-record.h" #include "user-record-show.h" #include "user-util.h" #include "userdb.h" diff --git a/src/shared/user-record-show.h b/src/shared/user-record-show.h index 7b65b14e9d2..3612fa3624d 100644 --- a/src/shared/user-record-show.h +++ b/src/shared/user-record-show.h @@ -1,8 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "group-record.h" -#include "user-record.h" +#include "forward.h" const char* user_record_state_color(const char *state); diff --git a/src/shared/user-record.c b/src/shared/user-record.c index 2dd590110e3..e0ff097bf30 100644 --- a/src/shared/user-record.c +++ b/src/shared/user-record.c @@ -7,12 +7,9 @@ #include "cap-list.h" #include "cgroup-util.h" #include "dns-domain.h" -#include "env-util.h" -#include "fs-util.h" #include "glyph-util.h" -#include "hexdecoct.h" +#include "hashmap.h" #include "hostname-setup.h" -#include "hostname-util.h" #include "json-util.h" #include "locale-util.h" #include "log.h" @@ -23,11 +20,12 @@ #include "rlimit-util.h" #include "sha256.h" #include "string-table.h" +#include "string-util.h" #include "strv.h" +#include "time-util.h" #include "uid-classification.h" #include "user-record.h" #include "user-util.h" -#include "utf8.h" #define DEFAULT_RATELIMIT_BURST 30 #define DEFAULT_RATELIMIT_INTERVAL_USEC (1*USEC_PER_MINUTE) @@ -106,6 +104,11 @@ UserRecord* user_record_new(void) { return h; } +sd_json_dispatch_flags_t USER_RECORD_LOAD_FLAGS_TO_JSON_DISPATCH_FLAGS(UserRecordLoadFlags flags) { + return (FLAGS_SET(flags, USER_RECORD_LOG) ? SD_JSON_LOG : 0) | + (FLAGS_SET(flags, USER_RECORD_PERMISSIVE) ? SD_JSON_PERMISSIVE : 0); +} + static void pkcs11_encrypted_key_done(Pkcs11EncryptedKey *k) { if (!k) return; @@ -2761,6 +2764,21 @@ int suitable_blob_filename(const char *name) { name[0] != '.'; } +bool userdb_match_is_set(const UserDBMatch *match) { + if (!match) + return false; + + return !strv_isempty(match->fuzzy_names) || + !FLAGS_SET(match->disposition_mask, USER_DISPOSITION_MASK_ALL) || + match->uid_min > 0 || + match->uid_max < UID_INVALID-1; +} + +void userdb_match_done(UserDBMatch *match) { + assert(match); + strv_free(match->fuzzy_names); +} + bool user_name_fuzzy_match(const char *names[], size_t n_names, char **matches) { assert(names || n_names == 0); diff --git a/src/shared/user-record.h b/src/shared/user-record.h index fde03e55958..870c30b7a82 100644 --- a/src/shared/user-record.h +++ b/src/shared/user-record.h @@ -1,18 +1,11 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - #include "sd-id128.h" -#include "sd-json.h" #include "bitfield.h" -#include "hashmap.h" #include "rlimit-util.h" -#include "strv.h" -#include "time-util.h" -#include "user-util.h" +#include "forward.h" typedef enum UserDisposition { USER_INTRINSIC, /* root and nobody */ @@ -184,10 +177,7 @@ static inline UserRecordMask USER_RECORD_STRIP_MASK(UserRecordLoadFlags f) { return (f >> 21) & _USER_RECORD_MASK_MAX; } -static inline sd_json_dispatch_flags_t USER_RECORD_LOAD_FLAGS_TO_JSON_DISPATCH_FLAGS(UserRecordLoadFlags flags) { - return (FLAGS_SET(flags, USER_RECORD_LOG) ? SD_JSON_LOG : 0) | - (FLAGS_SET(flags, USER_RECORD_PERMISSIVE) ? SD_JSON_PERMISSIVE : 0); -} +sd_json_dispatch_flags_t USER_RECORD_LOAD_FLAGS_TO_JSON_DISPATCH_FLAGS(UserRecordLoadFlags flags); typedef struct Pkcs11EncryptedKey { /* The encrypted passphrase, which can be decrypted with the private key indicated below */ @@ -541,22 +531,11 @@ typedef struct UserDBMatch { INDEXES_TO_MASK(uint64_t, USER_INTRINSIC, USER_SYSTEM), \ .uid_min = 0, \ .uid_max = UID_NOBODY - 1, \ - } + } -static inline bool userdb_match_is_set(const UserDBMatch *match) { - if (!match) - return false; +bool userdb_match_is_set(const UserDBMatch *match); - return !strv_isempty(match->fuzzy_names) || - !FLAGS_SET(match->disposition_mask, USER_DISPOSITION_MASK_ALL) || - match->uid_min > 0 || - match->uid_max < UID_INVALID-1; -} - -static inline void userdb_match_done(UserDBMatch *match) { - assert(match); - strv_free(match->fuzzy_names); -} +void userdb_match_done(UserDBMatch *match); bool user_name_fuzzy_match(const char *names[], size_t n_names, char **matches); bool user_record_match(UserRecord *u, const UserDBMatch *match); diff --git a/src/shared/userdb-dropin.c b/src/shared/userdb-dropin.c index 176cdddaafd..08dbccf0b2f 100644 --- a/src/shared/userdb-dropin.c +++ b/src/shared/userdb-dropin.c @@ -1,15 +1,18 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-json.h" + #include "alloc-util.h" #include "errno-util.h" #include "fd-util.h" #include "fileio.h" #include "format-util.h" #include "group-record.h" -#include "log.h" #include "path-util.h" #include "stdio-util.h" +#include "string-util.h" #include "user-util.h" +#include "userdb.h" #include "userdb-dropin.h" static int load_user( diff --git a/src/shared/userdb-dropin.h b/src/shared/userdb-dropin.h index 3bd1b9c8451..170232f99d4 100644 --- a/src/shared/userdb-dropin.h +++ b/src/shared/userdb-dropin.h @@ -1,10 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "constants.h" -#include "group-record.h" -#include "user-record.h" -#include "userdb.h" +#include "forward.h" /* This could be put together with CONF_PATHS_NULSTR, with the exception of the /run/host/ part in the * middle, which we use here, but not otherwise. */ diff --git a/src/shared/userdb.c b/src/shared/userdb.c index 2972def56a3..5274f87da17 100644 --- a/src/shared/userdb.c +++ b/src/shared/userdb.c @@ -1,7 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include +#include +#include +#include "sd-event.h" #include "sd-varlink.h" #include "alloc-util.h" @@ -14,10 +16,9 @@ #include "format-util.h" #include "json-util.h" #include "log.h" -#include "missing_syscall.h" #include "parse-util.h" #include "set.h" -#include "socket-util.h" +#include "string-util.h" #include "strv.h" #include "uid-classification.h" #include "user-record-nss.h" diff --git a/src/shared/userdb.h b/src/shared/userdb.h index 683b94a6df4..4004d80d232 100644 --- a/src/shared/userdb.h +++ b/src/shared/userdb.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - +#include "forward.h" #include "group-record.h" #include "user-record.h" diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c index 853ef29a7c7..b0581162ab7 100644 --- a/src/shared/utmp-wtmp.c +++ b/src/shared/utmp-wtmp.c @@ -1,24 +1,14 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include -#include #include -#include #include -#include "alloc-util.h" -#include "errno-util.h" -#include "hostname-util.h" #include "log.h" -#include "macro.h" #include "memory-util.h" -#include "path-util.h" #include "string-util.h" #include "time-util.h" -#include "user-util.h" #include "utmp-wtmp.h" int utmp_get_runlevel(int *runlevel, int *previous) { diff --git a/src/shared/utmp-wtmp.h b/src/shared/utmp-wtmp.h index 8577d9b013d..f4b543e6c08 100644 --- a/src/shared/utmp-wtmp.h +++ b/src/shared/utmp-wtmp.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "assert-util.h" -#include "time-util.h" +#include "forward.h" #if ENABLE_UTMP #include diff --git a/src/shared/varlink-io.systemd.Login.c b/src/shared/varlink-io.systemd.Login.c index e76a9d268f4..92cb2dfd75c 100644 --- a/src/shared/varlink-io.systemd.Login.c +++ b/src/shared/varlink-io.systemd.Login.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "bus-polkit.h" #include "varlink-idl-common.h" #include "varlink-io.systemd.Login.h" diff --git a/src/shared/varlink-io.systemd.Manager.c b/src/shared/varlink-io.systemd.Manager.c index 8ab65cf3c4b..2b26ef1dcfe 100644 --- a/src/shared/varlink-io.systemd.Manager.c +++ b/src/shared/varlink-io.systemd.Manager.c @@ -1,6 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "build.h" #include "varlink-idl-common.h" #include "varlink-io.systemd.Manager.h" diff --git a/src/shared/varlink-io.systemd.Udev.h b/src/shared/varlink-io.systemd.Udev.h index d56f613eff5..cb4a97a91c9 100644 --- a/src/shared/varlink-io.systemd.Udev.h +++ b/src/shared/varlink-io.systemd.Udev.h @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ #pragma once -#include "sd-varlink.h" #include "sd-varlink-idl.h" extern const sd_varlink_interface vl_interface_io_systemd_Udev; diff --git a/src/shared/varlink-io.systemd.service.c b/src/shared/varlink-io.systemd.service.c index 21c44a96b74..d130f0df51a 100644 --- a/src/shared/varlink-io.systemd.service.c +++ b/src/shared/varlink-io.systemd.service.c @@ -5,7 +5,6 @@ #include "env-util.h" #include "json-util.h" #include "log.h" -#include "string-util.h" #include "strv.h" #include "utf8.h" #include "varlink-io.systemd.service.h" diff --git a/src/shared/varlink-serialize.c b/src/shared/varlink-serialize.c index 075cb6cc5e1..c7e6c5c4030 100644 --- a/src/shared/varlink-serialize.c +++ b/src/shared/varlink-serialize.c @@ -1,8 +1,13 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-event.h" + +#include "alloc-util.h" +#include "fdset.h" #include "log.h" #include "parse-util.h" #include "socket-util.h" +#include "string-util.h" #include "varlink-internal.h" #include "varlink-serialize.h" diff --git a/src/shared/varlink-serialize.h b/src/shared/varlink-serialize.h index 4cc47aa0536..9bb47b9570d 100644 --- a/src/shared/varlink-serialize.h +++ b/src/shared/varlink-serialize.h @@ -1,11 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "sd-varlink.h" - -#include "fdset.h" +#include "forward.h" int varlink_server_serialize(sd_varlink_server *s, FILE *f, FDSet *fds); int varlink_server_deserialize_one(sd_varlink_server *s, const char *value, FDSet *fds); diff --git a/src/shared/vconsole-util.c b/src/shared/vconsole-util.c index 4b722faeab1..cd623bebdbb 100644 --- a/src/shared/vconsole-util.c +++ b/src/shared/vconsole-util.c @@ -1,5 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include +#include + #include "alloc-util.h" #include "env-util.h" #include "extract-word.h" diff --git a/src/shared/vconsole-util.h b/src/shared/vconsole-util.h index c9acc97b298..00ccd3bbf72 100644 --- a/src/shared/vconsole-util.h +++ b/src/shared/vconsole-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" typedef struct X11Context { char *layout; diff --git a/src/shared/verb-log-control.c b/src/shared/verb-log-control.c index d6748f74922..304dd5431b2 100644 --- a/src/shared/verb-log-control.c +++ b/src/shared/verb-log-control.c @@ -1,10 +1,12 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-bus.h" + #include "alloc-util.h" #include "bus-error.h" +#include "bus-locator.h" #include "log.h" #include "string-util.h" -#include "strv.h" #include "syslog-util.h" #include "verb-log-control.h" diff --git a/src/shared/verb-log-control.h b/src/shared/verb-log-control.h index b9e7cdd10b4..71c5f6c58db 100644 --- a/src/shared/verb-log-control.h +++ b/src/shared/verb-log-control.h @@ -1,8 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "bus-locator.h" +#include "forward.h" int verb_log_control_common(sd_bus *bus, const char *destination, const char *verb, const char *value); diff --git a/src/shared/verbs.c b/src/shared/verbs.c index 5b4b0705ac5..b7b78619fde 100644 --- a/src/shared/verbs.c +++ b/src/shared/verbs.c @@ -1,14 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include -#include -#include #include "env-util.h" #include "log.h" -#include "macro.h" -#include "process-util.h" #include "string-util.h" #include "strv.h" #include "verbs.h" diff --git a/src/shared/verbs.h b/src/shared/verbs.h index 3c0ae79d5a7..abf1a35641c 100644 --- a/src/shared/verbs.h +++ b/src/shared/verbs.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" #define VERB_ANY (UINT_MAX) diff --git a/src/shared/vlan-util.c b/src/shared/vlan-util.c index 17f2d3990b7..2343acb346c 100644 --- a/src/shared/vlan-util.c +++ b/src/shared/vlan-util.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include "conf-parser.h" +#include "log.h" #include "parse-util.h" #include "string-util.h" #include "vlan-util.h" diff --git a/src/shared/vlan-util.h b/src/shared/vlan-util.h index f245b72aab6..835e0f6cc24 100644 --- a/src/shared/vlan-util.h +++ b/src/shared/vlan-util.h @@ -1,10 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include -#include - -#include "conf-parser.h" +#include "conf-parser-forward.h" +#include "forward.h" #define VLANID_MAX 4094 #define VLANID_INVALID UINT16_MAX diff --git a/src/shared/volatile-util.c b/src/shared/volatile-util.c index 5138edbd101..eaf53ac4ad1 100644 --- a/src/shared/volatile-util.c +++ b/src/shared/volatile-util.c @@ -1,13 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "alloc-util.h" -#include "macro.h" -#include "parse-util.h" #include "proc-cmdline.h" #include "string-table.h" -#include "string-util.h" #include "volatile-util.h" int query_volatile_mode(VolatileMode *ret) { diff --git a/src/shared/volatile-util.h b/src/shared/volatile-util.h index ba3073b9131..b9cd6c283a5 100644 --- a/src/shared/volatile-util.h +++ b/src/shared/volatile-util.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" typedef enum VolatileMode { VOLATILE_NO, diff --git a/src/shared/vpick.c b/src/shared/vpick.c index abad0290943..b1b2d930543 100644 --- a/src/shared/vpick.c +++ b/src/shared/vpick.c @@ -7,11 +7,11 @@ #include "bitfield.h" #include "chase.h" #include "fd-util.h" -#include "fs-util.h" #include "log.h" #include "parse-util.h" #include "path-util.h" #include "recurse-dir.h" +#include "stat-util.h" #include "string-util.h" #include "strv.h" #include "vpick.h" diff --git a/src/shared/vpick.h b/src/shared/vpick.h index ce7dac57214..3075a4b0476 100644 --- a/src/shared/vpick.h +++ b/src/shared/vpick.h @@ -2,9 +2,9 @@ #pragma once #include -#include #include "architecture.h" +#include "forward.h" typedef enum PickFlags { PICK_ARCHITECTURE = 1 << 0, /* Look for an architecture suffix */ diff --git a/src/shared/wall.c b/src/shared/wall.c index f936ba97d9d..184c7c63eab 100644 --- a/src/shared/wall.c +++ b/src/shared/wall.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include #include #include "sd-login.h" @@ -15,6 +13,7 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" +#include "time-util.h" #include "user-util.h" #include "utmp-wtmp.h" #include "wall.h" diff --git a/src/shared/wall.h b/src/shared/wall.h index 29642778c7e..c622b6f652d 100644 --- a/src/shared/wall.h +++ b/src/shared/wall.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include +#include "forward.h" #if ENABLE_UTMP || ENABLE_LOGIND diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index 28cae1c2608..5b113013950 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -1,9 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include #include #include #include +#include #include #include diff --git a/src/shared/watchdog.h b/src/shared/watchdog.h index 7880b041282..f613689ca58 100644 --- a/src/shared/watchdog.h +++ b/src/shared/watchdog.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "time-util.h" +#include "forward.h" const char* watchdog_get_device(void); usec_t watchdog_get_last_ping(clockid_t clock); diff --git a/src/shared/web-util.c b/src/shared/web-util.c index 39a300f5c96..628f0805bd3 100644 --- a/src/shared/web-util.c +++ b/src/shared/web-util.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include - #include "string-util.h" #include "strv.h" #include "utf8.h" diff --git a/src/shared/web-util.h b/src/shared/web-util.h index 88b4897be05..1bb8509da07 100644 --- a/src/shared/web-util.h +++ b/src/shared/web-util.h @@ -1,9 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include - -#include "macro.h" +#include "forward.h" bool http_url_is_valid(const char *url) _pure_; bool file_url_is_valid(const char *url) _pure_; diff --git a/src/shared/wifi-util.c b/src/shared/wifi-util.c index 052f5606e53..81b6cda5dd0 100644 --- a/src/shared/wifi-util.c +++ b/src/shared/wifi-util.c @@ -1,5 +1,9 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "sd-netlink.h" + +#include "alloc-util.h" +#include "ether-addr-util.h" #include "log.h" #include "string-table.h" #include "string-util.h" diff --git a/src/shared/wifi-util.h b/src/shared/wifi-util.h index b71df933b77..973a49155ad 100644 --- a/src/shared/wifi-util.h +++ b/src/shared/wifi-util.h @@ -4,9 +4,7 @@ #include -#include "sd-netlink.h" - -#include "ether-addr-util.h" +#include "forward.h" int wifi_get_interface(sd_netlink *genl, int ifindex, enum nl80211_iftype *ret_iftype, char **ret_ssid); int wifi_get_station(sd_netlink *genl, int ifindex, struct ether_addr *ret_bssid); diff --git a/src/shared/xml.c b/src/shared/xml.c index d5ec3b25fe5..a8a99ac3480 100644 --- a/src/shared/xml.c +++ b/src/shared/xml.c @@ -1,10 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include -#include - -#include "log.h" -#include "macro.h" #include "string-util.h" #include "xml.h" diff --git a/src/shared/xml.h b/src/shared/xml.h index 217b3b0e40e..1ef9de147d2 100644 --- a/src/shared/xml.h +++ b/src/shared/xml.h @@ -1,6 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#include "forward.h" + enum { XML_END, XML_TEXT,