diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2022-11-09 01:23:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-09 01:23:17 +0100 |
commit | bf1886226724b3db0779d643195d428575cff0be (patch) | |
tree | f6a912f0950a2bd000625fe2b9c717a0370d3788 /src | |
parent | networkd-ipv4acd.c: Use net/if.h for getting IFF_LOOPBACK definition (diff) | |
parent | Rename def.h to constants.h (diff) | |
download | systemd-bf1886226724b3db0779d643195d428575cff0be.tar.xz systemd-bf1886226724b3db0779d643195d428575cff0be.zip |
Merge pull request #25291 from keszybz/util-cleanup
Split/rename util.c+h and def.h
Diffstat (limited to 'src')
359 files changed, 942 insertions, 996 deletions
diff --git a/src/ac-power/ac-power.c b/src/ac-power/ac-power.c index 12379df344..853635047d 100644 --- a/src/ac-power/ac-power.c +++ b/src/ac-power/ac-power.c @@ -2,6 +2,7 @@ #include <getopt.h> +#include "build.h" #include "main-func.h" #include "udev-util.h" diff --git a/src/activate/activate.c b/src/activate/activate.c index 24ebde0283..5934e7a57a 100644 --- a/src/activate/activate.c +++ b/src/activate/activate.c @@ -9,6 +9,7 @@ #include "sd-daemon.h" #include "alloc-util.h" +#include "build.h" #include "env-util.h" #include "errno-util.h" #include "escape.h" @@ -23,7 +24,6 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" static char **arg_listen = NULL; static bool arg_accept = false; diff --git a/src/analyze/analyze-cat-config.c b/src/analyze/analyze-cat-config.c index d214ceaf42..a30662b49f 100644 --- a/src/analyze/analyze-cat-config.c +++ b/src/analyze/analyze-cat-config.c @@ -3,7 +3,7 @@ #include "analyze.h" #include "analyze-cat-config.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "nulstr-util.h" #include "path-util.h" #include "pretty-print.h" diff --git a/src/analyze/analyze.c b/src/analyze/analyze.c index 6e47357a11..cac2d3adba 100644 --- a/src/analyze/analyze.c +++ b/src/analyze/analyze.c @@ -37,6 +37,7 @@ #include "analyze-unit-paths.h" #include "analyze-compare-versions.h" #include "analyze-verify.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-map-properties.h" @@ -46,7 +47,7 @@ #include "capability-util.h" #include "conf-files.h" #include "copy.h" -#include "def.h" +#include "constants.h" #include "exit-status.h" #include "extract-word.h" #include "fd-util.h" @@ -79,7 +80,6 @@ #include "time-util.h" #include "tmpfile-util.h" #include "unit-name.h" -#include "util.h" #include "verb-log-control.h" #include "verbs.h" #include "version.h" diff --git a/src/ask-password/ask-password.c b/src/ask-password/ask-password.c index 093533182f..f161e65973 100644 --- a/src/ask-password/ask-password.c +++ b/src/ask-password/ask-password.c @@ -6,7 +6,8 @@ #include <unistd.h> #include "ask-password-api.h" -#include "def.h" +#include "build.h" +#include "constants.h" #include "log.h" #include "macro.h" #include "main-func.h" diff --git a/src/backlight/backlight.c b/src/backlight/backlight.c index b6474d31a7..e66477f328 100644 --- a/src/backlight/backlight.c +++ b/src/backlight/backlight.c @@ -19,7 +19,6 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" #define PCI_CLASS_GRAPHICS_CARD 0x30000 diff --git a/src/basic/architecture.h b/src/basic/architecture.h index b86f5f35d0..096526a857 100644 --- a/src/basic/architecture.h +++ b/src/basic/architecture.h @@ -4,7 +4,6 @@ #include <endian.h> #include "macro.h" -#include "util.h" /* A cleaned up architecture definition. We don't want to get lost in * processor features, models, generations or even ABIs. Hence we diff --git a/src/basic/argv-util.c b/src/basic/argv-util.c new file mode 100644 index 0000000000..54649f4bda --- /dev/null +++ b/src/basic/argv-util.c @@ -0,0 +1,222 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include <sched.h> +#include <sys/mman.h> +#include <sys/prctl.h> +#include <unistd.h> + +#include "argv-util.h" +#include "errno-util.h" +#include "missing_sched.h" +#include "parse-util.h" +#include "path-util.h" +#include "process-util.h" +#include "string-util.h" +#include "strv.h" + +int saved_argc = 0; +char **saved_argv = NULL; + +bool invoked_as(char *argv[], const char *token) { + if (!argv || isempty(argv[0])) + return false; + + if (isempty(token)) + return false; + + return strstr(last_path_component(argv[0]), token); +} + +bool invoked_by_systemd(void) { + int r; + + /* If the process is directly executed by PID1 (e.g. ExecStart= or generator), systemd-importd, + * or systemd-homed, then $SYSTEMD_EXEC_PID= is set, and read the command line. */ + const char *e = getenv("SYSTEMD_EXEC_PID"); + if (!e) + return false; + + if (streq(e, "*")) + /* For testing. */ + return true; + + pid_t p; + r = parse_pid(e, &p); + if (r < 0) { + /* We know that systemd sets the variable correctly. Something else must have set it. */ + log_debug_errno(r, "Failed to parse \"SYSTEMD_EXEC_PID=%s\", ignoring: %m", e); + return false; + } + + return getpid_cached() == p; +} + +bool argv_looks_like_help(int argc, char **argv) { + char **l; + + /* Scans the command line for indications the user asks for help. This is supposed to be called by + * tools that do not implement getopt() style command line parsing because they are not primarily + * user-facing. Detects four ways of asking for help: + * + * 1. Passing zero arguments + * 2. Passing "help" as first argument + * 3. Passing --help as any argument + * 4. Passing -h as any argument + */ + + if (argc <= 1) + return true; + + if (streq_ptr(argv[1], "help")) + return true; + + l = strv_skip(argv, 1); + + return strv_contains(l, "--help") || + strv_contains(l, "-h"); +} + +static int update_argv(const char name[], size_t l) { + static int can_do = -1; + + if (can_do == 0) + return 0; + can_do = false; /* We'll set it to true only if the whole process works */ + + /* Let's not bother with this if we don't have euid == 0. Strictly speaking we should check for the + * CAP_SYS_RESOURCE capability which is independent of the euid. In our own code the capability generally is + * present only for euid == 0, hence let's use this as quick bypass check, to avoid calling mmap() if + * PR_SET_MM_ARG_{START,END} fails with EPERM later on anyway. After all geteuid() is dead cheap to call, but + * mmap() is not. */ + if (geteuid() != 0) + return log_debug_errno(SYNTHETIC_ERRNO(EPERM), + "Skipping PR_SET_MM, as we don't have privileges."); + + static size_t mm_size = 0; + static char *mm = NULL; + int r; + + if (mm_size < l+1) { + size_t nn_size; + char *nn; + + nn_size = PAGE_ALIGN(l+1); + nn = mmap(NULL, nn_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); + if (nn == MAP_FAILED) + return log_debug_errno(errno, "mmap() failed: %m"); + + strncpy(nn, name, nn_size); + + /* Now, let's tell the kernel about this new memory */ + if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, (unsigned long) nn, 0, 0) < 0) { + if (ERRNO_IS_PRIVILEGE(errno)) + return log_debug_errno(errno, "PR_SET_MM_ARG_START failed: %m"); + + /* HACK: prctl() API is kind of dumb on this point. The existing end address may already be + * below the desired start address, in which case the kernel may have kicked this back due + * to a range-check failure (see linux/kernel/sys.c:validate_prctl_map() to see this in + * action). The proper solution would be to have a prctl() API that could set both start+end + * simultaneously, or at least let us query the existing address to anticipate this condition + * and respond accordingly. For now, we can only guess at the cause of this failure and try + * a workaround--which will briefly expand the arg space to something potentially huge before + * resizing it to what we want. */ + log_debug_errno(errno, "PR_SET_MM_ARG_START failed, attempting PR_SET_MM_ARG_END hack: %m"); + + if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, (unsigned long) nn + l + 1, 0, 0) < 0) { + r = log_debug_errno(errno, "PR_SET_MM_ARG_END hack failed, proceeding without: %m"); + (void) munmap(nn, nn_size); + return r; + } + + if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, (unsigned long) nn, 0, 0) < 0) + return log_debug_errno(errno, "PR_SET_MM_ARG_START still failed, proceeding without: %m"); + } else { + /* And update the end pointer to the new end, too. If this fails, we don't really know what + * to do, it's pretty unlikely that we can rollback, hence we'll just accept the failure, + * and continue. */ + if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, (unsigned long) nn + l + 1, 0, 0) < 0) + log_debug_errno(errno, "PR_SET_MM_ARG_END failed, proceeding without: %m"); + } + + if (mm) + (void) munmap(mm, mm_size); + + mm = nn; + mm_size = nn_size; + } else { + strncpy(mm, name, mm_size); + + /* Update the end pointer, continuing regardless of any failure. */ + if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, (unsigned long) mm + l + 1, 0, 0) < 0) + log_debug_errno(errno, "PR_SET_MM_ARG_END failed, proceeding without: %m"); + } + + can_do = true; + return 0; +} + +int rename_process(const char name[]) { + bool truncated = false; + + /* This is a like a poor man's setproctitle(). It changes the comm field, argv[0], and also the glibc's + * internally used name of the process. For the first one a limit of 16 chars applies; to the second one in + * many cases one of 10 (i.e. length of "/sbin/init") — however if we have CAP_SYS_RESOURCES it is unbounded; + * to the third one 7 (i.e. the length of "systemd". If you pass a longer string it will likely be + * truncated. + * + * Returns 0 if a name was set but truncated, > 0 if it was set but not truncated. */ + + if (isempty(name)) + return -EINVAL; /* let's not confuse users unnecessarily with an empty name */ + + if (!is_main_thread()) + return -EPERM; /* Let's not allow setting the process name from other threads than the main one, as we + * cache things without locking, and we make assumptions that PR_SET_NAME sets the + * process name that isn't correct on any other threads */ + + size_t l = strlen(name); + + /* First step, change the comm field. The main thread's comm is identical to the process comm. This means we + * can use PR_SET_NAME, which sets the thread name for the calling thread. */ + if (prctl(PR_SET_NAME, name) < 0) + log_debug_errno(errno, "PR_SET_NAME failed: %m"); + if (l >= TASK_COMM_LEN) /* Linux userspace process names can be 15 chars at max */ + truncated = true; + + /* Second step, change glibc's ID of the process name. */ + if (program_invocation_name) { + size_t k; + + k = strlen(program_invocation_name); + strncpy(program_invocation_name, name, k); + if (l > k) + truncated = true; + } + + /* Third step, completely replace the argv[] array the kernel maintains for us. This requires privileges, but + * has the advantage that the argv[] array is exactly what we want it to be, and not filled up with zeros at + * the end. This is the best option for changing /proc/self/cmdline. */ + (void) update_argv(name, l); + + /* Fourth step: in all cases we'll also update the original argv[], so that our own code gets it right too if + * it still looks here */ + if (saved_argc > 0) { + if (saved_argv[0]) { + size_t k; + + k = strlen(saved_argv[0]); + strncpy(saved_argv[0], name, k); + if (l > k) + truncated = true; + } + + for (int i = 1; i < saved_argc; i++) { + if (!saved_argv[i]) + break; + + memzero(saved_argv[i], strlen(saved_argv[i])); + } + } + + return !truncated; +} diff --git a/src/basic/argv-util.h b/src/basic/argv-util.h new file mode 100644 index 0000000000..a20a951793 --- /dev/null +++ b/src/basic/argv-util.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include <stdbool.h> + +#include "macro.h" + +extern int saved_argc; +extern char **saved_argv; + +static inline void save_argc_argv(int argc, char **argv) { + /* Protect against CVE-2021-4034 style attacks */ + assert_se(argc > 0); + assert_se(argv); + assert_se(argv[0]); + + saved_argc = argc; + saved_argv = argv; +} + +bool invoked_as(char *argv[], const char *token); +bool invoked_by_systemd(void); +bool argv_looks_like_help(int argc, char **argv); + +int rename_process(const char name[]); diff --git a/src/basic/async.c b/src/basic/async.c index 443cfa95ab..241803f33a 100644 --- a/src/basic/async.c +++ b/src/basic/async.c @@ -12,7 +12,6 @@ #include "macro.h" #include "process-util.h" #include "signal-util.h" -#include "util.h" int asynchronous_job(void* (*func)(void *p), void *arg) { sigset_t ss, saved_ss; diff --git a/src/basic/build.c b/src/basic/build.c index 4a15f901d0..0b7a44f1f6 100644 --- a/src/basic/build.c +++ b/src/basic/build.c @@ -1,6 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include <stdio.h> + #include "build.h" +#include "macro.h" +#include "version.h" const char* const systemd_features = @@ -226,3 +230,9 @@ const char* const systemd_features = " default-hierarchy=" DEFAULT_HIERARCHY_NAME ; + +int version(void) { + printf("systemd " STRINGIFY(PROJECT_VERSION) " (" GIT_VERSION ")\n%s\n", + systemd_features); + return 0; +} diff --git a/src/basic/build.h b/src/basic/build.h index 87276bf686..27d44111d4 100644 --- a/src/basic/build.h +++ b/src/basic/build.h @@ -4,3 +4,5 @@ #include "version.h" extern const char* const systemd_features; + +int version(void); diff --git a/src/basic/cap-list.c b/src/basic/cap-list.c index fdc7948a23..fb1ad14fd3 100644 --- a/src/basic/cap-list.c +++ b/src/basic/cap-list.c @@ -10,7 +10,6 @@ #include "macro.h" #include "parse-util.h" #include "stdio-util.h" -#include "util.h" static const struct capability_name* lookup_capability(register const char *str, register GPERF_LEN_TYPE len); diff --git a/src/basic/capability-util.c b/src/basic/capability-util.c index fa74b5b9c6..5ab110d341 100644 --- a/src/basic/capability-util.c +++ b/src/basic/capability-util.c @@ -11,11 +11,11 @@ #include "cap-list.h" #include "fileio.h" #include "log.h" +#include "logarithm.h" #include "macro.h" #include "missing_prctl.h" #include "parse-util.h" #include "user-util.h" -#include "util.h" int have_effective_cap(int value) { _cleanup_cap_free_ cap_t cap = NULL; diff --git a/src/basic/capability-util.h b/src/basic/capability-util.h index dbce54531d..4d1b0521f4 100644 --- a/src/basic/capability-util.h +++ b/src/basic/capability-util.h @@ -8,7 +8,6 @@ #include "macro.h" #include "missing_capability.h" -#include "util.h" #define CAP_ALL UINT64_MAX diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c index b03cc70e2e..7949dd7d70 100644 --- a/src/basic/cgroup-util.c +++ b/src/basic/cgroup-util.c @@ -12,7 +12,7 @@ #include "alloc-util.h" #include "cgroup-util.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "extract-word.h" #include "fd-util.h" diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h index df6d5b7bbb..c9aae5abf6 100644 --- a/src/basic/cgroup-util.h +++ b/src/basic/cgroup-util.h @@ -9,7 +9,7 @@ #include <sys/statfs.h> #include <sys/types.h> -#include "def.h" +#include "constants.h" #include "set.h" #define SYSTEMD_CGROUP_CONTROLLER_LEGACY "name=systemd" diff --git a/src/basic/compress.c b/src/basic/compress.c index 1e94635397..0a330ecb55 100644 --- a/src/basic/compress.c +++ b/src/basic/compress.c @@ -32,7 +32,6 @@ #include "string-table.h" #include "string-util.h" #include "unaligned.h" -#include "util.h" #if HAVE_LZ4 DEFINE_TRIVIAL_CLEANUP_FUNC_FULL(LZ4F_compressionContext_t, LZ4F_freeCompressionContext, NULL); diff --git a/src/basic/conf-files.c b/src/basic/conf-files.c index 532c9d19b8..348f7dcc70 100644 --- a/src/basic/conf-files.c +++ b/src/basic/conf-files.c @@ -7,7 +7,7 @@ #include "chase-symlinks.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "fd-util.h" #include "hashmap.h" diff --git a/src/basic/def.h b/src/basic/constants.h index 2b4de29021..54021911ab 100644 --- a/src/basic/def.h +++ b/src/basic/constants.h @@ -1,6 +1,30 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once +#if !defined(HAS_FEATURE_MEMORY_SANITIZER) +# if defined(__has_feature) +# if __has_feature(memory_sanitizer) +# define HAS_FEATURE_MEMORY_SANITIZER 1 +# endif +# endif +# if !defined(HAS_FEATURE_MEMORY_SANITIZER) +# define HAS_FEATURE_MEMORY_SANITIZER 0 +# endif +#endif + +#if !defined(HAS_FEATURE_ADDRESS_SANITIZER) +# ifdef __SANITIZE_ADDRESS__ +# define HAS_FEATURE_ADDRESS_SANITIZER 1 +# elif defined(__has_feature) +# if __has_feature(address_sanitizer) +# define HAS_FEATURE_ADDRESS_SANITIZER 1 +# endif +# endif +# if !defined(HAS_FEATURE_ADDRESS_SANITIZER) +# define HAS_FEATURE_ADDRESS_SANITIZER 0 +# endif +#endif + #define DEFAULT_TIMEOUT_USEC (90*USEC_PER_SEC) #define DEFAULT_RESTART_USEC (100*USEC_PER_MSEC) #define DEFAULT_CONFIRM_USEC (30*USEC_PER_SEC) diff --git a/src/basic/fd-util.c b/src/basic/fd-util.c index 66bb7569bb..ec33a61588 100644 --- a/src/basic/fd-util.c +++ b/src/basic/fd-util.c @@ -29,7 +29,6 @@ #include "stat-util.h" #include "stdio-util.h" #include "tmpfile-util.h" -#include "util.h" /* The maximum number of iterations in the loop to close descriptors in the fallback case * when /proc/self/fd/ is inaccessible. */ diff --git a/src/basic/filesystems.c b/src/basic/filesystems.c index 0f71f8e07c..b11cbb9d65 100644 --- a/src/basic/filesystems.c +++ b/src/basic/filesystems.c @@ -27,7 +27,7 @@ int fs_type_from_string(const char *name, const statfs_f_type_t **ret) { return 0; } -int fs_in_group(const struct statfs *s, FilesystemGroups fs_group) { +bool fs_in_group(const struct statfs *s, FilesystemGroups fs_group) { const char *fs; int r; @@ -35,7 +35,7 @@ int fs_in_group(const struct statfs *s, FilesystemGroups fs_group) { const statfs_f_type_t *magic; r = fs_type_from_string(fs, &magic); - if (r == 0) { + if (r >= 0) for (size_t i = 0; i < FILESYSTEM_MAGIC_MAX; i++) { if (magic[i] == 0) break; @@ -43,7 +43,6 @@ int fs_in_group(const struct statfs *s, FilesystemGroups fs_group) { if (is_fs_type(s, magic[i])) return true; } - } } return false; diff --git a/src/basic/filesystems.h b/src/basic/filesystems.h index 6d07a97ba7..f9edbc1f29 100644 --- a/src/basic/filesystems.h +++ b/src/basic/filesystems.h @@ -36,7 +36,7 @@ const FilesystemSet *filesystem_set_find(const char *name); const char *fs_type_to_string(statfs_f_type_t magic); int fs_type_from_string(const char *name, const statfs_f_type_t **ret); -int fs_in_group(const struct statfs *s, enum FilesystemGroups fs_group); +bool fs_in_group(const struct statfs *s, enum FilesystemGroups fs_group); /* gperf prototypes */ const struct FilesystemMagic* filesystems_gperf_lookup(const char *key, GPERF_LEN_TYPE length); diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 6b757bd570..8b4d81ebdc 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -32,7 +32,6 @@ #include "tmpfile-util.h" #include "umask-util.h" #include "user-util.h" -#include "util.h" int unlink_noerrno(const char *path) { PROTECT_ERRNO; diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index f68cd36bb7..d19627595f 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -9,6 +9,7 @@ #include "alloc-util.h" #include "fileio.h" #include "hashmap.h" +#include "logarithm.h" #include "macro.h" #include "memory-util.h" #include "mempool.h" diff --git a/src/basic/hashmap.h b/src/basic/hashmap.h index 91b3fe862b..ebb5a63eb4 100644 --- a/src/basic/hashmap.h +++ b/src/basic/hashmap.h @@ -7,7 +7,6 @@ #include "hash-funcs.h" #include "macro.h" -#include "util.h" /* * A hash table implementation. As a minor optimization a NULL hashmap object diff --git a/src/basic/in-addr-util.c b/src/basic/in-addr-util.c index 05c729d34d..8ee5c0cc20 100644 --- a/src/basic/in-addr-util.c +++ b/src/basic/in-addr-util.c @@ -11,13 +11,13 @@ #include "alloc-util.h" #include "errno-util.h" #include "in-addr-util.h" +#include "logarithm.h" #include "macro.h" #include "parse-util.h" #include "random-util.h" #include "stdio-util.h" #include "string-util.h" #include "strxcpyx.h" -#include "util.h" bool in4_addr_is_null(const struct in_addr *a) { assert(a); diff --git a/src/basic/in-addr-util.h b/src/basic/in-addr-util.h index 19fa35f1d2..8d6efaa006 100644 --- a/src/basic/in-addr-util.h +++ b/src/basic/in-addr-util.h @@ -8,7 +8,6 @@ #include "hash-funcs.h" #include "macro.h" -#include "util.h" union in_addr_union { struct in_addr in; diff --git a/src/basic/util.c b/src/basic/initrd-util.c index fbcb87001a..2b6809aea5 100644 --- a/src/basic/util.c +++ b/src/basic/initrd-util.c @@ -1,46 +1,15 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include <errno.h> -#include <fcntl.h> -#include <sys/mman.h> +#include <unistd.h> -#include "alloc-util.h" -#include "build.h" -#include "env-file.h" #include "env-util.h" -#include "fd-util.h" -#include "fileio.h" -#include "hostname-util.h" -#include "log.h" -#include "macro.h" +#include "initrd-util.h" #include "parse-util.h" #include "stat-util.h" #include "string-util.h" -#include "util.h" -#include "virt.h" -int saved_argc = 0; -char **saved_argv = NULL; static int saved_in_initrd = -1; -int prot_from_flags(int flags) { - - switch (flags & O_ACCMODE) { - - case O_RDONLY: - return PROT_READ; - - case O_WRONLY: - return PROT_WRITE; - - case O_RDWR: - return PROT_READ|PROT_WRITE; - - default: - return -EINVAL; - } -} - bool in_initrd(void) { int r; const char *e; @@ -104,62 +73,3 @@ bool in_initrd(void) { void in_initrd_force(bool value) { saved_in_initrd = value; } - -int container_get_leader(const char *machine, pid_t *pid) { - _cleanup_free_ char *s = NULL, *class = NULL; - const char *p; - pid_t leader; - int r; - - assert(machine); - assert(pid); - - if (streq(machine, ".host")) { - *pid = 1; - return 0; - } - - if (!hostname_is_valid(machine, 0)) - return -EINVAL; - - p = strjoina("/run/systemd/machines/", machine); - r = parse_env_file(NULL, p, - "LEADER", &s, - "CLASS", &class); - if (r == -ENOENT) - return -EHOSTDOWN; - if (r < 0) - return r; - if (!s) - return -EIO; - - if (!streq_ptr(class, "container")) - return -EIO; - - r = parse_pid(s, &leader); - if (r < 0) - return r; - if (leader <= 1) - return -EIO; - - *pid = leader; - return 0; -} - -int version(void) { - printf("systemd " STRINGIFY(PROJECT_VERSION) " (" GIT_VERSION ")\n%s\n", - systemd_features); - return 0; -} - -/* Turn off core dumps but only if we're running outside of a container. */ -void disable_coredumps(void) { - int r; - - if (detect_container() > 0) - return; - - r = write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", WRITE_STRING_FILE_DISABLE_BUFFER); - if (r < 0) - log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m"); -} diff --git a/src/basic/initrd-util.h b/src/basic/initrd-util.h new file mode 100644 index 0000000000..173093c069 --- /dev/null +++ b/src/basic/initrd-util.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +#pragma once + +#include <stdbool.h> + +bool in_initrd(void); +void in_initrd_force(bool value); diff --git a/src/basic/locale-util.c b/src/basic/locale-util.c index d8518ec06a..2f486a4d92 100644 --- a/src/basic/locale-util.c +++ b/src/basic/locale-util.c @@ -10,7 +10,7 @@ #include <sys/mman.h> #include <sys/stat.h> -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "env-util.h" #include "fd-util.h" diff --git a/src/basic/log.c b/src/basic/log.c index 39d08b0928..173643196e 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -16,6 +16,7 @@ #include "sd-messages.h" #include "alloc-util.h" +#include "argv-util.h" #include "errno-util.h" #include "fd-util.h" #include "format-util.h" diff --git a/src/basic/util.h b/src/basic/logarithm.h index 5d5d821610..646f2d3613 100644 --- a/src/basic/util.h +++ b/src/basic/logarithm.h @@ -5,25 +5,6 @@ #include "macro.h" -extern int saved_argc; -extern char **saved_argv; - -static inline void save_argc_argv(int argc, char **argv) { - - /* Protect against CVE-2021-4034 style attacks */ - assert_se(argc > 0); - assert_se(argv); - assert_se(argv[0]); - - saved_argc = argc; - saved_argv = argv; -} - -int prot_from_flags(int flags) _const_; - -bool in_initrd(void); -void in_initrd_force(bool value); - /* Note: log2(0) == log2(1) == 0 here and below. */ #define CONST_LOG2ULL(x) ((x) > 1 ? (unsigned) __builtin_clzll(x) ^ 63U : 0) @@ -70,9 +51,3 @@ static inline unsigned log2u_round_up(unsigned x) { return log2u(x - 1) + 1; } - -int container_get_leader(const char *machine, pid_t *pid); - -int version(void); - -void disable_coredumps(void); diff --git a/src/basic/macro.h b/src/basic/macro.h index 237117db12..3d1b175123 100644 --- a/src/basic/macro.h +++ b/src/basic/macro.h @@ -9,32 +9,9 @@ #include <sys/sysmacros.h> #include <sys/types.h> +#include "constants.h" #include "macro-fundamental.h" -#if !defined(HAS_FEATURE_MEMORY_SANITIZER) -# if defined(__has_feature) -# if __has_feature(memory_sanitizer) -# define HAS_FEATURE_MEMORY_SANITIZER 1 -# endif -# endif -# if !defined(HAS_FEATURE_MEMORY_SANITIZER) -# define HAS_FEATURE_MEMORY_SANITIZER 0 -# endif -#endif - -#if !defined(HAS_FEATURE_ADDRESS_SANITIZER) -# ifdef __SANITIZE_ADDRESS__ -# define HAS_FEATURE_ADDRESS_SANITIZER 1 -# elif defined(__has_feature) -# if __has_feature(address_sanitizer) -# define HAS_FEATURE_ADDRESS_SANITIZER 1 -# endif -# endif -# if !defined(HAS_FEATURE_ADDRESS_SANITIZER) -# define HAS_FEATURE_ADDRESS_SANITIZER 0 -# endif -#endif - /* Note: on GCC "no_sanitize_address" is a function attribute only, on llvm it may also be applied to global * variables. We define a specific macro which knows this. Note that on GCC we don't need this decorator so much, since * our primary usecase for this attribute is registration structures placed in named ELF sections which shall not be diff --git a/src/basic/meson.build b/src/basic/meson.build index bfe52d5879..541031b8a3 100644 --- a/src/basic/meson.build +++ b/src/basic/meson.build @@ -9,6 +9,8 @@ basic_sources = files( 'alloc-util.h', 'architecture.c', 'architecture.h', + 'argv-util.c', + 'argv-util.h', 'arphrd-util.c', 'arphrd-util.h', 'async.c', @@ -31,7 +33,7 @@ basic_sources = files( 'chattr-util.h', 'conf-files.c', 'conf-files.h', - 'def.h', + 'constants.h', 'devnum-util.c', 'devnum-util.h', 'dirent-util.c', @@ -80,6 +82,8 @@ basic_sources = files( 'hostname-util.h', 'in-addr-util.c', 'in-addr-util.h', + 'initrd-util.c', + 'initrd-util.h', 'inotify-util.c', 'inotify-util.h', 'io-util.c', @@ -126,6 +130,7 @@ basic_sources = files( 'locale-util.h', 'log.c', 'log.h', + 'logarithm.h', 'login-util.c', 'login-util.h', 'macro.h', @@ -254,8 +259,6 @@ basic_sources = files( 'user-util.h', 'utf8.c', 'utf8.h', - 'util.c', - 'util.h', 'virt.c', 'virt.h', 'xattr-util.c', diff --git a/src/basic/path-lookup.h b/src/basic/path-lookup.h index aed72defe7..46eb32c4b0 100644 --- a/src/basic/path-lookup.h +++ b/src/basic/path-lookup.h @@ -3,7 +3,7 @@ #include <stdbool.h> -#include "def.h" +#include "constants.h" #include "macro.h" typedef enum LookupPathsFlags { diff --git a/src/basic/proc-cmdline.c b/src/basic/proc-cmdline.c index 410b8a3eb5..eea70d8606 100644 --- a/src/basic/proc-cmdline.c +++ b/src/basic/proc-cmdline.c @@ -7,13 +7,13 @@ #include "efivars.h" #include "extract-word.h" #include "fileio.h" +#include "initrd-util.h" #include "macro.h" #include "parse-util.h" #include "proc-cmdline.h" #include "process-util.h" #include "special.h" #include "string-util.h" -#include "util.h" #include "virt.h" int proc_cmdline(char **ret) { diff --git a/src/basic/process-util.c b/src/basic/process-util.c index 0213f5913f..dd913bc323 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -8,7 +8,6 @@ #include <stdbool.h> #include <stdio.h> #include <stdlib.h> -#include <sys/mman.h> #include <sys/mount.h> #include <sys/personality.h> #include <sys/prctl.h> @@ -22,12 +21,15 @@ #include "alloc-util.h" #include "architecture.h" +#include "argv-util.h" +#include "env-file.h" #include "env-util.h" #include "errno-util.h" #include "escape.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" +#include "hostname-util.h" #include "locale-util.h" #include "log.h" #include "macro.h" @@ -35,6 +37,7 @@ #include "missing_sched.h" #include "missing_syscall.h" #include "namespace-util.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "raw-clone.h" @@ -253,149 +256,45 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags return 0; } -static int update_argv(const char name[], size_t l) { - static int can_do = -1; - - if (can_do == 0) - return 0; - can_do = false; /* We'll set it to true only if the whole process works */ - - /* Let's not bother with this if we don't have euid == 0. Strictly speaking we should check for the - * CAP_SYS_RESOURCE capability which is independent of the euid. In our own code the capability generally is - * present only for euid == 0, hence let's use this as quick bypass check, to avoid calling mmap() if - * PR_SET_MM_ARG_{START,END} fails with EPERM later on anyway. After all geteuid() is dead cheap to call, but - * mmap() is not. */ - if (geteuid() != 0) - return log_debug_errno(SYNTHETIC_ERRNO(EPERM), - "Skipping PR_SET_MM, as we don't have privileges."); - - static size_t mm_size = 0; - static char *mm = NULL; +int container_get_leader(const char *machine, pid_t *pid) { + _cleanup_free_ char *s = NULL, *class = NULL; + const char *p; + pid_t leader; int r; - if (mm_size < l+1) { - size_t nn_size; - char *nn; - - nn_size = PAGE_ALIGN(l+1); - nn = mmap(NULL, nn_size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); - if (nn == MAP_FAILED) - return log_debug_errno(errno, "mmap() failed: %m"); - - strncpy(nn, name, nn_size); - - /* Now, let's tell the kernel about this new memory */ - if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, (unsigned long) nn, 0, 0) < 0) { - if (ERRNO_IS_PRIVILEGE(errno)) - return log_debug_errno(errno, "PR_SET_MM_ARG_START failed: %m"); - - /* HACK: prctl() API is kind of dumb on this point. The existing end address may already be - * below the desired start address, in which case the kernel may have kicked this back due - * to a range-check failure (see linux/kernel/sys.c:validate_prctl_map() to see this in - * action). The proper solution would be to have a prctl() API that could set both start+end - * simultaneously, or at least let us query the existing address to anticipate this condition - * and respond accordingly. For now, we can only guess at the cause of this failure and try - * a workaround--which will briefly expand the arg space to something potentially huge before - * resizing it to what we want. */ - log_debug_errno(errno, "PR_SET_MM_ARG_START failed, attempting PR_SET_MM_ARG_END hack: %m"); - - if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, (unsigned long) nn + l + 1, 0, 0) < 0) { - r = log_debug_errno(errno, "PR_SET_MM_ARG_END hack failed, proceeding without: %m"); - (void) munmap(nn, nn_size); - return r; - } + assert(machine); + assert(pid); - if (prctl(PR_SET_MM, PR_SET_MM_ARG_START, (unsigned long) nn, 0, 0) < 0) - return log_debug_errno(errno, "PR_SET_MM_ARG_START still failed, proceeding without: %m"); - } else { - /* And update the end pointer to the new end, too. If this fails, we don't really know what - * to do, it's pretty unlikely that we can rollback, hence we'll just accept the failure, - * and continue. */ - if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, (unsigned long) nn + l + 1, 0, 0) < 0) - log_debug_errno(errno, "PR_SET_MM_ARG_END failed, proceeding without: %m"); - } - - if (mm) - (void) munmap(mm, mm_size); - - mm = nn; - mm_size = nn_size; - } else { - strncpy(mm, name, mm_size); - - /* Update the end pointer, continuing regardless of any failure. */ - if (prctl(PR_SET_MM, PR_SET_MM_ARG_END, (unsigned long) mm + l + 1, 0, 0) < 0) - log_debug_errno(errno, "PR_SET_MM_ARG_END failed, proceeding without: %m"); + if (streq(machine, ".host")) { + *pid = 1; + return 0; } - can_do = true; - return 0; -} - -int rename_process(const char name[]) { - bool truncated = false; - - /* This is a like a poor man's setproctitle(). It changes the comm field, argv[0], and also the glibc's - * internally used name of the process. For the first one a limit of 16 chars applies; to the second one in - * many cases one of 10 (i.e. length of "/sbin/init") — however if we have CAP_SYS_RESOURCES it is unbounded; - * to the third one 7 (i.e. the length of "systemd". If you pass a longer string it will likely be - * truncated. - * - * Returns 0 if a name was set but truncated, > 0 if it was set but not truncated. */ - - if (isempty(name)) - return -EINVAL; /* let's not confuse users unnecessarily with an empty name */ - - if (!is_main_thread()) - return -EPERM; /* Let's not allow setting the process name from other threads than the main one, as we - * cache things without locking, and we make assumptions that PR_SET_NAME sets the - * process name that isn't correct on any other threads */ - - size_t l = strlen(name); - - /* First step, change the comm field. The main thread's comm is identical to the process comm. This means we - * can use PR_SET_NAME, which sets the thread name for the calling thread. */ - if (prctl(PR_SET_NAME, name) < 0) - log_debug_errno(errno, "PR_SET_NAME failed: %m"); - if (l >= TASK_COMM_LEN) /* Linux userspace process names can be 15 chars at max */ - truncated = true; - - /* Second step, change glibc's ID of the process name. */ - if (program_invocation_name) { - size_t k; - - k = strlen(program_invocation_name); - strncpy(program_invocation_name, name, k); - if (l > k) - truncated = true; - } + if (!hostname_is_valid(machine, 0)) + return -EINVAL; - /* Third step, completely replace the argv[] array the kernel maintains for us. This requires privileges, but - * has the advantage that the argv[] array is exactly what we want it to be, and not filled up with zeros at - * the end. This is the best option for changing /proc/self/cmdline. */ - (void) update_argv(name, l); - - /* Fourth step: in all cases we'll also update the original argv[], so that our own code gets it right too if - * it still looks here */ - if (saved_argc > 0) { - if (saved_argv[0]) { - size_t k; - - k = strlen(saved_argv[0]); - strncpy(saved_argv[0], name, k); - if (l > k) - truncated = true; - } + p = strjoina("/run/systemd/machines/", machine); + r = parse_env_file(NULL, p, + "LEADER", &s, + "CLASS", &class); + if (r == -ENOENT) + return -EHOSTDOWN; + if (r < 0) + return r; + if (!s) + return -EIO; - for (int i = 1; i < saved_argc; i++) { - if (!saved_argv[i]) - break; + if (!streq_ptr(class, "container")) + return -EIO; - memzero(saved_argv[i], strlen(saved_argv[i])); - } - } + r = parse_pid(s, &leader); + if (r < 0) + return r; + if (leader <= 1) + return -EIO; - return !truncated; + *pid = leader; + return 0; } int is_kernel_thread(pid_t pid) { @@ -1583,40 +1482,6 @@ int setpriority_closest(int priority) { return 0; } -bool invoked_as(char *argv[], const char *token) { - if (!argv || isempty(argv[0])) - return false; - - if (isempty(token)) - return false; - - return strstr(last_path_component(argv[0]), token); -} - -bool invoked_by_systemd(void) { - int r; - - /* If the process is directly executed by PID1 (e.g. ExecStart= or generator), systemd-importd, - * or systemd-homed, then $SYSTEMD_EXEC_PID= is set, and read the command line. */ - const char *e = getenv("SYSTEMD_EXEC_PID"); - if (!e) - return false; - - if (streq(e, "*")) - /* For testing. */ - return true; - - pid_t p; - r = parse_pid(e, &p); - if (r < 0) { - /* We know that systemd sets the variable correctly. Something else must have set it. */ - log_debug_errno(r, "Failed to parse \"SYSTEMD_EXEC_PID=%s\", ignoring: %m", e); - return false; - } - - return getpid_cached() == p; -} - _noreturn_ void freeze(void) { log_close(); @@ -1638,31 +1503,6 @@ _noreturn_ void freeze(void) { pause(); } -bool argv_looks_like_help(int argc, char **argv) { - char **l; - - /* Scans the command line for indications the user asks for help. This is supposed to be called by - * tools that do not implement getopt() style command line parsing because they are not primarily - * user-facing. Detects four ways of asking for help: - * - * 1. Passing zero arguments - * 2. Passing "help" as first argument - * 3. Passing --help as any argument - * 4. Passing -h as any argument - */ - - if (argc <= 1) - return true; - - if (streq_ptr(argv[1], "help")) - return true; - - l = strv_skip(argv, 1); - - return strv_contains(l, "--help") || - strv_contains(l, "-h"); -} - static const char *const sigchld_code_table[] = { [CLD_EXITED] = "exited", [CLD_KILLED] = "killed", diff --git a/src/basic/process-util.h b/src/basic/process-util.h index ed2f73673e..83663670ac 100644 --- a/src/basic/process-util.h +++ b/src/basic/process-util.h @@ -50,6 +50,8 @@ int get_process_environ(pid_t pid, char **ret); int get_process_ppid(pid_t pid, pid_t *ret); int get_process_umask(pid_t pid, mode_t *ret); +int container_get_leader(const char *machine, pid_t *pid); + int wait_for_terminate(pid_t pid, siginfo_t *status); typedef enum WaitFlags { @@ -69,7 +71,6 @@ void sigterm_wait(pid_t pid); int kill_and_sigcont(pid_t pid, int sig); -int rename_process(const char name[]); int is_kernel_thread(pid_t pid); int getenv_for_pid(pid_t pid, const char *field, char **_value); @@ -189,10 +190,4 @@ int pidfd_get_pid(int fd, pid_t *ret); int setpriority_closest(int priority); -bool invoked_as(char *argv[], const char *token); - -bool invoked_by_systemd(void); - _noreturn_ void freeze(void); - -bool argv_looks_like_help(int argc, char **argv); diff --git a/src/basic/procfs-util.c b/src/basic/procfs-util.c index 4f607307b6..bcba5a5208 100644 --- a/src/basic/procfs-util.c +++ b/src/basic/procfs-util.c @@ -4,7 +4,7 @@ #include <unistd.h> #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "fd-util.h" #include "fileio.h" #include "parse-util.h" diff --git a/src/basic/raw-clone.h b/src/basic/raw-clone.h index becf42e70b..a3b768f826 100644 --- a/src/basic/raw-clone.h +++ b/src/basic/raw-clone.h @@ -11,6 +11,7 @@ #include "log.h" #include "macro.h" +#include "process-util.h" /** * raw_clone() - uses clone to create a new process with clone flags diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 17d35fe1a4..5e3a92c7c0 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -18,7 +18,6 @@ #include "strv.h" #include "terminal-util.h" #include "utf8.h" -#include "util.h" char* first_word(const char *s, const char *word) { size_t sl, wl; diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 0c092597eb..8fa9986a76 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -21,7 +21,7 @@ #include <unistd.h> #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "devnum-util.h" #include "env-util.h" #include "fd-util.h" @@ -44,7 +44,6 @@ #include "terminal-util.h" #include "time-util.h" #include "user-util.h" -#include "util.h" static volatile unsigned cached_columns = 0; static volatile unsigned cached_lines = 0; diff --git a/src/basic/unit-file.c b/src/basic/unit-file.c index c81c69db30..1334365c2f 100644 --- a/src/basic/unit-file.c +++ b/src/basic/unit-file.c @@ -6,6 +6,7 @@ #include "dirent-util.h" #include "fd-util.h" #include "fs-util.h" +#include "initrd-util.h" #include "macro.h" #include "path-lookup.h" #include "set.h" diff --git a/src/binfmt/binfmt.c b/src/binfmt/binfmt.c index 71cb56aa4a..ba209a8d47 100644 --- a/src/binfmt/binfmt.c +++ b/src/binfmt/binfmt.c @@ -11,8 +11,9 @@ #include "alloc-util.h" #include "binfmt-util.h" +#include "build.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "fd-util.h" #include "fileio.h" #include "log.h" diff --git a/src/boot/bless-boot-generator.c b/src/boot/bless-boot-generator.c index 6adef5b3dc..5120b9622e 100644 --- a/src/boot/bless-boot-generator.c +++ b/src/boot/bless-boot-generator.c @@ -5,6 +5,7 @@ #include "efi-loader.h" #include "generator.h" +#include "initrd-util.h" #include "log.h" #include "mkdir.h" #include "special.h" diff --git a/src/boot/bless-boot.c b/src/boot/bless-boot.c index 554a716d8a..b2dd60f8ad 100644 --- a/src/boot/bless-boot.c +++ b/src/boot/bless-boot.c @@ -5,6 +5,7 @@ #include "alloc-util.h" #include "bootspec.h" +#include "build.h" #include "devnum-util.h" #include "efi-api.h" #include "efi-loader.h" @@ -19,7 +20,6 @@ #include "pretty-print.h" #include "sync-util.h" #include "terminal-util.h" -#include "util.h" #include "verbs.h" #include "virt.h" diff --git a/src/boot/boot-check-no-failures.c b/src/boot/boot-check-no-failures.c index 78642063c4..4ff91cb906 100644 --- a/src/boot/boot-check-no-failures.c +++ b/src/boot/boot-check-no-failures.c @@ -8,12 +8,12 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "log.h" #include "main-func.h" #include "pretty-print.h" #include "terminal-util.h" -#include "util.h" static int help(void) { _cleanup_free_ char *link = NULL; diff --git a/src/boot/bootctl.c b/src/boot/bootctl.c index b53df11764..79b2676537 100644 --- a/src/boot/bootctl.c +++ b/src/boot/bootctl.c @@ -15,6 +15,7 @@ #include "alloc-util.h" #include "blkid-util.h" #include "bootspec.h" +#include "build.h" #include "chase-symlinks.h" #include "copy.h" #include "devnum-util.h" @@ -53,7 +54,6 @@ #include "tpm2-util.h" #include "umask-util.h" #include "utf8.h" -#include "util.h" #include "verbs.h" #include "virt.h" diff --git a/src/boot/measure.c b/src/boot/measure.c index 4f16acedf0..b9cd2853b6 100644 --- a/src/boot/measure.c +++ b/src/boot/measure.c @@ -4,6 +4,7 @@ #include <unistd.h> #include "alloc-util.h" +#include "build.h" #include "efi-loader.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/boot/pcrphase.c b/src/boot/pcrphase.c index 267f66767c..a77a85fb2e 100644 --- a/src/boot/pcrphase.c +++ b/src/boot/pcrphase.c @@ -4,6 +4,7 @@ #include <sd-messages.h> +#include "build.h" #include "efivars.h" #include "main-func.h" #include "openssl-util.h" diff --git a/src/busctl/busctl-introspect.c b/src/busctl/busctl-introspect.c index 6002af5b2a..a248205f3f 100644 --- a/src/busctl/busctl-introspect.c +++ b/src/busctl/busctl-introspect.c @@ -6,7 +6,6 @@ #include "busctl-introspect.h" #include "path-util.h" #include "string-util.h" -#include "util.h" #include "xml.h" #define NODE_DEPTH_MAX 16 diff --git a/src/busctl/busctl.c b/src/busctl/busctl.c index f57a5d605d..32c6ed7cac 100644 --- a/src/busctl/busctl.c +++ b/src/busctl/busctl.c @@ -5,6 +5,7 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-dump.h" #include "bus-internal.h" #include "bus-message.h" diff --git a/src/cgls/cgls.c b/src/cgls/cgls.c index 6af95204e3..a6ec6326f3 100644 --- a/src/cgls/cgls.c +++ b/src/cgls/cgls.c @@ -8,6 +8,7 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-util.h" #include "cgroup-show.h" #include "cgroup-util.h" @@ -21,7 +22,6 @@ #include "pretty-print.h" #include "strv.h" #include "unit-name.h" -#include "util.h" static PagerFlags arg_pager_flags = 0; static OutputFlags arg_output_flags = OUTPUT_CGROUP_XATTRS | OUTPUT_CGROUP_ID; diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c index 95c3987525..cf51024dcb 100644 --- a/src/cgtop/cgtop.c +++ b/src/cgtop/cgtop.c @@ -10,6 +10,7 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "bus-util.h" #include "cgroup-show.h" diff --git a/src/core/audit-fd.c b/src/core/audit-fd.c index 097bea39b3..872280f798 100644 --- a/src/core/audit-fd.c +++ b/src/core/audit-fd.c @@ -12,7 +12,6 @@ #include "capability-util.h" #include "fd-util.h" #include "log.h" -#include "util.h" static bool initialized = false; static int audit_fd; diff --git a/src/core/bpf-util.c b/src/core/bpf-util.c index 84170da0a8..6fe229e32d 100644 --- a/src/core/bpf-util.c +++ b/src/core/bpf-util.c @@ -3,6 +3,7 @@ #include "bpf-dlopen.h" #include "bpf-util.h" #include "cgroup-util.h" +#include "initrd-util.h" #include "log.h" bool cgroup_bpf_supported(void) { diff --git a/src/core/execute.c b/src/core/execute.c index b5b7de6d2a..8e70ecab82 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -39,6 +39,7 @@ #if HAVE_APPARMOR #include "apparmor-util.h" #endif +#include "argv-util.h" #include "async.h" #include "barrier.h" #include "bpf-lsm.h" @@ -47,10 +48,10 @@ #include "cgroup-setup.h" #include "chase-symlinks.h" #include "chown-recursive.h" +#include "constants.h" #include "cpu-set-util.h" #include "creds-util.h" #include "data-fd-util.h" -#include "def.h" #include "env-file.h" #include "env-util.h" #include "errno-list.h" diff --git a/src/core/import-creds.c b/src/core/import-creds.c index 4685e43f47..1f2017ee5a 100644 --- a/src/core/import-creds.c +++ b/src/core/import-creds.c @@ -9,6 +9,7 @@ #include "format-util.h" #include "fs-util.h" #include "hexdecoct.h" +#include "initrd-util.h" #include "import-creds.h" #include "io-util.h" #include "mkdir-label.h" diff --git a/src/core/kill.c b/src/core/kill.c index e858ae9607..c8b581d05d 100644 --- a/src/core/kill.c +++ b/src/core/kill.c @@ -3,7 +3,6 @@ #include "kill.h" #include "signal-util.h" #include "string-table.h" -#include "util.h" void kill_context_init(KillContext *c) { assert(c); diff --git a/src/core/main.c b/src/core/main.c index 14a4f81452..cc725e6c42 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -22,6 +22,7 @@ #include "alloc-util.h" #include "apparmor-setup.h" #include "architecture.h" +#include "argv-util.h" #if HAVE_LIBBPF #include "bpf-lsm.h" #endif @@ -36,7 +37,7 @@ #include "crash-handler.h" #include "dbus-manager.h" #include "dbus.h" -#include "def.h" +#include "constants.h" #include "dev-setup.h" #include "efi-random.h" #include "efivars.h" @@ -52,6 +53,7 @@ #include "hostname-setup.h" #include "ima-setup.h" #include "import-creds.h" +#include "initrd-util.h" #include "killall.h" #include "kmod-setup.h" #include "limits-util.h" @@ -92,7 +94,6 @@ #include "time-util.h" #include "umask-util.h" #include "user-util.h" -#include "util.h" #include "virt.h" #include "watchdog.h" diff --git a/src/core/manager-serialize.c b/src/core/manager-serialize.c index 27cb0925ae..dd16d17afa 100644 --- a/src/core/manager-serialize.c +++ b/src/core/manager-serialize.c @@ -6,6 +6,7 @@ #include "fd-util.h" #include "fileio.h" #include "format-util.h" +#include "initrd-util.h" #include "macro.h" #include "manager-serialize.h" #include "manager.h" diff --git a/src/core/manager.c b/src/core/manager.c index a59afafb58..ffaa9fa595 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -30,13 +30,13 @@ #include "bus-util.h" #include "clean-ipc.h" #include "clock-util.h" +#include "constants.h" #include "core-varlink.h" #include "creds-util.h" #include "dbus-job.h" #include "dbus-manager.h" #include "dbus-unit.h" #include "dbus.h" -#include "def.h" #include "dirent-util.h" #include "env-util.h" #include "escape.h" @@ -48,6 +48,7 @@ #include "fileio.h" #include "generator-setup.h" #include "hashmap.h" +#include "initrd-util.h" #include "inotify-util.h" #include "install.h" #include "io-util.h" diff --git a/src/core/mount.c b/src/core/mount.c index 5e8a6ead61..be46e56689 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -14,6 +14,7 @@ #include "exit-status.h" #include "format-util.h" #include "fstab-util.h" +#include "initrd-util.h" #include "libmount-util.h" #include "log.h" #include "manager.h" diff --git a/src/core/selinux-access.c b/src/core/selinux-access.c index c1744cff92..e05ebdc631 100644 --- a/src/core/selinux-access.c +++ b/src/core/selinux-access.c @@ -23,7 +23,6 @@ #include "selinux-util.h" #include "stdio-util.h" #include "strv.h" -#include "util.h" static bool initialized = false; diff --git a/src/core/selinux-setup.c b/src/core/selinux-setup.c index 3f873baa91..153322442c 100644 --- a/src/core/selinux-setup.c +++ b/src/core/selinux-setup.c @@ -8,13 +8,13 @@ #include <selinux/selinux.h> #endif +#include "initrd-util.h" #include "log.h" #include "macro.h" #include "selinux-setup.h" #include "selinux-util.h" #include "string-util.h" #include "time-util.h" -#include "util.h" #if HAVE_SELINUX _printf_(2,3) diff --git a/src/core/service.c b/src/core/service.c index 42de40e137..2c734eb096 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -13,9 +13,9 @@ #include "bus-kernel.h" #include "bus-util.h" #include "chase-symlinks.h" +#include "constants.h" #include "dbus-service.h" #include "dbus-unit.h" -#include "def.h" #include "env-util.h" #include "escape.h" #include "exit-status.h" @@ -41,7 +41,6 @@ #include "unit-name.h" #include "unit.h" #include "utf8.h" -#include "util.h" #define service_spawn(...) service_spawn_internal(__func__, __VA_ARGS__) diff --git a/src/core/show-status.c b/src/core/show-status.c index df25429938..2ba7a8588d 100644 --- a/src/core/show-status.c +++ b/src/core/show-status.c @@ -12,7 +12,6 @@ #include "string-table.h" #include "string-util.h" #include "terminal-util.h" -#include "util.h" static const char* const show_status_table[_SHOW_STATUS_MAX] = { [SHOW_STATUS_NO] = "no", diff --git a/src/core/smack-setup.c b/src/core/smack-setup.c index b76bb74465..58552f79e7 100644 --- a/src/core/smack-setup.c +++ b/src/core/smack-setup.c @@ -19,7 +19,6 @@ #include "macro.h" #include "smack-setup.h" #include "string-util.h" -#include "util.h" #if ENABLE_SMACK diff --git a/src/core/socket.c b/src/core/socket.c index 2a8aa54f7f..55847c2f7c 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -15,10 +15,10 @@ #include "bus-error.h" #include "bus-util.h" #include "chase-symlinks.h" +#include "constants.h" #include "copy.h" #include "dbus-socket.h" #include "dbus-unit.h" -#include "def.h" #include "errno-list.h" #include "exit-status.h" #include "fd-util.h" diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index 98e7492811..50220c5ec7 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -20,6 +20,7 @@ #include "compress.h" #include "conf-parser.h" #include "copy.h" +#include "coredump-util.h" #include "coredump-vacuum.h" #include "dirent-util.h" #include "elf-util.h" diff --git a/src/coredump/coredumpctl.c b/src/coredump/coredumpctl.c index 30ea08702e..a6abcc6496 100644 --- a/src/coredump/coredumpctl.c +++ b/src/coredump/coredumpctl.c @@ -11,12 +11,13 @@ #include "sd-messages.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-util.h" #include "chase-symlinks.h" #include "compress.h" -#include "def.h" +#include "constants.h" #include "dissect-image.h" #include "fd-util.h" #include "format-table.h" @@ -42,7 +43,6 @@ #include "terminal-util.h" #include "tmpfile-util.h" #include "user-util.h" -#include "util.h" #include "verbs.h" #define SHORT_BUS_CALL_TIMEOUT_USEC (3 * USEC_PER_SEC) diff --git a/src/creds/creds.c b/src/creds/creds.c index a755a52c34..3c86b10aab 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -3,6 +3,7 @@ #include <getopt.h> #include <unistd.h> +#include "build.h" #include "creds-util.h" #include "dirent-util.h" #include "escape.h" diff --git a/src/cryptenroll/cryptenroll.c b/src/cryptenroll/cryptenroll.c index 6a9170f000..dbf6cf45af 100644 --- a/src/cryptenroll/cryptenroll.c +++ b/src/cryptenroll/cryptenroll.c @@ -3,6 +3,7 @@ #include <getopt.h> #include "ask-password-api.h" +#include "build.h" #include "cryptenroll-fido2.h" #include "cryptenroll-list.h" #include "cryptenroll-password.h" diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c index 07903f1044..083878e42a 100644 --- a/src/cryptsetup/cryptsetup-generator.c +++ b/src/cryptsetup/cryptsetup-generator.c @@ -23,7 +23,6 @@ #include "string-util.h" #include "strv.h" #include "unit-name.h" -#include "util.h" typedef struct crypto_device { char *uuid; diff --git a/src/debug-generator/debug-generator.c b/src/debug-generator/debug-generator.c index cf638fcc56..1fe2b56810 100644 --- a/src/debug-generator/debug-generator.c +++ b/src/debug-generator/debug-generator.c @@ -5,6 +5,7 @@ #include "alloc-util.h" #include "dropin.h" #include "generator.h" +#include "initrd-util.h" #include "mkdir-label.h" #include "parse-util.h" #include "path-util.h" diff --git a/src/delta/delta.c b/src/delta/delta.c index a08d35e43c..da648bc837 100644 --- a/src/delta/delta.c +++ b/src/delta/delta.c @@ -6,6 +6,7 @@ #include <unistd.h> #include "alloc-util.h" +#include "build.h" #include "chase-symlinks.h" #include "dirent-util.h" #include "fd-util.h" diff --git a/src/detect-virt/detect-virt.c b/src/detect-virt/detect-virt.c index af2a58b78d..b75e3c34ca 100644 --- a/src/detect-virt/detect-virt.c +++ b/src/detect-virt/detect-virt.c @@ -6,10 +6,10 @@ #include <stdlib.h> #include "alloc-util.h" +#include "build.h" #include "main-func.h" #include "pretty-print.h" #include "string-table.h" -#include "util.h" #include "virt.h" static bool arg_quiet = false; diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index 7014e9ad86..668534a663 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -12,6 +12,7 @@ #include "architecture.h" #include "blockdev-util.h" +#include "build.h" #include "chase-symlinks.h" #include "copy.h" #include "device-util.h" @@ -42,7 +43,6 @@ #include "terminal-util.h" #include "tmpfile-util.h" #include "user-util.h" -#include "util.h" static enum { ACTION_DISSECT, diff --git a/src/environment-d-generator/environment-d-generator.c b/src/environment-d-generator/environment-d-generator.c index e3fea1f2b0..90e31c98ef 100644 --- a/src/environment-d-generator/environment-d-generator.c +++ b/src/environment-d-generator/environment-d-generator.c @@ -3,7 +3,7 @@ #include "sd-path.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "env-file.h" #include "escape.h" #include "glyph-util.h" diff --git a/src/escape/escape.c b/src/escape/escape.c index 0ad77f3f94..abbc08b37f 100644 --- a/src/escape/escape.c +++ b/src/escape/escape.c @@ -5,6 +5,7 @@ #include <stdlib.h> #include "alloc-util.h" +#include "build.h" #include "log.h" #include "main-func.h" #include "path-util.h" diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c index 63db78b52d..7cd9aed579 100644 --- a/src/firstboot/firstboot.c +++ b/src/firstboot/firstboot.c @@ -9,6 +9,7 @@ #include "alloc-util.h" #include "ask-password-api.h" +#include "build.h" #include "chase-symlinks.h" #include "copy.h" #include "creds-util.h" diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c index 595434ab57..73c76fceea 100644 --- a/src/fsck/fsck.c +++ b/src/fsck/fsck.c @@ -32,7 +32,6 @@ #include "socket-util.h" #include "special.h" #include "stdio-util.h" -#include "util.h" static bool arg_skip = false; static bool arg_force = false; diff --git a/src/fstab-generator/fstab-generator.c b/src/fstab-generator/fstab-generator.c index e76de45a0f..872e01f58f 100644 --- a/src/fstab-generator/fstab-generator.c +++ b/src/fstab-generator/fstab-generator.c @@ -13,6 +13,7 @@ #include "fstab-util.h" #include "generator.h" #include "in-addr-util.h" +#include "initrd-util.h" #include "log.h" #include "main-func.h" #include "mkdir.h" @@ -29,7 +30,6 @@ #include "string-util.h" #include "strv.h" #include "unit-name.h" -#include "util.h" #include "virt.h" #include "volatile-util.h" diff --git a/src/fuzz/fuzz-time-util.c b/src/fuzz/fuzz-time-util.c index bf2a66336c..f1c95ae09b 100644 --- a/src/fuzz/fuzz-time-util.c +++ b/src/fuzz/fuzz-time-util.c @@ -4,7 +4,6 @@ #include "fd-util.h" #include "fuzz.h" #include "time-util.h" -#include "util.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { _cleanup_free_ char *str = NULL; diff --git a/src/getty-generator/getty-generator.c b/src/getty-generator/getty-generator.c index 4e8162a319..b3f5ddc586 100644 --- a/src/getty-generator/getty-generator.c +++ b/src/getty-generator/getty-generator.c @@ -18,7 +18,6 @@ #include "strv.h" #include "terminal-util.h" #include "unit-name.h" -#include "util.h" #include "virt.h" static const char *arg_dest = NULL; diff --git a/src/gpt-auto-generator/gpt-auto-generator.c b/src/gpt-auto-generator/gpt-auto-generator.c index 0fb53bb9ea..f939b2e8c2 100644 --- a/src/gpt-auto-generator/gpt-auto-generator.c +++ b/src/gpt-auto-generator/gpt-auto-generator.c @@ -23,6 +23,7 @@ #include "fstab-util.h" #include "generator.h" #include "gpt.h" +#include "initrd-util.h" #include "mkdir.h" #include "mountpoint-util.h" #include "parse-util.h" @@ -34,7 +35,6 @@ #include "string-util.h" #include "strv.h" #include "unit-name.h" -#include "util.h" #include "virt.h" static const char *arg_dest = NULL; diff --git a/src/hibernate-resume/hibernate-resume-generator.c b/src/hibernate-resume/hibernate-resume-generator.c index 82c2a56493..be52c21d00 100644 --- a/src/hibernate-resume/hibernate-resume-generator.c +++ b/src/hibernate-resume/hibernate-resume-generator.c @@ -8,6 +8,7 @@ #include "dropin.h" #include "fstab-util.h" #include "generator.h" +#include "initrd-util.h" #include "log.h" #include "main-func.h" #include "mkdir-label.h" diff --git a/src/hibernate-resume/hibernate-resume.c b/src/hibernate-resume/hibernate-resume.c index 1c7d9179d8..9a9df5d22f 100644 --- a/src/hibernate-resume/hibernate-resume.c +++ b/src/hibernate-resume/hibernate-resume.c @@ -7,8 +7,8 @@ #include "alloc-util.h" #include "devnum-util.h" #include "fileio.h" +#include "initrd-util.h" #include "log.h" -#include "util.h" int main(int argc, char *argv[]) { struct stat st; diff --git a/src/home/homectl.c b/src/home/homectl.c index 87a1c6883f..3e846e370a 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -5,6 +5,7 @@ #include "sd-bus.h" #include "ask-password-api.h" +#include "build.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-locator.h" diff --git a/src/home/homed-conf.c b/src/home/homed-conf.c index 296e01449d..429a6e3c55 100644 --- a/src/home/homed-conf.c +++ b/src/home/homed-conf.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "home-util.h" #include "homed-conf.h" diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index bb014973fb..826826d70b 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -11,6 +11,7 @@ #include "alloc-util.h" #include "architecture.h" +#include "build.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-map-properties.h" @@ -23,7 +24,6 @@ #include "pretty-print.h" #include "spawn-polkit-agent.h" #include "terminal-util.h" -#include "util.h" #include "verbs.h" static bool arg_ask_password = true; diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index 486b093062..f3d3131828 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -11,7 +11,7 @@ #include "bus-get-properties.h" #include "bus-log-control-api.h" #include "bus-polkit.h" -#include "def.h" +#include "constants.h" #include "env-file-label.h" #include "env-file.h" #include "env-util.h" @@ -36,7 +36,6 @@ #include "string-table.h" #include "strv.h" #include "user-util.h" -#include "util.h" #include "virt.h" #define VALID_DEPLOYMENT_CHARS (DIGITS LETTERS "-.:") diff --git a/src/hwdb/hwdb.c b/src/hwdb/hwdb.c index 6925aecd84..edc5dfc1f5 100644 --- a/src/hwdb/hwdb.c +++ b/src/hwdb/hwdb.c @@ -5,12 +5,12 @@ #include "sd-hwdb.h" #include "alloc-util.h" +#include "build.h" #include "hwdb-util.h" #include "main-func.h" #include "pretty-print.h" #include "selinux-util.h" #include "terminal-util.h" -#include "util.h" #include "verbs.h" static const char *arg_hwdb_bin_dir = NULL; diff --git a/src/id128/id128.c b/src/id128/id128.c index 6f4d65103c..af88e315bb 100644 --- a/src/id128/id128.c +++ b/src/id128/id128.c @@ -4,6 +4,7 @@ #include <stdio.h> #include "alloc-util.h" +#include "build.h" #include "gpt.h" #include "id128-print.h" #include "main-func.h" @@ -11,7 +12,6 @@ #include "strv.h" #include "format-table.h" #include "terminal-util.h" -#include "util.h" #include "verbs.h" static Id128PrettyPrintMode arg_mode = ID128_PRINT_ID128; diff --git a/src/import/export-raw.c b/src/import/export-raw.c index a3ff6a3934..6b15884e77 100644 --- a/src/import/export-raw.c +++ b/src/import/export-raw.c @@ -16,7 +16,6 @@ #include "stat-util.h" #include "string-util.h" #include "tmpfile-util.h" -#include "util.h" #define COPY_BUFFER_SIZE (16*1024) diff --git a/src/import/export-tar.c b/src/import/export-tar.c index 78f0a7ca75..b9953a4bf3 100644 --- a/src/import/export-tar.c +++ b/src/import/export-tar.c @@ -11,7 +11,6 @@ #include "ratelimit.h" #include "string-util.h" #include "tmpfile-util.h" -#include "util.h" #define COPY_BUFFER_SIZE (16*1024) diff --git a/src/import/export.c b/src/import/export.c index 26533baeb8..690e194453 100644 --- a/src/import/export.c +++ b/src/import/export.c @@ -7,6 +7,7 @@ #include "sd-id128.h" #include "alloc-util.h" +#include "build.h" #include "discover-image.h" #include "export-raw.h" #include "export-tar.h" diff --git a/src/import/import-common.c b/src/import/import-common.c index 4eda9087c5..3c46aedf61 100644 --- a/src/import/import-common.c +++ b/src/import/import-common.c @@ -21,7 +21,6 @@ #include "signal-util.h" #include "stat-util.h" #include "tmpfile-util.h" -#include "util.h" int import_fork_tar_x(const char *path, pid_t *ret) { _cleanup_close_pair_ int pipefd[2] = { -1, -1 }; diff --git a/src/import/import-compress.c b/src/import/import-compress.c index 03f5efa00e..28cf6f841a 100644 --- a/src/import/import-compress.c +++ b/src/import/import-compress.c @@ -2,7 +2,6 @@ #include "import-compress.h" #include "string-table.h" -#include "util.h" void import_compress_free(ImportCompress *c) { assert(c); diff --git a/src/import/import-fs.c b/src/import/import-fs.c index 1c5581fd61..4e7250c02e 100644 --- a/src/import/import-fs.c +++ b/src/import/import-fs.c @@ -4,6 +4,7 @@ #include <locale.h> #include "alloc-util.h" +#include "build.h" #include "btrfs-util.h" #include "discover-image.h" #include "fd-util.h" diff --git a/src/import/import-raw.c b/src/import/import-raw.c index 30f5b9050b..ee904bc4e0 100644 --- a/src/import/import-raw.c +++ b/src/import/import-raw.c @@ -25,7 +25,6 @@ #include "rm-rf.h" #include "string-util.h" #include "tmpfile-util.h" -#include "util.h" struct RawImport { sd_event *event; diff --git a/src/import/import-tar.c b/src/import/import-tar.c index f31d3d75a1..90b4e51d2c 100644 --- a/src/import/import-tar.c +++ b/src/import/import-tar.c @@ -26,7 +26,6 @@ #include "rm-rf.h" #include "string-util.h" #include "tmpfile-util.h" -#include "util.h" struct TarImport { sd_event *event; diff --git a/src/import/import.c b/src/import/import.c index c76212494b..13f34633d2 100644 --- a/src/import/import.c +++ b/src/import/import.c @@ -7,6 +7,7 @@ #include "sd-id128.h" #include "alloc-util.h" +#include "build.h" #include "discover-image.h" #include "env-util.h" #include "fd-util.h" diff --git a/src/import/importd.c b/src/import/importd.c index 74e8ffb0cf..9a3ea131c1 100644 --- a/src/import/importd.c +++ b/src/import/importd.c @@ -10,7 +10,7 @@ #include "bus-get-properties.h" #include "bus-log-control-api.h" #include "bus-polkit.h" -#include "def.h" +#include "constants.h" #include "env-util.h" #include "fd-util.h" #include "float.h" @@ -32,7 +32,6 @@ #include "strv.h" #include "syslog-util.h" #include "user-util.h" -#include "util.h" #include "web-util.h" typedef struct Transfer Transfer; diff --git a/src/import/pull-common.c b/src/import/pull-common.c index 028bae82a8..7633d3e74b 100644 --- a/src/import/pull-common.c +++ b/src/import/pull-common.c @@ -22,7 +22,6 @@ #include "siphash24.h" #include "string-util.h" #include "strv.h" -#include "util.h" #include "web-util.h" #define FILENAME_ESCAPE "/.#\"\'" diff --git a/src/import/pull-raw.c b/src/import/pull-raw.c index f4f869d38e..d3d14af6d1 100644 --- a/src/import/pull-raw.c +++ b/src/import/pull-raw.c @@ -28,7 +28,6 @@ #include "strv.h" #include "tmpfile-util.h" #include "utf8.h" -#include "util.h" #include "web-util.h" typedef enum RawProgress { diff --git a/src/import/pull-tar.c b/src/import/pull-tar.c index fd866fc514..cf18461db3 100644 --- a/src/import/pull-tar.c +++ b/src/import/pull-tar.c @@ -28,7 +28,6 @@ #include "tmpfile-util.h" #include "user-util.h" #include "utf8.h" -#include "util.h" #include "web-util.h" typedef enum TarProgress { diff --git a/src/import/pull.c b/src/import/pull.c index 2cf0cca14f..38821b5790 100644 --- a/src/import/pull.c +++ b/src/import/pull.c @@ -7,6 +7,7 @@ #include "sd-id128.h" #include "alloc-util.h" +#include "build.h" #include "discover-image.h" #include "env-util.h" #include "hexdecoct.h" diff --git a/src/import/qcow2-util.c b/src/import/qcow2-util.c index 5a7232d3ed..fe2b535087 100644 --- a/src/import/qcow2-util.c +++ b/src/import/qcow2-util.c @@ -6,7 +6,6 @@ #include "btrfs-util.h" #include "qcow2-util.h" #include "sparse-endian.h" -#include "util.h" #define QCOW2_MAGIC 0x514649fb diff --git a/src/initctl/initctl.c b/src/initctl/initctl.c index e1b85d5218..7484200065 100644 --- a/src/initctl/initctl.c +++ b/src/initctl/initctl.c @@ -14,8 +14,8 @@ #include "alloc-util.h" #include "bus-error.h" #include "bus-util.h" +#include "constants.h" #include "daemon-util.h" -#include "def.h" #include "fd-util.h" #include "format-util.h" #include "initreq.h" diff --git a/src/journal-remote/journal-gatewayd.c b/src/journal-remote/journal-gatewayd.c index 34def4670e..b3b44bceb8 100644 --- a/src/journal-remote/journal-gatewayd.c +++ b/src/journal-remote/journal-gatewayd.c @@ -14,6 +14,7 @@ #include "sd-journal.h" #include "alloc-util.h" +#include "build.h" #include "bus-util.h" #include "errno-util.h" #include "fd-util.h" @@ -30,7 +31,6 @@ #include "pretty-print.h" #include "sigbus.h" #include "tmpfile-util.h" -#include "util.h" #define JOURNAL_WAIT_TIMEOUT (10*USEC_PER_SEC) diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index 0088652184..440aad1cf7 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -5,9 +5,10 @@ #include "sd-daemon.h" +#include "build.h" #include "conf-parser.h" +#include "constants.h" #include "daemon-util.h" -#include "def.h" #include "fd-util.h" #include "fileio.h" #include "journal-remote-write.h" diff --git a/src/journal-remote/journal-remote.c b/src/journal-remote/journal-remote.c index e8fe04165e..3d7b552e95 100644 --- a/src/journal-remote/journal-remote.c +++ b/src/journal-remote/journal-remote.c @@ -10,7 +10,7 @@ #include "af-list.h" #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "errno-util.h" #include "escape.h" #include "fd-util.h" diff --git a/src/journal-remote/journal-upload-journal.c b/src/journal-remote/journal-upload-journal.c index 7a8f50dd0d..8206ca89bf 100644 --- a/src/journal-remote/journal-upload-journal.c +++ b/src/journal-remote/journal-upload-journal.c @@ -10,7 +10,6 @@ #include "log.h" #include "string-util.h" #include "utf8.h" -#include "util.h" /** * Write up to size bytes to buf. Return negative on error, and number of diff --git a/src/journal-remote/journal-upload.c b/src/journal-remote/journal-upload.c index 06448b2225..5a34b73f76 100644 --- a/src/journal-remote/journal-upload.c +++ b/src/journal-remote/journal-upload.c @@ -10,9 +10,10 @@ #include "sd-daemon.h" #include "alloc-util.h" +#include "build.h" #include "conf-parser.h" +#include "constants.h" #include "daemon-util.h" -#include "def.h" #include "env-file.h" #include "fd-util.h" #include "fileio.h" @@ -32,7 +33,6 @@ #include "string-util.h" #include "strv.h" #include "tmpfile-util.h" -#include "util.h" #include "version.h" #define PRIV_KEY_FILE CERTIFICATE_ROOT "/private/journal-upload.pem" diff --git a/src/journal-remote/microhttpd-util.c b/src/journal-remote/microhttpd-util.c index 271e304273..9e6c36f87d 100644 --- a/src/journal-remote/microhttpd-util.c +++ b/src/journal-remote/microhttpd-util.c @@ -14,7 +14,6 @@ #include "microhttpd-util.h" #include "string-util.h" #include "strv.h" -#include "util.h" void microhttpd_logger(void *arg, const char *fmt, va_list ap) { char *f; diff --git a/src/journal/cat.c b/src/journal/cat.c index 0c2c0d6152..404a748736 100644 --- a/src/journal/cat.c +++ b/src/journal/cat.c @@ -10,6 +10,7 @@ #include "sd-journal.h" #include "alloc-util.h" +#include "build.h" #include "fd-util.h" #include "main-func.h" #include "parse-argument.h" @@ -18,7 +19,6 @@ #include "string-util.h" #include "syslog-util.h" #include "terminal-util.h" -#include "util.h" static const char *arg_identifier = NULL; static int arg_priority = LOG_INFO; diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 11de07fcfa..eb8106cbb4 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -19,12 +19,13 @@ #include "acl-util.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "bus-util.h" #include "catalog.h" #include "chase-symlinks.h" #include "chattr-util.h" -#include "def.h" +#include "constants.h" #include "dissect-image.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/journal/journald-rate-limit.c b/src/journal/journald-rate-limit.c index 842882bc59..65fbe400a8 100644 --- a/src/journal/journald-rate-limit.c +++ b/src/journal/journald-rate-limit.c @@ -6,6 +6,7 @@ #include "hashmap.h" #include "journald-rate-limit.h" #include "list.h" +#include "logarithm.h" #include "random-util.h" #include "string-util.h" #include "time-util.h" diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 71d7a59bda..c02d73bdc2 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -27,6 +27,7 @@ #include "hashmap.h" #include "hostname-util.h" #include "id128-util.h" +#include "initrd-util.h" #include "io-util.h" #include "journal-authenticate.h" #include "journal-internal.h" diff --git a/src/journal/test-journal-interleaving.c b/src/journal/test-journal-interleaving.c index 378bf162ca..c5288000af 100644 --- a/src/journal/test-journal-interleaving.c +++ b/src/journal/test-journal-interleaving.c @@ -14,7 +14,6 @@ #include "parse-util.h" #include "rm-rf.h" #include "tests.h" -#include "util.h" /* This program tests skipping around in a multi-file journal. */ diff --git a/src/journal/test-journal-stream.c b/src/journal/test-journal-stream.c index ac5b7f0005..9f4494c6c0 100644 --- a/src/journal/test-journal-stream.c +++ b/src/journal/test-journal-stream.c @@ -15,7 +15,6 @@ #include "parse-util.h" #include "rm-rf.h" #include "tests.h" -#include "util.h" #define N_ENTRIES 200 diff --git a/src/journal/test-journal-verify.c b/src/journal/test-journal-verify.c index e36ea8cae1..0c58d05ced 100644 --- a/src/journal/test-journal-verify.c +++ b/src/journal/test-journal-verify.c @@ -14,7 +14,6 @@ #include "rm-rf.h" #include "terminal-util.h" #include "tests.h" -#include "util.h" #define N_ENTRIES 6000 #define RANDOM_RANGE 77 diff --git a/src/libsystemd-network/arp-util.c b/src/libsystemd-network/arp-util.c index 99a5f69b70..eec794a653 100644 --- a/src/libsystemd-network/arp-util.c +++ b/src/libsystemd-network/arp-util.c @@ -12,7 +12,6 @@ #include "fd-util.h" #include "in-addr-util.h" #include "unaligned.h" -#include "util.h" int arp_update_filter(int fd, const struct in_addr *a, const struct ether_addr *mac) { struct sock_filter filter[] = { diff --git a/src/libsystemd-network/dhcp-lease-internal.h b/src/libsystemd-network/dhcp-lease-internal.h index c67e9511a1..a660e52201 100644 --- a/src/libsystemd-network/dhcp-lease-internal.h +++ b/src/libsystemd-network/dhcp-lease-internal.h @@ -10,7 +10,6 @@ #include "dhcp-internal.h" #include "dhcp-protocol.h" #include "list.h" -#include "util.h" struct sd_dhcp_route { struct in_addr dst_addr; diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 4b0fac3cf1..a29279e6af 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -20,7 +20,6 @@ #include "siphash24.h" #include "sparse-endian.h" #include "string-util.h" -#include "util.h" #define IPV4LL_NETWORK UINT32_C(0xA9FE0000) #define IPV4LL_NETMASK UINT32_C(0xFFFF0000) diff --git a/src/libsystemd-network/test-acd.c b/src/libsystemd-network/test-acd.c index 73105f5a04..4b5ad70cf1 100644 --- a/src/libsystemd-network/test-acd.c +++ b/src/libsystemd-network/test-acd.c @@ -13,7 +13,6 @@ #include "in-addr-util.h" #include "tests.h" -#include "util.h" static void acd_handler(sd_ipv4acd *acd, int event, void *userdata) { assert_se(acd); diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c index 0f3a68e990..92b9b5b9bc 100644 --- a/src/libsystemd-network/test-dhcp-client.c +++ b/src/libsystemd-network/test-dhcp-client.c @@ -21,7 +21,6 @@ #include "fd-util.h" #include "random-util.h" #include "tests.h" -#include "util.h" static struct hw_addr_data hw_addr = { .length = ETH_ALEN, diff --git a/src/libsystemd-network/test-ipv4ll-manual.c b/src/libsystemd-network/test-ipv4ll-manual.c index 5453ef93a4..5dc6b10347 100644 --- a/src/libsystemd-network/test-ipv4ll-manual.c +++ b/src/libsystemd-network/test-ipv4ll-manual.c @@ -15,7 +15,6 @@ #include "parse-util.h" #include "string-util.h" #include "tests.h" -#include "util.h" static void ll_handler(sd_ipv4ll *ll, int event, void *userdata) { assert_se(ll); diff --git a/src/libsystemd-network/test-ipv4ll.c b/src/libsystemd-network/test-ipv4ll.c index 2a078a502e..bb42930cf5 100644 --- a/src/libsystemd-network/test-ipv4ll.c +++ b/src/libsystemd-network/test-ipv4ll.c @@ -16,7 +16,6 @@ #include "fd-util.h" #include "socket-util.h" #include "tests.h" -#include "util.h" static bool verbose = false; static bool extended = false; diff --git a/src/libsystemd/sd-bus/bus-container.c b/src/libsystemd/sd-bus/bus-container.c index b3c0279c0b..b9a38269d9 100644 --- a/src/libsystemd/sd-bus/bus-container.c +++ b/src/libsystemd/sd-bus/bus-container.c @@ -10,7 +10,6 @@ #include "namespace-util.h" #include "process-util.h" #include "string-util.h" -#include "util.h" int bus_container_connect_socket(sd_bus *b) { _cleanup_close_pair_ int pair[2] = { -1, -1 }; diff --git a/src/libsystemd/sd-bus/bus-creds.c b/src/libsystemd/sd-bus/bus-creds.c index 4468b45dd1..45e7473c29 100644 --- a/src/libsystemd/sd-bus/bus-creds.c +++ b/src/libsystemd/sd-bus/bus-creds.c @@ -21,7 +21,6 @@ #include "strv.h" #include "terminal-util.h" #include "user-util.h" -#include "util.h" enum { CAP_OFFSET_INHERITABLE = 0, diff --git a/src/libsystemd/sd-bus/bus-dump.c b/src/libsystemd/sd-bus/bus-dump.c index 73939d8f7a..6d24f3b1c9 100644 --- a/src/libsystemd/sd-bus/bus-dump.c +++ b/src/libsystemd/sd-bus/bus-dump.c @@ -17,7 +17,6 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" static char *indent(unsigned level, uint64_t flags) { char *p; diff --git a/src/libsystemd/sd-bus/bus-error.c b/src/libsystemd/sd-bus/bus-error.c index 4d687cfac9..413e2dd43f 100644 --- a/src/libsystemd/sd-bus/bus-error.c +++ b/src/libsystemd/sd-bus/bus-error.c @@ -14,7 +14,6 @@ #include "errno-util.h" #include "string-util.h" #include "strv.h" -#include "util.h" BUS_ERROR_MAP_ELF_REGISTER const sd_bus_error_map bus_standard_errors[] = { SD_BUS_ERROR_MAP("org.freedesktop.DBus.Error.Failed", EACCES), diff --git a/src/libsystemd/sd-bus/bus-internal.h b/src/libsystemd/sd-bus/bus-internal.h index 51673ad1c5..dda6adfd48 100644 --- a/src/libsystemd/sd-bus/bus-internal.h +++ b/src/libsystemd/sd-bus/bus-internal.h @@ -8,7 +8,7 @@ #include "bus-error.h" #include "bus-kernel.h" #include "bus-match.h" -#include "def.h" +#include "constants.h" #include "hashmap.h" #include "list.h" #include "prioq.h" diff --git a/src/libsystemd/sd-bus/bus-signature.c b/src/libsystemd/sd-bus/bus-signature.c index bd0842fdbc..78c743648b 100644 --- a/src/libsystemd/sd-bus/bus-signature.c +++ b/src/libsystemd/sd-bus/bus-signature.c @@ -1,7 +1,5 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ -#include <util.h> - #include "sd-bus.h" #include "bus-signature.h" diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c index 3803a2c4c4..7e72245e8d 100644 --- a/src/libsystemd/sd-bus/sd-bus.c +++ b/src/libsystemd/sd-bus/sd-bus.c @@ -27,7 +27,7 @@ #include "bus-track.h" #include "bus-type.h" #include "cgroup-util.h" -#include "def.h" +#include "constants.h" #include "errno-util.h" #include "fd-util.h" #include "glyph-util.h" diff --git a/src/libsystemd/sd-bus/test-bus-benchmark.c b/src/libsystemd/sd-bus/test-bus-benchmark.c index 317653bedc..7d7dc390dd 100644 --- a/src/libsystemd/sd-bus/test-bus-benchmark.c +++ b/src/libsystemd/sd-bus/test-bus-benchmark.c @@ -8,12 +8,11 @@ #include "alloc-util.h" #include "bus-internal.h" #include "bus-kernel.h" -#include "def.h" +#include "constants.h" #include "fd-util.h" #include "missing_resource.h" #include "string-util.h" #include "time-util.h" -#include "util.h" #define MAX_SIZE (2*1024*1024) diff --git a/src/libsystemd/sd-bus/test-bus-chat.c b/src/libsystemd/sd-bus/test-bus-chat.c index 09401a9784..9b5efcce59 100644 --- a/src/libsystemd/sd-bus/test-bus-chat.c +++ b/src/libsystemd/sd-bus/test-bus-chat.c @@ -18,7 +18,6 @@ #include "macro.h" #include "string-util.h" #include "tests.h" -#include "util.h" static int match_callback(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { log_info("Match triggered! destination=%s interface=%s member=%s", diff --git a/src/libsystemd/sd-bus/test-bus-marshal.c b/src/libsystemd/sd-bus/test-bus-marshal.c index e1afbc2f1b..3361b0675e 100644 --- a/src/libsystemd/sd-bus/test-bus-marshal.c +++ b/src/libsystemd/sd-bus/test-bus-marshal.c @@ -23,7 +23,6 @@ #include "fileio.h" #include "log.h" #include "tests.h" -#include "util.h" static void test_bus_path_encode_unique(void) { _cleanup_free_ char *a = NULL, *b = NULL, *c = NULL, *d = NULL, *e = NULL; diff --git a/src/libsystemd/sd-bus/test-bus-objects.c b/src/libsystemd/sd-bus/test-bus-objects.c index 949ef07c34..0d4a6db1e3 100644 --- a/src/libsystemd/sd-bus/test-bus-objects.c +++ b/src/libsystemd/sd-bus/test-bus-objects.c @@ -12,7 +12,6 @@ #include "log.h" #include "macro.h" #include "strv.h" -#include "util.h" struct context { int fds[2]; diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c index 199d10a00e..80206a7d91 100644 --- a/src/libsystemd/sd-daemon/sd-daemon.c +++ b/src/libsystemd/sd-daemon/sd-daemon.c @@ -26,7 +26,6 @@ #include "stat-util.h" #include "strv.h" #include "time-util.h" -#include "util.h" #define SNDBUF_SIZE (8*1024*1024) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c index f2e142457b..55a0ee730e 100644 --- a/src/libsystemd/sd-device/sd-device.c +++ b/src/libsystemd/sd-device/sd-device.c @@ -33,7 +33,6 @@ #include "strv.h" #include "strxcpyx.h" #include "user-util.h" -#include "util.h" int device_new_aux(sd_device **ret) { sd_device *device; diff --git a/src/libsystemd/sd-device/test-sd-device-monitor.c b/src/libsystemd/sd-device/test-sd-device-monitor.c index 9e64ba01c6..4654ef709d 100644 --- a/src/libsystemd/sd-device/test-sd-device-monitor.c +++ b/src/libsystemd/sd-device/test-sd-device-monitor.c @@ -14,7 +14,6 @@ #include "stat-util.h" #include "string-util.h" #include "tests.h" -#include "util.h" #include "virt.h" static int monitor_handler(sd_device_monitor *m, sd_device *d, void *userdata) { diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index eb7a37ce68..27908a9abc 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -16,6 +16,7 @@ #include "glyph-util.h" #include "hashmap.h" #include "list.h" +#include "logarithm.h" #include "macro.h" #include "memory-util.h" #include "missing_syscall.h" diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index 246658d024..9ec988d76e 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -21,7 +21,6 @@ #include "string-util.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" static int prepare_handler(sd_event_source *s, void *userdata) { log_info("preparing %c", PTR_TO_INT(userdata)); diff --git a/src/libsystemd/sd-hwdb/hwdb-internal.h b/src/libsystemd/sd-hwdb/hwdb-internal.h index 62d27f7b89..5302679a62 100644 --- a/src/libsystemd/sd-hwdb/hwdb-internal.h +++ b/src/libsystemd/sd-hwdb/hwdb-internal.h @@ -4,7 +4,7 @@ #include <stdint.h> #include <sys/stat.h> -#include "def.h" +#include "constants.h" #include "hashmap.h" #include "sparse-endian.h" diff --git a/src/libsystemd/sd-id128/sd-id128.c b/src/libsystemd/sd-id128/sd-id128.c index 709c8ffb57..c8f051196d 100644 --- a/src/libsystemd/sd-id128/sd-id128.c +++ b/src/libsystemd/sd-id128/sd-id128.c @@ -16,7 +16,6 @@ #include "missing_syscall.h" #include "random-util.h" #include "user-util.h" -#include "util.h" _public_ char *sd_id128_to_string(sd_id128_t id, char s[_SD_ARRAY_STATIC SD_ID128_STRING_MAX]) { assert_return(s, NULL); diff --git a/src/libsystemd/sd-journal/fsprg.h b/src/libsystemd/sd-journal/fsprg.h index dfe2d79222..d3d88aab31 100644 --- a/src/libsystemd/sd-journal/fsprg.h +++ b/src/libsystemd/sd-journal/fsprg.h @@ -26,7 +26,6 @@ #include <sys/types.h> #include "macro.h" -#include "util.h" #ifdef __cplusplus extern "C" { diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index c1ec6bb1d8..3f0dcaebf1 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -92,6 +92,19 @@ # pragma GCC diagnostic ignored "-Waddress-of-packed-member" #endif +static int mmap_prot_from_open_flags(int flags) { + switch (flags & O_ACCMODE) { + case O_RDONLY: + return PROT_READ; + case O_WRONLY: + return PROT_WRITE; + case O_RDWR: + return PROT_READ|PROT_WRITE; + default: + assert_not_reached(); + } +} + int journal_file_tail_end_by_pread(JournalFile *f, uint64_t *ret_offset) { uint64_t p; int r; @@ -3767,7 +3780,7 @@ int journal_file_open( newly_created = f->last_stat.st_size == 0 && journal_file_writable(f); } - f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, prot_from_flags(open_flags)); + f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, mmap_prot_from_open_flags(open_flags)); if (!f->cache_fd) { r = -ENOMEM; goto fail; diff --git a/src/libsystemd/sd-journal/journal-verify.c b/src/libsystemd/sd-journal/journal-verify.c index ad4039dee0..34b1d8b909 100644 --- a/src/libsystemd/sd-journal/journal-verify.c +++ b/src/libsystemd/sd-journal/journal-verify.c @@ -18,7 +18,6 @@ #include "macro.h" #include "terminal-util.h" #include "tmpfile-util.h" -#include "util.h" static void draw_progress(uint64_t p, usec_t *last_usec) { unsigned n, i, j, k; diff --git a/src/libsystemd/sd-journal/test-catalog.c b/src/libsystemd/sd-journal/test-catalog.c index ad06221175..526b8200ba 100644 --- a/src/libsystemd/sd-journal/test-catalog.c +++ b/src/libsystemd/sd-journal/test-catalog.c @@ -18,7 +18,6 @@ #include "strv.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" static char** catalog_dirs = NULL; static const char *no_catalog_dirs[] = { diff --git a/src/libsystemd/sd-journal/test-journal-init.c b/src/libsystemd/sd-journal/test-journal-init.c index 80aff75bb9..d5702db330 100644 --- a/src/libsystemd/sd-journal/test-journal-init.c +++ b/src/libsystemd/sd-journal/test-journal-init.c @@ -7,7 +7,6 @@ #include "parse-util.h" #include "rm-rf.h" #include "tests.h" -#include "util.h" int main(int argc, char *argv[]) { sd_journal *j; diff --git a/src/libsystemd/sd-journal/test-journal-match.c b/src/libsystemd/sd-journal/test-journal-match.c index ded67563d7..571a88c1ac 100644 --- a/src/libsystemd/sd-journal/test-journal-match.c +++ b/src/libsystemd/sd-journal/test-journal-match.c @@ -9,7 +9,6 @@ #include "log.h" #include "string-util.h" #include "tests.h" -#include "util.h" int main(int argc, char *argv[]) { _cleanup_(sd_journal_closep) sd_journal *j = NULL; diff --git a/src/libsystemd/sd-journal/test-mmap-cache.c b/src/libsystemd/sd-journal/test-mmap-cache.c index 6ec36931fd..e3dfbada32 100644 --- a/src/libsystemd/sd-journal/test-mmap-cache.c +++ b/src/libsystemd/sd-journal/test-mmap-cache.c @@ -9,7 +9,6 @@ #include "macro.h" #include "mmap-cache.h" #include "tmpfile-util.h" -#include "util.h" int main(int argc, char *argv[]) { MMapFileDescriptor *fx; diff --git a/src/libsystemd/sd-login/sd-login.c b/src/libsystemd/sd-login/sd-login.c index f134f0a8c9..872d39e9ab 100644 --- a/src/libsystemd/sd-login/sd-login.c +++ b/src/libsystemd/sd-login/sd-login.c @@ -27,7 +27,6 @@ #include "string-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" /* Error codes: * diff --git a/src/libsystemd/sd-netlink/netlink-message-rtnl.c b/src/libsystemd/sd-netlink/netlink-message-rtnl.c index 109f3ee814..008e8022b1 100644 --- a/src/libsystemd/sd-netlink/netlink-message-rtnl.c +++ b/src/libsystemd/sd-netlink/netlink-message-rtnl.c @@ -15,7 +15,6 @@ #include "netlink-types.h" #include "netlink-util.h" #include "socket-util.h" -#include "util.h" static bool rtnl_message_type_is_neigh(uint16_t type) { return IN_SET(type, RTM_NEWNEIGH, RTM_GETNEIGH, RTM_DELNEIGH); diff --git a/src/libsystemd/sd-netlink/netlink-socket.c b/src/libsystemd/sd-netlink/netlink-socket.c index 605e80916c..1da459c014 100644 --- a/src/libsystemd/sd-netlink/netlink-socket.c +++ b/src/libsystemd/sd-netlink/netlink-socket.c @@ -14,7 +14,6 @@ #include "netlink-internal.h" #include "netlink-types.h" #include "socket-util.h" -#include "util.h" static int broadcast_groups_get(sd_netlink *nl) { _cleanup_free_ uint32_t *groups = NULL; diff --git a/src/libsystemd/sd-netlink/netlink-util.h b/src/libsystemd/sd-netlink/netlink-util.h index d14392a018..72d16fa9a9 100644 --- a/src/libsystemd/sd-netlink/netlink-util.h +++ b/src/libsystemd/sd-netlink/netlink-util.h @@ -9,7 +9,6 @@ #include "in-addr-util.h" #include "ordered-set.h" #include "socket-util.h" -#include "util.h" /* See struct rtvia in rtnetlink.h */ typedef struct RouteVia { diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 3d6b07f39f..00687e5cc8 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -16,7 +16,6 @@ #include "stdio-util.h" #include "string-util.h" #include "strv.h" -#include "util.h" static int network_get_string(const char *field, char **ret) { _cleanup_free_ char *s = NULL; diff --git a/src/libsystemd/sd-path/sd-path.c b/src/libsystemd/sd-path/sd-path.c index ac33e349c0..601f61bf63 100644 --- a/src/libsystemd/sd-path/sd-path.c +++ b/src/libsystemd/sd-path/sd-path.c @@ -12,7 +12,6 @@ #include "string-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" static int from_environment(const char *envname, const char *fallback, const char **ret) { assert(ret); diff --git a/src/locale/localectl.c b/src/locale/localectl.c index c23f1fa3f6..e44e287282 100644 --- a/src/locale/localectl.c +++ b/src/locale/localectl.c @@ -5,6 +5,7 @@ #include "sd-bus.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-map-properties.h" diff --git a/src/locale/localed.c b/src/locale/localed.c index 7aa47f18c2..a2014e3da0 100644 --- a/src/locale/localed.c +++ b/src/locale/localed.c @@ -17,7 +17,7 @@ #include "bus-log-control-api.h" #include "bus-message.h" #include "bus-polkit.h" -#include "def.h" +#include "constants.h" #include "dlfcn-util.h" #include "kbd-util.h" #include "localed-util.h" diff --git a/src/login/inhibit.c b/src/login/inhibit.c index 211af404bd..6184d10cde 100644 --- a/src/login/inhibit.c +++ b/src/login/inhibit.c @@ -9,6 +9,7 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "bus-util.h" #include "fd-util.h" @@ -22,7 +23,6 @@ #include "strv.h" #include "terminal-util.h" #include "user-util.h" -#include "util.h" static const char* arg_what = "idle:sleep:shutdown"; static const char* arg_who = NULL; diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 4dbfa0db44..244708d2f5 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -8,6 +8,7 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-map-properties.h" diff --git a/src/login/logind-button.c b/src/login/logind-button.c index 0314ae1774..f16be0f4e1 100644 --- a/src/login/logind-button.c +++ b/src/login/logind-button.c @@ -13,7 +13,6 @@ #include "logind-button.h" #include "missing_input.h" #include "string-util.h" -#include "util.h" #define CONST_MAX5(a, b, c, d, e) CONST_MAX(CONST_MAX(a, b), CONST_MAX(CONST_MAX(c, d), e)) diff --git a/src/login/logind-device.c b/src/login/logind-device.c index 592ee3b9d6..f605034526 100644 --- a/src/login/logind-device.c +++ b/src/login/logind-device.c @@ -5,7 +5,6 @@ #include "alloc-util.h" #include "logind-device.h" #include "logind-seat-dbus.h" -#include "util.h" Device* device_new(Manager *m, const char *sysfs, bool master) { Device *d; diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c index 16612ddf18..9cf00a502f 100644 --- a/src/login/logind-inhibit.c +++ b/src/login/logind-inhibit.c @@ -24,7 +24,6 @@ #include "string-util.h" #include "tmpfile-util.h" #include "user-util.h" -#include "util.h" static void inhibitor_remove_fifo(Inhibitor *i); diff --git a/src/login/logind-seat-dbus.c b/src/login/logind-seat-dbus.c index 03a419229e..877b9c1af1 100644 --- a/src/login/logind-seat-dbus.c +++ b/src/login/logind-seat-dbus.c @@ -17,7 +17,6 @@ #include "missing_capability.h" #include "strv.h" #include "user-util.h" -#include "util.h" static BUS_DEFINE_PROPERTY_GET_GLOBAL(property_get_const_true, "b", true); static BUS_DEFINE_PROPERTY_GET(property_get_can_tty, "b", Seat, seat_can_tty); diff --git a/src/login/logind-seat.c b/src/login/logind-seat.c index d8ad424bfe..863b8cc3b4 100644 --- a/src/login/logind-seat.c +++ b/src/login/logind-seat.c @@ -23,7 +23,6 @@ #include "string-util.h" #include "terminal-util.h" #include "tmpfile-util.h" -#include "util.h" int seat_new(Seat** ret, Manager *m, const char *id) { _cleanup_(seat_freep) Seat *s = NULL; diff --git a/src/login/logind-session-dbus.c b/src/login/logind-session-dbus.c index 56f6307dcd..ea4800d827 100644 --- a/src/login/logind-session-dbus.c +++ b/src/login/logind-session-dbus.c @@ -24,7 +24,6 @@ #include "signal-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" static int property_get_user( sd_bus *bus, diff --git a/src/login/logind-session-device.c b/src/login/logind-session-device.c index 4f934dd01d..eccc1aeb5d 100644 --- a/src/login/logind-session-device.c +++ b/src/login/logind-session-device.c @@ -17,7 +17,6 @@ #include "missing_drm.h" #include "missing_input.h" #include "parse-util.h" -#include "util.h" enum SessionDeviceNotifications { SESSION_DEVICE_RESUME, diff --git a/src/login/logind-session.c b/src/login/logind-session.c index 5bd4abc474..85cb4eba9e 100644 --- a/src/login/logind-session.c +++ b/src/login/logind-session.c @@ -38,7 +38,6 @@ #include "tmpfile-util.h" #include "uid-alloc-range.h" #include "user-util.h" -#include "util.h" #define RELEASE_USEC (20*USEC_PER_SEC) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index e02ad754ee..5680a300f3 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -35,7 +35,6 @@ #include "uid-alloc-range.h" #include "unit-name.h" #include "user-util.h" -#include "util.h" int user_new(User **ret, Manager *m, diff --git a/src/login/logind.c b/src/login/logind.c index cdca5ca58c..cc153fd6bf 100644 --- a/src/login/logind.c +++ b/src/login/logind.c @@ -14,8 +14,8 @@ #include "bus-log-control-api.h" #include "bus-polkit.h" #include "cgroup-util.h" +#include "constants.h" #include "daemon-util.h" -#include "def.h" #include "device-util.h" #include "dirent-util.h" #include "fd-util.h" diff --git a/src/login/sysfs-show.c b/src/login/sysfs-show.c index d79f753c9a..0a8c02a2a2 100644 --- a/src/login/sysfs-show.c +++ b/src/login/sysfs-show.c @@ -11,7 +11,6 @@ #include "string-util.h" #include "sysfs-show.h" #include "terminal-util.h" -#include "util.h" static int show_sysfs_one( const char *seat, diff --git a/src/login/test-inhibit.c b/src/login/test-inhibit.c index dbe79c7074..aefae277fc 100644 --- a/src/login/test-inhibit.c +++ b/src/login/test-inhibit.c @@ -8,7 +8,6 @@ #include "bus-util.h" #include "fd-util.h" #include "macro.h" -#include "util.h" static int inhibit(sd_bus *bus, const char *what) { _cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL; diff --git a/src/machine-id-setup/machine-id-setup-main.c b/src/machine-id-setup/machine-id-setup-main.c index 8a3b1efb4c..6aef48650d 100644 --- a/src/machine-id-setup/machine-id-setup-main.c +++ b/src/machine-id-setup/machine-id-setup-main.c @@ -6,6 +6,7 @@ #include <stdlib.h> #include "alloc-util.h" +#include "build.h" #include "dissect-image.h" #include "id128-util.h" #include "log.h" @@ -16,7 +17,6 @@ #include "path-util.h" #include "pretty-print.h" #include "terminal-util.h" -#include "util.h" static char *arg_root = NULL; static char *arg_image = NULL; diff --git a/src/machine/machine.c b/src/machine/machine.c index 335a4e96fb..de7b20ff2d 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -32,7 +32,6 @@ #include "tmpfile-util.h" #include "unit-name.h" #include "user-util.h" -#include "util.h" Machine* machine_new(Manager *manager, MachineClass class, const char *name) { Machine *m; diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 14085f7397..af0f5d8612 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -14,6 +14,7 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-locator.h" @@ -24,8 +25,8 @@ #include "bus-wait-for-jobs.h" #include "cgroup-show.h" #include "cgroup-util.h" +#include "constants.h" #include "copy.h" -#include "def.h" #include "env-util.h" #include "fd-util.h" #include "format-table.h" diff --git a/src/modules-load/modules-load.c b/src/modules-load/modules-load.c index 9e20d59389..8e7f7a5eba 100644 --- a/src/modules-load/modules-load.c +++ b/src/modules-load/modules-load.c @@ -5,8 +5,9 @@ #include <limits.h> #include <sys/stat.h> +#include "build.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "fd-util.h" #include "fileio.h" #include "log.h" @@ -16,7 +17,6 @@ #include "proc-cmdline.h" #include "string-util.h" #include "strv.h" -#include "util.h" static char **arg_proc_cmdline_modules = NULL; static const char conf_file_dirs[] = CONF_PATHS_NULSTR("modules-load.d"); diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index 25e18d279c..95dcf1bab0 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -5,6 +5,7 @@ #include "sd-bus.h" #include "sd-device.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-unit-util.h" diff --git a/src/network/generator/main.c b/src/network/generator/main.c index a36fe98c86..a0af0b831b 100644 --- a/src/network/generator/main.c +++ b/src/network/generator/main.c @@ -2,6 +2,7 @@ #include <getopt.h> +#include "build.h" #include "fd-util.h" #include "generator.h" #include "macro.h" diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index acd609f296..7baec1529f 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -13,7 +13,6 @@ #include "parse-util.h" #include "string-table.h" #include "string-util.h" -#include "util.h" static const char* const fou_encap_type_table[_NETDEV_FOO_OVER_UDP_ENCAP_MAX] = { [NETDEV_FOO_OVER_UDP_ENCAP_DIRECT] = "FooOverUDP", diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c index 2bce0fc5b2..7d51a619bd 100644 --- a/src/network/netdev/l2tp-tunnel.c +++ b/src/network/netdev/l2tp-tunnel.c @@ -15,7 +15,6 @@ #include "socket-util.h" #include "string-table.h" #include "string-util.h" -#include "util.h" static const char* const l2tp_l2spec_type_table[_NETDEV_L2TP_L2SPECTYPE_MAX] = { [NETDEV_L2TP_L2SPECTYPE_NONE] = "none", diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index 1e3f6a9c4b..0da3dd4bd2 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -18,7 +18,6 @@ #include "socket-util.h" #include "string-table.h" #include "string-util.h" -#include "util.h" static void security_association_clear(SecurityAssociation *sa) { if (!sa) diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c index db414a8943..2addfeecaa 100644 --- a/src/network/netdev/tunnel.c +++ b/src/network/netdev/tunnel.c @@ -18,7 +18,6 @@ #include "string-table.h" #include "string-util.h" #include "tunnel.h" -#include "util.h" #define DEFAULT_IPV6_TTL 64 #define IP6_FLOWINFO_FLOWLABEL htobe32(0x000FFFFF) diff --git a/src/network/networkctl.c b/src/network/networkctl.c index a2e216e779..8146125fc8 100644 --- a/src/network/networkctl.c +++ b/src/network/networkctl.c @@ -22,6 +22,7 @@ #include "alloc-util.h" #include "bond-util.h" #include "bridge-util.h" +#include "build.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-locator.h" diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index 259cd312c9..107f19fd15 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -5,6 +5,7 @@ #include "alloc-util.h" #include "firewall-util.h" +#include "logarithm.h" #include "memory-util.h" #include "netlink-util.h" #include "networkd-address-pool.h" diff --git a/src/network/networkd-conf.c b/src/network/networkd-conf.c index 9190dbfc53..f73b2d43c7 100644 --- a/src/network/networkd-conf.c +++ b/src/network/networkd-conf.c @@ -4,7 +4,7 @@ ***/ #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "networkd-conf.h" #include "networkd-manager.h" #include "networkd-speed-meter.h" diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 95b08cb885..4ed622cfe6 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -27,6 +27,7 @@ #include "format-util.h" #include "fs-util.h" #include "glyph-util.h" +#include "logarithm.h" #include "missing_network.h" #include "netlink-util.h" #include "network-internal.h" @@ -66,7 +67,6 @@ #include "tmpfile-util.h" #include "tuntap.h" #include "udev-util.h" -#include "util.h" #include "vrf.h" bool link_ipv6_enabled(Link *link) { diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index 684d635d36..f3ebeadd2c 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -17,8 +17,8 @@ #include "bus-polkit.h" #include "bus-util.h" #include "conf-parser.h" +#include "constants.h" #include "daemon-util.h" -#include "def.h" #include "device-private.h" #include "device-util.h" #include "dns-domain.h" @@ -26,6 +26,7 @@ #include "fileio.h" #include "firewall-util.h" #include "fs-util.h" +#include "initrd-util.h" #include "local-addresses.h" #include "netlink-util.h" #include "network-internal.h" diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 41a0766f07..d516918c78 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -42,7 +42,6 @@ #include "string-util.h" #include "strv.h" #include "tclass.h" -#include "util.h" /* Let's assume that anything above this number is a user misconfiguration. */ #define MAX_NTP_SERVERS 128U diff --git a/src/network/networkd-route-util.c b/src/network/networkd-route-util.c index 0366382093..84866d3f84 100644 --- a/src/network/networkd-route-util.c +++ b/src/network/networkd-route-util.c @@ -3,6 +3,7 @@ #include <linux/rtnetlink.h> #include "alloc-util.h" +#include "logarithm.h" #include "networkd-address.h" #include "networkd-link.h" #include "networkd-manager.h" diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c index 69347d80ff..33352ba772 100644 --- a/src/network/networkd-util.c +++ b/src/network/networkd-util.c @@ -3,6 +3,7 @@ #include "condition.h" #include "conf-parser.h" #include "escape.h" +#include "logarithm.h" #include "networkd-link.h" #include "networkd-util.h" #include "parse-util.h" diff --git a/src/network/tc/fq.c b/src/network/tc/fq.c index c588f385c7..149a72e37c 100644 --- a/src/network/tc/fq.c +++ b/src/network/tc/fq.c @@ -6,6 +6,7 @@ #include "alloc-util.h" #include "conf-parser.h" #include "fq.h" +#include "logarithm.h" #include "netlink-util.h" #include "parse-util.h" #include "string-util.h" diff --git a/src/network/tc/hhf.c b/src/network/tc/hhf.c index 2d71a42c53..d44522f98c 100644 --- a/src/network/tc/hhf.c +++ b/src/network/tc/hhf.c @@ -9,7 +9,6 @@ #include "netlink-util.h" #include "parse-util.h" #include "string-util.h" -#include "util.h" static int heavy_hitter_filter_fill_message(Link *link, QDisc *qdisc, sd_netlink_message *req) { HeavyHitterFilter *hhf; diff --git a/src/network/wait-online/manager.c b/src/network/wait-online/manager.c index 624029a812..43ac10704b 100644 --- a/src/network/wait-online/manager.c +++ b/src/network/wait-online/manager.c @@ -10,7 +10,6 @@ #include "netlink-util.h" #include "strv.h" #include "time-util.h" -#include "util.h" static bool link_in_command_line_interfaces(Link *link, Manager *m) { assert(link); diff --git a/src/network/wait-online/wait-online.c b/src/network/wait-online/wait-online.c index a679b858fa..5328bba2d8 100644 --- a/src/network/wait-online/wait-online.c +++ b/src/network/wait-online/wait-online.c @@ -6,6 +6,7 @@ #include "sd-daemon.h" +#include "build.h" #include "daemon-util.h" #include "main-func.h" #include "manager.h" diff --git a/src/notify/notify.c b/src/notify/notify.c index 7b23e7bdb0..c4f54920ac 100644 --- a/src/notify/notify.c +++ b/src/notify/notify.c @@ -9,6 +9,7 @@ #include "sd-daemon.h" #include "alloc-util.h" +#include "build.h" #include "env-util.h" #include "format-util.h" #include "log.h" @@ -20,7 +21,6 @@ #include "terminal-util.h" #include "time-util.h" #include "user-util.h" -#include "util.h" static bool arg_ready = false; static pid_t arg_pid = 0; diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index 9e6379ae7b..bdb8985fbe 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -18,7 +18,6 @@ #include "string-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" static int chown_cgroup_path(const char *path, uid_t uid_shift) { _cleanup_close_ int fd = -1; diff --git a/src/nspawn/nspawn-expose-ports.c b/src/nspawn/nspawn-expose-ports.c index bb54f8c1e7..a8b1437171 100644 --- a/src/nspawn/nspawn-expose-ports.c +++ b/src/nspawn/nspawn-expose-ports.c @@ -13,7 +13,6 @@ #include "parse-util.h" #include "socket-util.h" #include "string-util.h" -#include "util.h" int expose_port_parse(ExposePort **l, const char *s) { const char *split, *e; diff --git a/src/nspawn/nspawn-network.c b/src/nspawn/nspawn-network.c index 536e369231..3a0e155f38 100644 --- a/src/nspawn/nspawn-network.c +++ b/src/nspawn/nspawn-network.c @@ -25,7 +25,6 @@ #include "string-util.h" #include "strv.h" #include "udev-util.h" -#include "util.h" #define HOST_HASH_KEY SD_ID128_MAKE(1a,37,6f,c7,46,ec,45,0b,ad,a3,d5,31,06,60,5d,b1) #define CONTAINER_HASH_KEY SD_ID128_MAKE(c3,c4,f9,19,b5,57,b2,1c,e6,cf,14,27,03,9c,ee,a2) diff --git a/src/nspawn/nspawn-register.c b/src/nspawn/nspawn-register.c index c78bead4a4..8995e0f7b3 100644 --- a/src/nspawn/nspawn-register.c +++ b/src/nspawn/nspawn-register.c @@ -11,7 +11,6 @@ #include "special.h" #include "stat-util.h" #include "strv.h" -#include "util.h" static int append_machine_properties( sd_bus_message *m, diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c index e06de68072..05bde1c756 100644 --- a/src/nspawn/nspawn-settings.c +++ b/src/nspawn/nspawn-settings.c @@ -16,7 +16,6 @@ #include "string-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" Settings *settings_new(void) { Settings *s; diff --git a/src/nspawn/nspawn-setuid.c b/src/nspawn/nspawn-setuid.c index 34758d8b0f..54f56725a8 100644 --- a/src/nspawn/nspawn-setuid.c +++ b/src/nspawn/nspawn-setuid.c @@ -5,7 +5,7 @@ #include <unistd.h> #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "errno.h" #include "fd-util.h" #include "fileio.h" @@ -17,7 +17,6 @@ #include "string-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" static int spawn_getent(const char *database, const char *key, pid_t *rpid) { int pipe_fds[2], r; diff --git a/src/nspawn/nspawn-stub-pid1.c b/src/nspawn/nspawn-stub-pid1.c index 85c439815c..47f7155b19 100644 --- a/src/nspawn/nspawn-stub-pid1.c +++ b/src/nspawn/nspawn-stub-pid1.c @@ -6,7 +6,8 @@ #include <sys/prctl.h> #include <unistd.h> -#include "def.h" +#include "argv-util.h" +#include "constants.h" #include "exit-status.h" #include "fd-util.h" #include "log.h" diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 01a67b5553..fb9fbed12c 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -28,6 +28,7 @@ #include "base-filesystem.h" #include "blkid-util.h" #include "btrfs-util.h" +#include "build.h" #include "bus-error.h" #include "bus-util.h" #include "cap-list.h" @@ -110,7 +111,6 @@ #include "umask-util.h" #include "unit-name.h" #include "user-util.h" -#include "util.h" /* The notify socket inside the container it can use to talk to nspawn using the sd_notify(3) protocol */ #define NSPAWN_NOTIFY_SOCKET_PATH "/run/host/notify" diff --git a/src/oom/oomctl.c b/src/oom/oomctl.c index 2ffb9d4d19..e527abf5da 100644 --- a/src/oom/oomctl.c +++ b/src/oom/oomctl.c @@ -3,6 +3,7 @@ #include <getopt.h> #include <unistd.h> +#include "build.h" #include "bus-error.h" #include "copy.h" #include "main-func.h" diff --git a/src/oom/oomd.c b/src/oom/oomd.c index 6cfe1a3f4c..eb1b830605 100644 --- a/src/oom/oomd.c +++ b/src/oom/oomd.c @@ -2,6 +2,7 @@ #include <getopt.h> +#include "build.h" #include "bus-log-control-api.h" #include "bus-object.h" #include "cgroup-util.h" diff --git a/src/partition/growfs.c b/src/partition/growfs.c index 8a04071f17..bb2b53103f 100644 --- a/src/partition/growfs.c +++ b/src/partition/growfs.c @@ -14,6 +14,7 @@ #include "blockdev-util.h" #include "btrfs-util.h" +#include "build.h" #include "cryptsetup-util.h" #include "device-nodes.h" #include "device-util.h" diff --git a/src/partition/repart.c b/src/partition/repart.c index 8e3cfece89..a037d7be1d 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -19,11 +19,12 @@ #include "blkid-util.h" #include "blockdev-util.h" #include "btrfs-util.h" +#include "build.h" #include "chase-symlinks.h" #include "conf-files.h" #include "conf-parser.h" +#include "constants.h" #include "cryptsetup-util.h" -#include "def.h" #include "device-util.h" #include "devnum-util.h" #include "dirent-util.h" @@ -40,6 +41,7 @@ #include "hexdecoct.h" #include "hmac.h" #include "id128-util.h" +#include "initrd-util.h" #include "io-util.h" #include "json.h" #include "list.h" diff --git a/src/path/path.c b/src/path/path.c index 0024a60611..d3348ce04f 100644 --- a/src/path/path.c +++ b/src/path/path.c @@ -8,12 +8,12 @@ #include "sd-path.h" #include "alloc-util.h" +#include "build.h" #include "log.h" #include "macro.h" #include "main-func.h" #include "pretty-print.h" #include "string-util.h" -#include "util.h" static const char *arg_suffix = NULL; diff --git a/src/portable/portable.c b/src/portable/portable.c index be906f786c..dd0f6d3d13 100644 --- a/src/portable/portable.c +++ b/src/portable/portable.c @@ -8,7 +8,7 @@ #include "conf-files.h" #include "copy.h" #include "data-fd-util.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "discover-image.h" #include "dissect-image.h" diff --git a/src/portable/portablectl.c b/src/portable/portablectl.c index dbae8a4d47..ff71535c13 100644 --- a/src/portable/portablectl.c +++ b/src/portable/portablectl.c @@ -6,12 +6,13 @@ #include "sd-bus.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-unit-util.h" #include "bus-wait-for-jobs.h" #include "chase-symlinks.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "env-file.h" #include "fd-util.h" diff --git a/src/portable/portabled.c b/src/portable/portabled.c index 2f9afdc8f2..a4fae65e7e 100644 --- a/src/portable/portabled.c +++ b/src/portable/portabled.c @@ -8,8 +8,8 @@ #include "alloc-util.h" #include "bus-log-control-api.h" #include "bus-polkit.h" +#include "constants.h" #include "daemon-util.h" -#include "def.h" #include "main-func.h" #include "portabled-bus.h" #include "portabled-image-bus.h" diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index d820ceb9f6..f8e6582d5b 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -45,7 +45,6 @@ #include "strv.h" #include "tmpfile-util.h" #include "user-util.h" -#include "util.h" /* Command line argument handling */ typedef enum PStoreStorage { diff --git a/src/quotacheck/quotacheck.c b/src/quotacheck/quotacheck.c index 575965c470..ef5fec3f10 100644 --- a/src/quotacheck/quotacheck.c +++ b/src/quotacheck/quotacheck.c @@ -13,7 +13,6 @@ #include "process-util.h" #include "signal-util.h" #include "string-util.h" -#include "util.h" static bool arg_skip = false; static bool arg_force = false; diff --git a/src/random-seed/random-seed.c b/src/random-seed/random-seed.c index 22ddf659ae..65de1aa986 100644 --- a/src/random-seed/random-seed.c +++ b/src/random-seed/random-seed.c @@ -15,6 +15,7 @@ #include "sd-id128.h" #include "alloc-util.h" +#include "build.h" #include "fd-util.h" #include "fs-util.h" #include "io-util.h" @@ -33,7 +34,6 @@ #include "sync-util.h" #include "sha256.h" #include "terminal-util.h" -#include "util.h" #include "xattr-util.h" typedef enum SeedAction { diff --git a/src/rc-local-generator/rc-local-generator.c b/src/rc-local-generator/rc-local-generator.c index c2b9e64217..d8c06b1d2d 100644 --- a/src/rc-local-generator/rc-local-generator.c +++ b/src/rc-local-generator/rc-local-generator.c @@ -8,7 +8,6 @@ #include "log.h" #include "mkdir-label.h" #include "string-util.h" -#include "util.h" static const char *arg_dest = NULL; diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c index d747d60d5d..4515592387 100644 --- a/src/remount-fs/remount-fs.c +++ b/src/remount-fs/remount-fs.c @@ -18,7 +18,6 @@ #include "process-util.h" #include "signal-util.h" #include "strv.h" -#include "util.h" /* Goes through /etc/fstab and remounts all API file systems, applying options that are in /etc/fstab that systemd * might not have respected */ diff --git a/src/reply-password/reply-password.c b/src/reply-password/reply-password.c index a9aa4b832a..feb1d1ef7c 100644 --- a/src/reply-password/reply-password.c +++ b/src/reply-password/reply-password.c @@ -13,7 +13,6 @@ #include "memory-util.h" #include "socket-util.h" #include "string-util.h" -#include "util.h" static int send_on_socket(int fd, const char *socket_name, const void *packet, size_t size) { union sockaddr_union sa = {}; diff --git a/src/resolve/resolvconf-compat.c b/src/resolve/resolvconf-compat.c index d95df29793..3804d3dde3 100644 --- a/src/resolve/resolvconf-compat.c +++ b/src/resolve/resolvconf-compat.c @@ -4,7 +4,8 @@ #include <net/if.h> #include "alloc-util.h" -#include "def.h" +#include "build.h" +#include "constants.h" #include "dns-domain.h" #include "extract-word.h" #include "fileio.h" diff --git a/src/resolve/resolvectl.c b/src/resolve/resolvectl.c index b07761a495..dd0a8e121e 100644 --- a/src/resolve/resolvectl.c +++ b/src/resolve/resolvectl.c @@ -9,6 +9,7 @@ #include "af-list.h" #include "alloc-util.h" +#include "build.h" #include "bus-common-errors.h" #include "bus-error.h" #include "bus-locator.h" diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index 6fd193a7cb..2be5986f9b 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -2,7 +2,7 @@ #include "alloc-util.h" #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "extract-word.h" #include "hexdecoct.h" #include "parse-util.h" diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 88c52e411b..f90e5974c4 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -14,7 +14,6 @@ #include "strv.h" #include "unaligned.h" #include "utf8.h" -#include "util.h" #define EDNS0_OPT_DO (1<<15) diff --git a/src/resolve/resolved-dns-trust-anchor.c b/src/resolve/resolved-dns-trust-anchor.c index 69a484dc12..828045f68f 100644 --- a/src/resolve/resolved-dns-trust-anchor.c +++ b/src/resolve/resolved-dns-trust-anchor.c @@ -4,7 +4,7 @@ #include "alloc-util.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "dns-domain.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/resolve/resolved-dnssd.c b/src/resolve/resolved-dnssd.c index 464892a8fe..f5a8a80ebc 100644 --- a/src/resolve/resolved-dnssd.c +++ b/src/resolve/resolved-dnssd.c @@ -2,7 +2,7 @@ #include "conf-files.h" #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "resolved-dnssd.h" #include "resolved-dns-rr.h" #include "resolved-manager.h" diff --git a/src/rfkill/rfkill.c b/src/rfkill/rfkill.c index 8aec9b21e4..773b25d816 100644 --- a/src/rfkill/rfkill.c +++ b/src/rfkill/rfkill.c @@ -24,7 +24,6 @@ #include "string-table.h" #include "string-util.h" #include "udev-util.h" -#include "util.h" /* Note that any write is delayed until exit and the rfkill state will not be * stored for rfkill indices that disappear after a change. */ diff --git a/src/run/run.c b/src/run/run.c index 627a6b11da..5f7d651b90 100644 --- a/src/run/run.c +++ b/src/run/run.c @@ -10,6 +10,7 @@ #include "sd-event.h" #include "alloc-util.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-map-properties.h" diff --git a/src/shared/acl-util.c b/src/shared/acl-util.c index 2bdc529b80..c6c673984d 100644 --- a/src/shared/acl-util.c +++ b/src/shared/acl-util.c @@ -10,7 +10,6 @@ #include "string-util.h" #include "strv.h" #include "user-util.h" -#include "util.h" int acl_find_uid(acl_t acl, uid_t uid, acl_entry_t *ret_entry) { acl_entry_t i; diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 17474fe0be..84d7b31bad 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -20,8 +20,8 @@ #include "alloc-util.h" #include "ask-password-api.h" +#include "constants.h" #include "creds-util.h" -#include "def.h" #include "fd-util.h" #include "fileio.h" #include "format-util.h" diff --git a/src/shared/btrfs-util.c b/src/shared/btrfs-util.c index 58ba286a24..92a9bcde4f 100644 --- a/src/shared/btrfs-util.c +++ b/src/shared/btrfs-util.c @@ -31,7 +31,6 @@ #include "stat-util.h" #include "string-util.h" #include "time-util.h" -#include "util.h" /* WARNING: Be careful with file system ioctls! When we get an fd, we * need to make sure it either refers to only a regular file or diff --git a/src/shared/calendarspec.h b/src/shared/calendarspec.h index d756efcdb7..5a04ac018d 100644 --- a/src/shared/calendarspec.h +++ b/src/shared/calendarspec.h @@ -7,7 +7,6 @@ #include <stdbool.h> #include "time-util.h" -#include "util.h" typedef struct CalendarComponent { int start; diff --git a/src/shared/condition.c b/src/shared/condition.c index a23d6a3e45..f404d99878 100644 --- a/src/shared/condition.c +++ b/src/shared/condition.c @@ -34,6 +34,7 @@ #include "fs-util.h" #include "glob-util.h" #include "hostname-util.h" +#include "initrd-util.h" #include "ima-util.h" #include "limits-util.h" #include "list.h" diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 5cb41a39da..69932865ba 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -10,7 +10,7 @@ #include "alloc-util.h" #include "conf-files.h" #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "dns-domain.h" #include "escape.h" #include "ether-addr-util.h" diff --git a/src/shared/coredump-util.c b/src/shared/coredump-util.c index a0b648bf79..3d2f179049 100644 --- a/src/shared/coredump-util.c +++ b/src/shared/coredump-util.c @@ -4,6 +4,7 @@ #include "extract-word.h" #include "fileio.h" #include "string-table.h" +#include "virt.h" static const char *const coredump_filter_table[_COREDUMP_FILTER_MAX] = { [COREDUMP_FILTER_PRIVATE_ANONYMOUS] = "private-anonymous", @@ -72,3 +73,15 @@ int set_coredump_filter(uint64_t value) { return write_string_file("/proc/self/coredump_filter", t, WRITE_STRING_FILE_VERIFY_ON_FAILURE|WRITE_STRING_FILE_DISABLE_BUFFER); } + +/* Turn off core dumps but only if we're running outside of a container. */ +void disable_coredumps(void) { + int r; + + if (detect_container() > 0) + return; + + r = write_string_file("/proc/sys/kernel/core_pattern", "|/bin/false", WRITE_STRING_FILE_DISABLE_BUFFER); + if (r < 0) + log_debug_errno(r, "Failed to turn off coredumps, ignoring: %m"); +} diff --git a/src/shared/coredump-util.h b/src/shared/coredump-util.h index 09e7ed443f..8eda86dfdb 100644 --- a/src/shared/coredump-util.h +++ b/src/shared/coredump-util.h @@ -27,3 +27,4 @@ CoredumpFilter coredump_filter_from_string(const char *s) _pure_; int coredump_filter_mask_from_string(const char *s, uint64_t *ret); int set_coredump_filter(uint64_t value); +void disable_coredumps(void); diff --git a/src/shared/cpu-set-util.c b/src/shared/cpu-set-util.c index b1873b6409..34c13cf969 100644 --- a/src/shared/cpu-set-util.c +++ b/src/shared/cpu-set-util.c @@ -18,7 +18,6 @@ #include "stat-util.h" #include "string-util.h" #include "strv.h" -#include "util.h" char* cpu_set_to_string(const CPUSet *a) { _cleanup_free_ char *str = NULL; diff --git a/src/shared/creds-util.c b/src/shared/creds-util.c index ecf90e2084..f6811ce9aa 100644 --- a/src/shared/creds-util.c +++ b/src/shared/creds-util.c @@ -10,8 +10,8 @@ #include "blockdev-util.h" #include "chattr-util.h" +#include "constants.h" #include "creds-util.h" -#include "def.h" #include "efi-api.h" #include "env-util.h" #include "fd-util.h" diff --git a/src/shared/devnode-acl.c b/src/shared/devnode-acl.c index 66e3a40f2f..5911c2f84d 100644 --- a/src/shared/devnode-acl.c +++ b/src/shared/devnode-acl.c @@ -15,7 +15,6 @@ #include "glyph-util.h" #include "set.h" #include "string-util.h" -#include "util.h" static int flush_acl(acl_t acl) { acl_entry_t i; diff --git a/src/shared/dissect-image.c b/src/shared/dissect-image.c index cfa7d7e0f3..101db51a13 100644 --- a/src/shared/dissect-image.c +++ b/src/shared/dissect-image.c @@ -27,9 +27,9 @@ #include "blockdev-util.h" #include "chase-symlinks.h" #include "conf-files.h" +#include "constants.h" #include "copy.h" #include "cryptsetup-util.h" -#include "def.h" #include "device-nodes.h" #include "device-util.h" #include "devnum-util.h" diff --git a/src/shared/elf-util.c b/src/shared/elf-util.c index 181735409d..7791545416 100644 --- a/src/shared/elf-util.c +++ b/src/shared/elf-util.c @@ -24,7 +24,6 @@ #include "process-util.h" #include "rlimit-util.h" #include "string-util.h" -#include "util.h" #define FRAMES_MAX 64 #define THREADS_MAX 64 diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 19ddf04986..cd57016964 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -29,7 +29,6 @@ #include "strv.h" #include "terminal-util.h" #include "tmpfile-util.h" -#include "util.h" /* Put this test here for a lack of better place */ assert_cc(EAGAIN == EWOULDBLOCK); diff --git a/src/shared/format-table.c b/src/shared/format-table.c index b62445faa6..0549c9f12e 100644 --- a/src/shared/format-table.c +++ b/src/shared/format-table.c @@ -30,7 +30,6 @@ #include "time-util.h" #include "user-util.h" #include "utf8.h" -#include "util.h" #define DEFAULT_WEIGHT 100 diff --git a/src/shared/fstab-util.c b/src/shared/fstab-util.c index f683f05981..3cbc6be248 100644 --- a/src/shared/fstab-util.c +++ b/src/shared/fstab-util.c @@ -7,6 +7,7 @@ #include "alloc-util.h" #include "device-nodes.h" #include "fstab-util.h" +#include "initrd-util.h" #include "macro.h" #include "mount-util.h" #include "nulstr-util.h" diff --git a/src/shared/generator.c b/src/shared/generator.c index 5d019f4f4e..7eed3b76c1 100644 --- a/src/shared/generator.c +++ b/src/shared/generator.c @@ -11,6 +11,7 @@ #include "fileio.h" #include "fstab-util.h" #include "generator.h" +#include "initrd-util.h" #include "log.h" #include "macro.h" #include "mkdir-label.h" @@ -21,7 +22,6 @@ #include "string-util.h" #include "time-util.h" #include "unit-name.h" -#include "util.h" int generator_open_unit_file( const char *dir, diff --git a/src/shared/hostname-setup.c b/src/shared/hostname-setup.c index 0fac0ecab7..0a56070224 100644 --- a/src/shared/hostname-setup.c +++ b/src/shared/hostname-setup.c @@ -17,7 +17,6 @@ #include "proc-cmdline.h" #include "string-table.h" #include "string-util.h" -#include "util.h" static int sethostname_idempotent_full(const char *s, bool really) { struct utsname u; diff --git a/src/shared/install.c b/src/shared/install.c index 834a1c59e3..51aa60bb52 100644 --- a/src/shared/install.c +++ b/src/shared/install.c @@ -13,7 +13,7 @@ #include "chase-symlinks.h" #include "conf-files.h" #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "errno-list.h" #include "extract-word.h" diff --git a/src/shared/killall.c b/src/shared/killall.c index 35180870a8..0b5a6642ec 100644 --- a/src/shared/killall.c +++ b/src/shared/killall.c @@ -9,10 +9,11 @@ #include <unistd.h> #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "fd-util.h" #include "format-util.h" +#include "initrd-util.h" #include "killall.h" #include "parse-util.h" #include "process-util.h" @@ -20,7 +21,6 @@ #include "stdio-util.h" #include "string-util.h" #include "terminal-util.h" -#include "util.h" static bool ignore_proc(pid_t pid, bool warn_rootfs) { _cleanup_fclose_ FILE *f = NULL; diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 2b180a8c0f..7972fc009e 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -40,7 +40,6 @@ #include "terminal-util.h" #include "time-util.h" #include "utf8.h" -#include "util.h" #include "web-util.h" /* up to three lines (each up to 100 characters) or 300 characters, whichever is less */ diff --git a/src/shared/logs-show.h b/src/shared/logs-show.h index 71e39ebb1f..0800b55c03 100644 --- a/src/shared/logs-show.h +++ b/src/shared/logs-show.h @@ -11,7 +11,6 @@ #include "macro.h" #include "output-mode.h" #include "time-util.h" -#include "util.h" int show_journal_entry( FILE *f, diff --git a/src/shared/machine-id-setup.c b/src/shared/machine-id-setup.c index df4ac419cb..c694a185ba 100644 --- a/src/shared/machine-id-setup.c +++ b/src/shared/machine-id-setup.c @@ -24,7 +24,6 @@ #include "string-util.h" #include "sync-util.h" #include "umask-util.h" -#include "util.h" #include "virt.h" static int generate_machine_id(const char *root, sd_id128_t *ret) { diff --git a/src/shared/main-func.h b/src/shared/main-func.h index 81a5c1813c..3dc4992282 100644 --- a/src/shared/main-func.h +++ b/src/shared/main-func.h @@ -5,12 +5,12 @@ #include "sd-daemon.h" +#include "argv-util.h" #include "pager.h" #include "selinux-util.h" #include "spawn-ask-password-agent.h" #include "spawn-polkit-agent.h" #include "static-destruct.h" -#include "util.h" #define _DEFINE_MAIN_FUNCTION(intro, impl, ret) \ int main(int argc, char *argv[]) { \ diff --git a/src/shared/meson.build b/src/shared/meson.build index e5879d046b..bdf1701ba9 100644 --- a/src/shared/meson.build +++ b/src/shared/meson.build @@ -466,7 +466,8 @@ libshared_deps = [threads, libselinux, libxenctrl, libxz, - libzstd] + libzstd, + versiondep] libshared_sym_path = '@0@/libshared.sym'.format(meson.current_source_dir()) diff --git a/src/shared/pager.c b/src/shared/pager.c index dc717cd1fe..74a6f9fd41 100644 --- a/src/shared/pager.c +++ b/src/shared/pager.c @@ -25,7 +25,6 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" static pid_t pager_pid = 0; diff --git a/src/shared/pretty-print.c b/src/shared/pretty-print.c index 98619c25d4..90f258f5bf 100644 --- a/src/shared/pretty-print.c +++ b/src/shared/pretty-print.c @@ -6,7 +6,7 @@ #include "alloc-util.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "env-util.h" #include "fd-util.h" #include "fileio.h" @@ -16,7 +16,6 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" bool urlify_enabled(void) { #if ENABLE_URLIFY diff --git a/src/shared/service-util.c b/src/shared/service-util.c index 68aa5775f5..b0585ba546 100644 --- a/src/shared/service-util.c +++ b/src/shared/service-util.c @@ -4,10 +4,10 @@ #include <stdio.h> #include "alloc-util.h" +#include "build.h" #include "pretty-print.h" #include "service-util.h" #include "terminal-util.h" -#include "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/sleep-config.c b/src/shared/sleep-config.c index efc066c4f2..0b1470ca01 100644 --- a/src/shared/sleep-config.c +++ b/src/shared/sleep-config.c @@ -21,7 +21,7 @@ #include "blockdev-util.h" #include "btrfs-util.h" #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "device-util.h" #include "devnum-util.h" #include "env-util.h" diff --git a/src/shared/spawn-ask-password-agent.c b/src/shared/spawn-ask-password-agent.c index 902d7543a5..d34cfffa83 100644 --- a/src/shared/spawn-ask-password-agent.c +++ b/src/shared/spawn-ask-password-agent.c @@ -8,7 +8,6 @@ #include "log.h" #include "process-util.h" #include "spawn-ask-password-agent.h" -#include "util.h" static pid_t agent_pid = 0; diff --git a/src/shared/spawn-polkit-agent.c b/src/shared/spawn-polkit-agent.c index 3abb02d03e..ce3c5fb948 100644 --- a/src/shared/spawn-polkit-agent.c +++ b/src/shared/spawn-polkit-agent.c @@ -15,7 +15,6 @@ #include "spawn-polkit-agent.h" #include "stdio-util.h" #include "time-util.h" -#include "util.h" #if ENABLE_POLKIT static pid_t agent_pid = 0; diff --git a/src/shared/switch-root.c b/src/shared/switch-root.c index 1a444841fa..0b93312bbf 100644 --- a/src/shared/switch-root.c +++ b/src/shared/switch-root.c @@ -11,6 +11,7 @@ #include "base-filesystem.h" #include "chase-symlinks.h" #include "fd-util.h" +#include "initrd-util.h" #include "log.h" #include "missing_syscall.h" #include "mkdir-label.h" @@ -23,7 +24,6 @@ #include "strv.h" #include "switch-root.h" #include "user-util.h" -#include "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 */ diff --git a/src/shared/tests.c b/src/shared/tests.c index a65080cbf4..ad6f978f98 100644 --- a/src/shared/tests.c +++ b/src/shared/tests.c @@ -6,7 +6,6 @@ #include <sys/mman.h> #include <sys/mount.h> #include <sys/wait.h> -#include <util.h> /* When we include libgen.h because we need dirname() we immediately * undefine basename() since libgen.h defines it as a macro to the POSIX diff --git a/src/shared/tests.h b/src/shared/tests.h index a2f7f38c41..cabd659fbd 100644 --- a/src/shared/tests.h +++ b/src/shared/tests.h @@ -5,9 +5,9 @@ #include "sd-daemon.h" +#include "argv-util.h" #include "macro.h" #include "static-destruct.h" -#include "util.h" static inline bool manager_errno_skip_test(int r) { return IN_SET(abs(r), diff --git a/src/shared/tpm2-util.c b/src/shared/tpm2-util.c index 65e8d48347..ba8a23e18c 100644 --- a/src/shared/tpm2-util.c +++ b/src/shared/tpm2-util.c @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "alloc-util.h" +#include "constants.h" #include "cryptsetup-util.h" -#include "def.h" #include "dirent-util.h" #include "dlfcn-util.h" #include "efi-api.h" diff --git a/src/shared/userdb-dropin.h b/src/shared/userdb-dropin.h index 94cdd1517b..fad3981f7c 100644 --- a/src/shared/userdb-dropin.h +++ b/src/shared/userdb-dropin.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #pragma once -#include "def.h" +#include "constants.h" #include "group-record.h" #include "user-record.h" #include "userdb.h" diff --git a/src/shared/utmp-wtmp.h b/src/shared/utmp-wtmp.h index 188d011fdd..97be719abf 100644 --- a/src/shared/utmp-wtmp.h +++ b/src/shared/utmp-wtmp.h @@ -5,7 +5,6 @@ #include <sys/types.h> #include "time-util.h" -#include "util.h" #if ENABLE_UTMP #include <utmpx.h> diff --git a/src/shared/watchdog.h b/src/shared/watchdog.h index a0a80efc97..a490183fa1 100644 --- a/src/shared/watchdog.h +++ b/src/shared/watchdog.h @@ -4,7 +4,6 @@ #include <stdbool.h> #include "time-util.h" -#include "util.h" const char *watchdog_get_device(void); usec_t watchdog_get_last_ping(clockid_t clock); diff --git a/src/shutdown/shutdown.c b/src/shutdown/shutdown.c index dcee0f9006..d0120bb85d 100644 --- a/src/shutdown/shutdown.c +++ b/src/shutdown/shutdown.c @@ -19,11 +19,13 @@ #include "binfmt-util.h" #include "cgroup-setup.h" #include "cgroup-util.h" -#include "def.h" +#include "coredump-util.h" +#include "constants.h" #include "errno-util.h" #include "exec-util.h" #include "fd-util.h" #include "fileio.h" +#include "initrd-util.h" #include "killall.h" #include "log.h" #include "parse-util.h" @@ -36,7 +38,6 @@ #include "sysctl-util.h" #include "terminal-util.h" #include "umount.h" -#include "util.h" #include "virt.h" #include "watchdog.h" diff --git a/src/shutdown/test-umount.c b/src/shutdown/test-umount.c index c92105b62b..80ec9b6dd6 100644 --- a/src/shutdown/test-umount.c +++ b/src/shutdown/test-umount.c @@ -7,7 +7,6 @@ #include "string-util.h" #include "tests.h" #include "umount.h" -#include "util.h" static void test_mount_points_list_one(const char *fname) { _cleanup_(mount_points_list_free) LIST_HEAD(MountPoint, mp_list_head); diff --git a/src/shutdown/umount.c b/src/shutdown/umount.c index e650b82170..c6fa64c344 100644 --- a/src/shutdown/umount.c +++ b/src/shutdown/umount.c @@ -23,7 +23,7 @@ #include "alloc-util.h" #include "blockdev-util.h" -#include "def.h" +#include "constants.h" #include "device-util.h" #include "dirent-util.h" #include "escape.h" @@ -43,7 +43,6 @@ #include "strv.h" #include "sync-util.h" #include "umount.h" -#include "util.h" #include "virt.h" static void mount_point_free(MountPoint **head, MountPoint *m) { diff --git a/src/sleep/sleep.c b/src/sleep/sleep.c index 3461d3e45f..6785ae2330 100644 --- a/src/sleep/sleep.c +++ b/src/sleep/sleep.c @@ -18,10 +18,11 @@ #include "sd-messages.h" #include "btrfs-util.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-util.h" -#include "def.h" +#include "constants.h" #include "exec-util.h" #include "fd-util.h" #include "fileio.h" @@ -37,7 +38,6 @@ #include "string-util.h" #include "strv.h" #include "time-util.h" -#include "util.h" static SleepOperation arg_operation = _SLEEP_OPERATION_INVALID; diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index c740b22057..2a6eeb661a 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -14,6 +14,7 @@ #include "sd-resolve.h" #include "alloc-util.h" +#include "build.h" #include "errno-util.h" #include "fd-util.h" #include "log.h" @@ -25,7 +26,6 @@ #include "set.h" #include "socket-util.h" #include "string-util.h" -#include "util.h" #define BUFFER_SIZE (256 * 1024) diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c index c851059a09..3c5ba074c7 100644 --- a/src/stdio-bridge/stdio-bridge.c +++ b/src/stdio-bridge/stdio-bridge.c @@ -10,13 +10,13 @@ #include "sd-daemon.h" #include "alloc-util.h" +#include "build.h" #include "bus-internal.h" #include "bus-util.h" #include "errno-util.h" #include "io-util.h" #include "log.h" #include "main-func.h" -#include "util.h" #include "version.h" #define DEFAULT_BUS_PATH "unix:path=/run/dbus/system_bus_socket" diff --git a/src/sulogin-shell/sulogin-shell.c b/src/sulogin-shell/sulogin-shell.c index 5648dfd83b..6161e134e1 100644 --- a/src/sulogin-shell/sulogin-shell.c +++ b/src/sulogin-shell/sulogin-shell.c @@ -11,7 +11,7 @@ #include "bus-locator.h" #include "bus-util.h" #include "bus-error.h" -#include "def.h" +#include "constants.h" #include "env-util.h" #include "log.h" #include "process-util.h" diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index 5de5d81655..d752ad2742 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -9,9 +9,10 @@ #include <sys/stat.h> #include <sys/types.h> +#include "build.h" #include "conf-files.h" +#include "constants.h" #include "creds-util.h" -#include "def.h" #include "errno-util.h" #include "fd-util.h" #include "fileio.h" diff --git a/src/sysext/sysext.c b/src/sysext/sysext.c index 0875099d5f..9a7ef8eb29 100644 --- a/src/sysext/sysext.c +++ b/src/sysext/sysext.c @@ -7,6 +7,7 @@ #include <sys/mount.h> #include <unistd.h> +#include "build.h" #include "capability-util.h" #include "chase-symlinks.h" #include "devnum-util.h" @@ -20,6 +21,7 @@ #include "format-table.h" #include "fs-util.h" #include "hashmap.h" +#include "initrd-util.h" #include "log.h" #include "main-func.h" #include "missing_magic.h" diff --git a/src/system-update-generator/system-update-generator.c b/src/system-update-generator/system-update-generator.c index fc5aaa9bac..54cd943af7 100644 --- a/src/system-update-generator/system-update-generator.c +++ b/src/system-update-generator/system-update-generator.c @@ -10,7 +10,6 @@ #include "special.h" #include "string-util.h" #include "unit-file.h" -#include "util.h" /* * Implements the logic described in systemd.offline-updates(7). diff --git a/src/systemctl/systemctl-switch-root.c b/src/systemctl/systemctl-switch-root.c index 669fa60dfd..8a7749be91 100644 --- a/src/systemctl/systemctl-switch-root.c +++ b/src/systemctl/systemctl-switch-root.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "argv-util.h" #include "bus-error.h" #include "bus-locator.h" #include "parse-util.h" diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 02a298d572..3f28bcc3dc 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -6,6 +6,7 @@ #include "sd-daemon.h" +#include "build.h" #include "bus-util.h" #include "dissect-image.h" #include "install.h" diff --git a/src/sysupdate/sysupdate-partition.c b/src/sysupdate/sysupdate-partition.c index 812007fa3b..fa46574fd6 100644 --- a/src/sysupdate/sysupdate-partition.c +++ b/src/sysupdate/sysupdate-partition.c @@ -10,7 +10,6 @@ #include "stdio-util.h" #include "string-util.h" #include "sysupdate-partition.h" -#include "util.h" void partition_info_destroy(PartitionInfo *p) { assert(p); diff --git a/src/sysupdate/sysupdate.c b/src/sysupdate/sysupdate.c index 944ac41a41..f6e89130bc 100644 --- a/src/sysupdate/sysupdate.c +++ b/src/sysupdate/sysupdate.c @@ -3,11 +3,12 @@ #include <getopt.h> #include <unistd.h> +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "chase-symlinks.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "dissect-image.h" #include "fd-util.h" diff --git a/src/sysusers/sysusers.c b/src/sysusers/sysusers.c index e2533e0128..b68a7d6d5a 100644 --- a/src/sysusers/sysusers.c +++ b/src/sysusers/sysusers.c @@ -4,11 +4,12 @@ #include <utmp.h> #include "alloc-util.h" +#include "build.h" #include "chase-symlinks.h" #include "conf-files.h" +#include "constants.h" #include "copy.h" #include "creds-util.h" -#include "def.h" #include "dissect-image.h" #include "env-util.h" #include "fd-util.h" @@ -38,7 +39,6 @@ #include "uid-range.h" #include "user-util.h" #include "utf8.h" -#include "util.h" typedef enum ItemType { ADD_USER = 'u', diff --git a/src/sysv-generator/sysv-generator.c b/src/sysv-generator/sysv-generator.c index 3c5df6c3ec..9b465e8c84 100644 --- a/src/sysv-generator/sysv-generator.c +++ b/src/sysv-generator/sysv-generator.c @@ -25,7 +25,6 @@ #include "string-util.h" #include "strv.h" #include "unit-name.h" -#include "util.h" static const struct { const char *path; diff --git a/src/test/meson.build b/src/test/meson.build index 2a4dfe26db..9d193651ed 100644 --- a/src/test/meson.build +++ b/src/test/meson.build @@ -41,6 +41,8 @@ test_dlopen_c = files('test-dlopen.c') ############################################################ tests += [ + [files('test-argv-util.c')], + [files('test-device-nodes.c')], [files('test-ether-addr-util.c')], @@ -205,7 +207,11 @@ tests += [ [files('test-ratelimit.c')], - [files('test-util.c')], + [files('test-raw-clone.c')], + + [files('test-limits-util.c')], + + [files('test-logarithm.c')], [files('test-macro.c')], @@ -213,6 +219,8 @@ tests += [ [], [libm]], + [files('test-memory-util.c')], + [files('test-mkdir.c')], [files('test-json.c'), diff --git a/src/test/test-af-list.c b/src/test/test-af-list.c index 644bc9e27b..45655d792e 100644 --- a/src/test/test-af-list.c +++ b/src/test/test-af-list.c @@ -5,7 +5,6 @@ #include "macro.h" #include "string-util.h" #include "tests.h" -#include "util.h" _unused_ static const struct af_name* lookup_af(register const char *str, register GPERF_LEN_TYPE len); diff --git a/src/test/test-architecture.c b/src/test/test-architecture.c index b542fe1ddf..043978e9a6 100644 --- a/src/test/test-architecture.c +++ b/src/test/test-architecture.c @@ -4,7 +4,6 @@ #include "errno-util.h" #include "log.h" #include "tests.h" -#include "util.h" #include "virt.h" int main(int argc, char *argv[]) { diff --git a/src/test/test-argv-util.c b/src/test/test-argv-util.c new file mode 100644 index 0000000000..26f6038534 --- /dev/null +++ b/src/test/test-argv-util.c @@ -0,0 +1,123 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include <sched.h> +#include <unistd.h> + +#if HAVE_VALGRIND_VALGRIND_H +# include <valgrind/valgrind.h> +#endif + +#include "argv-util.h" +#include "missing_sched.h" +#include "process-util.h" +#include "tests.h" +#include "virt.h" + +static void test_rename_process_now(const char *p, int ret) { + _cleanup_free_ char *comm = NULL, *cmdline = NULL; + int r; + + log_info("/* %s(%s) */", __func__, p); + + r = rename_process(p); + assert_se(r == ret || + (ret == 0 && r >= 0) || + (ret > 0 && r > 0)); + + log_debug_errno(r, "rename_process(%s): %m", p); + + if (r < 0) + return; + +#if HAVE_VALGRIND_VALGRIND_H + /* see above, valgrind is weird, we can't verify what we are doing here */ + if (RUNNING_ON_VALGRIND) + return; +#endif + + assert_se(get_process_comm(0, &comm) >= 0); + log_debug("comm = <%s>", comm); + assert_se(strneq(comm, p, TASK_COMM_LEN-1)); + /* We expect comm to be at most 16 bytes (TASK_COMM_LEN). The kernel may raise this limit in the + * future. We'd only check the initial part, at least until we recompile, but this will still pass. */ + + r = get_process_cmdline(0, SIZE_MAX, 0, &cmdline); + assert_se(r >= 0); + /* we cannot expect cmdline to be renamed properly without privileges */ + if (geteuid() == 0) { + if (r == 0 && detect_container() > 0) + log_info("cmdline = <%s> (not verified, Running in unprivileged container?)", cmdline); + else { + log_info("cmdline = <%s> (expected <%.*s>)", cmdline, (int) strlen("test-process-util"), p); + + bool skip = cmdline[0] == '"'; /* A shortcut to check if the string is quoted */ + + assert_se(strneq(cmdline + skip, p, strlen("test-process-util"))); + assert_se(startswith(cmdline + skip, p)); + } + } else + log_info("cmdline = <%s> (not verified)", cmdline); +} + +static void test_rename_process_one(const char *p, int ret) { + siginfo_t si; + pid_t pid; + + log_info("/* %s(%s) */", __func__, p); + + pid = fork(); + assert_se(pid >= 0); + + if (pid == 0) { + /* child */ + test_rename_process_now(p, ret); + _exit(EXIT_SUCCESS); + } + + assert_se(wait_for_terminate(pid, &si) >= 0); + assert_se(si.si_code == CLD_EXITED); + assert_se(si.si_status == EXIT_SUCCESS); +} + +TEST(rename_process_invalid) { + assert_se(rename_process(NULL) == -EINVAL); + assert_se(rename_process("") == -EINVAL); +} + +TEST(rename_process_multi) { + pid_t pid; + + pid = fork(); + assert_se(pid >= 0); + + if (pid > 0) { + siginfo_t si; + + assert_se(wait_for_terminate(pid, &si) >= 0); + assert_se(si.si_code == CLD_EXITED); + assert_se(si.si_status == EXIT_SUCCESS); + + return; + } + + /* child */ + test_rename_process_now("one", 1); + test_rename_process_now("more", 0); /* longer than "one", hence truncated */ + (void) setresuid(99, 99, 99); /* change uid when running privileged */ + test_rename_process_now("time!", 0); + test_rename_process_now("0", 1); /* shorter than "one", should fit */ + _exit(EXIT_SUCCESS); +} + +TEST(rename_process) { + test_rename_process_one("foo", 1); /* should always fit */ + test_rename_process_one("this is a really really long process name, followed by some more words", 0); /* unlikely to fit */ + test_rename_process_one("1234567", 1); /* should always fit */ +} + +static int intro(void) { + log_show_color(true); + return EXIT_SUCCESS; +} + +DEFINE_TEST_MAIN_WITH_INTRO(LOG_INFO, intro); diff --git a/src/test/test-async.c b/src/test/test-async.c index 8eefad5044..b97fedcfc6 100644 --- a/src/test/test-async.c +++ b/src/test/test-async.c @@ -6,7 +6,6 @@ #include "async.h" #include "macro.h" #include "tmpfile-util.h" -#include "util.h" static bool test_async = false; diff --git a/src/test/test-barrier.c b/src/test/test-barrier.c index 50ceb3a355..b255dba068 100644 --- a/src/test/test-barrier.c +++ b/src/test/test-barrier.c @@ -18,7 +18,6 @@ #include "errno-util.h" #include "tests.h" #include "time-util.h" -#include "util.h" #include "virt.h" /* 20ms to test deadlocks; All timings use multiples of this constant as diff --git a/src/test/test-boot-timestamps.c b/src/test/test-boot-timestamps.c index a9875defdd..53e378eaab 100644 --- a/src/test/test-boot-timestamps.c +++ b/src/test/test-boot-timestamps.c @@ -9,7 +9,6 @@ #include "errno-util.h" #include "log.h" #include "tests.h" -#include "util.h" static int test_acpi_fpdt(void) { usec_t loader_start, loader_exit; diff --git a/src/test/test-btrfs.c b/src/test/test-btrfs.c index 77ec801903..67acba23a7 100644 --- a/src/test/test-btrfs.c +++ b/src/test/test-btrfs.c @@ -8,7 +8,6 @@ #include "format-util.h" #include "log.h" #include "string-util.h" -#include "util.h" int main(int argc, char *argv[]) { BtrfsQuotaInfo quota; diff --git a/src/test/test-cap-list.c b/src/test/test-cap-list.c index 38f7420324..68f0461a62 100644 --- a/src/test/test-cap-list.c +++ b/src/test/test-cap-list.c @@ -9,7 +9,6 @@ #include "parse-util.h" #include "string-util.h" #include "tests.h" -#include "util.h" /* verify the capability parser */ TEST(cap_list) { diff --git a/src/test/test-cgroup-util.c b/src/test/test-cgroup-util.c index 7113b07a95..0b286ed8e4 100644 --- a/src/test/test-cgroup-util.c +++ b/src/test/test-cgroup-util.c @@ -15,7 +15,6 @@ #include "strv.h" #include "tests.h" #include "user-util.h" -#include "util.h" #include "version.h" static void check_p_d_u(const char *path, int code, const char *result) { diff --git a/src/test/test-conf-files.c b/src/test/test-conf-files.c index da8f3a97f2..beda749fb8 100644 --- a/src/test/test-conf-files.c +++ b/src/test/test-conf-files.c @@ -19,7 +19,6 @@ #include "strv.h" #include "tests.h" #include "user-util.h" -#include "util.h" static void setup_test_dir(char *tmp_dir, const char *files, ...) { va_list ap; diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index 8c27dcac3f..0acb4131b5 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -9,7 +9,6 @@ #include "strv.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" static void test_config_parse_path_one(const char *rvalue, const char *expected) { _cleanup_free_ char *path = NULL; diff --git a/src/test/test-copy.c b/src/test/test-copy.c index 4091b425d1..e4e38ac731 100644 --- a/src/test/test-copy.c +++ b/src/test/test-copy.c @@ -20,7 +20,6 @@ #include "tests.h" #include "tmpfile-util.h" #include "user-util.h" -#include "util.h" #include "xattr-util.h" TEST(copy_file) { diff --git a/src/test/test-ellipsize.c b/src/test/test-ellipsize.c index 7317193363..2b27b44efb 100644 --- a/src/test/test-ellipsize.c +++ b/src/test/test-ellipsize.c @@ -3,12 +3,11 @@ #include <stdio.h> #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "string-util.h" #include "strv.h" #include "terminal-util.h" #include "tests.h" -#include "util.h" #include "utf8.h" static void test_ellipsize_mem_one(const char *s, size_t old_length, size_t new_length) { diff --git a/src/test/test-env-util.c b/src/test/test-env-util.c index cc37d96327..4796e3c208 100644 --- a/src/test/test-env-util.c +++ b/src/test/test-env-util.c @@ -10,7 +10,6 @@ #include "string-util.h" #include "strv.h" #include "tests.h" -#include "util.h" TEST(strv_env_delete) { _cleanup_strv_free_ char **a = NULL, **b = NULL, **c = NULL, **d = NULL; diff --git a/src/test/test-errno-list.c b/src/test/test-errno-list.c index 6c8f384cab..f91a1f770f 100644 --- a/src/test/test-errno-list.c +++ b/src/test/test-errno-list.c @@ -7,7 +7,6 @@ #include "macro.h" #include "string-util.h" #include "tests.h" -#include "util.h" TEST(errno_list) { for (size_t i = 0; i < ELEMENTSOF(errno_names); i++) { diff --git a/src/test/test-errno-util.c b/src/test/test-errno-util.c index f858927c92..d3d022c33f 100644 --- a/src/test/test-errno-util.c +++ b/src/test/test-errno-util.c @@ -47,4 +47,35 @@ TEST(STRERROR_OR_ELSE) { log_info("STRERROR_OR_ELSE(-EPERM, \"EOF\") → %s", STRERROR_OR_EOF(-EPERM)); } +TEST(PROTECT_ERRNO) { + errno = 12; + { + PROTECT_ERRNO; + errno = 11; + } + assert_se(errno == 12); +} + +static void test_unprotect_errno_inner_function(void) { + PROTECT_ERRNO; + + errno = 2222; +} + +TEST(UNPROTECT_ERRNO) { + errno = 4711; + + PROTECT_ERRNO; + + errno = 815; + + UNPROTECT_ERRNO; + + assert_se(errno == 4711); + + test_unprotect_errno_inner_function(); + + assert_se(errno == 4711); +} + DEFINE_TEST_MAIN(LOG_INFO); diff --git a/src/test/test-exec-util.c b/src/test/test-exec-util.c index bae06a81ad..2304f6a8b6 100644 --- a/src/test/test-exec-util.c +++ b/src/test/test-exec-util.c @@ -7,7 +7,7 @@ #include "alloc-util.h" #include "copy.h" -#include "def.h" +#include "constants.h" #include "env-util.h" #include "exec-util.h" #include "fd-util.h" diff --git a/src/test/test-execute.c b/src/test/test-execute.c index 0283caeca6..51c3e755e0 100644 --- a/src/test/test-execute.c +++ b/src/test/test-execute.c @@ -32,7 +32,6 @@ #include "tmpfile-util.h" #include "unit.h" #include "user-util.h" -#include "util.h" #include "virt.h" static char *user_runtime_unit_dir = NULL; diff --git a/src/test/test-fdset.c b/src/test/test-fdset.c index 5d63eeee37..b6ad290eef 100644 --- a/src/test/test-fdset.c +++ b/src/test/test-fdset.c @@ -8,7 +8,6 @@ #include "macro.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" TEST(fdset_new_fill) { int fd = -1; diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index ba6dd9ace9..6f27cd43d6 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -24,7 +24,6 @@ #include "strv.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" TEST(parse_env_file) { _cleanup_(unlink_tempfilep) char diff --git a/src/test/test-fs-util.c b/src/test/test-fs-util.c index 9c1ced7591..d0259843b6 100644 --- a/src/test/test-fs-util.c +++ b/src/test/test-fs-util.c @@ -22,7 +22,6 @@ #include "tmpfile-util.h" #include "umask-util.h" #include "user-util.h" -#include "util.h" #include "virt.h" static const char *arg_test_dir = NULL; diff --git a/src/test/test-gpt.c b/src/test/test-gpt.c index 5037f498bb..8c313c66cc 100644 --- a/src/test/test-gpt.c +++ b/src/test/test-gpt.c @@ -8,7 +8,6 @@ #include "strv.h" #include "terminal-util.h" #include "tests.h" -#include "util.h" TEST(gpt_types_against_architectures) { int r; diff --git a/src/test/test-hashmap.c b/src/test/test-hashmap.c index dbf762cc0b..5daa0e64f6 100644 --- a/src/test/test-hashmap.c +++ b/src/test/test-hashmap.c @@ -3,7 +3,6 @@ #include "hashmap.h" #include "string-util.h" #include "tests.h" -#include "util.h" unsigned custom_counter = 0; static void custom_destruct(void* p) { diff --git a/src/test/test-json.c b/src/test/test-json.c index 946c827ccf..17ad2017f8 100644 --- a/src/test/test-json.c +++ b/src/test/test-json.c @@ -12,7 +12,6 @@ #include "string-util.h" #include "strv.h" #include "tests.h" -#include "util.h" static void test_tokenizer_one(const char *data, ...) { unsigned line = 0, column = 0; diff --git a/src/test/test-limits-util.c b/src/test/test-limits-util.c new file mode 100644 index 0000000000..3b6c8c0224 --- /dev/null +++ b/src/test/test-limits-util.c @@ -0,0 +1,89 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "format-util.h" +#include "limits-util.h" +#include "tests.h" + +TEST(physical_memory) { + uint64_t p; + + p = physical_memory(); + assert_se(p > 0); + assert_se(p < UINT64_MAX); + assert_se(p % page_size() == 0); + + log_info("Memory: %s (%" PRIu64 ")", FORMAT_BYTES(p), p); +} + +TEST(physical_memory_scale) { + uint64_t p; + + p = physical_memory(); + + assert_se(physical_memory_scale(0, 100) == 0); + assert_se(physical_memory_scale(100, 100) == p); + + log_info("Memory original: %" PRIu64, physical_memory()); + log_info("Memory scaled by 50%%: %" PRIu64, physical_memory_scale(50, 100)); + log_info("Memory divided by 2: %" PRIu64, physical_memory() / 2); + log_info("Page size: %zu", page_size()); + + /* There might be an uneven number of pages, hence permit these calculations to be half a page off... */ + assert_se(page_size()/2 + physical_memory_scale(50, 100) - p/2 <= page_size()); + assert_se(physical_memory_scale(200, 100) == p*2); + + assert_se(physical_memory_scale(0, 1) == 0); + assert_se(physical_memory_scale(1, 1) == p); + assert_se(physical_memory_scale(2, 1) == p*2); + + assert_se(physical_memory_scale(0, 2) == 0); + + assert_se(page_size()/2 + physical_memory_scale(1, 2) - p/2 <= page_size()); + assert_se(physical_memory_scale(2, 2) == p); + assert_se(physical_memory_scale(4, 2) == p*2); + + assert_se(physical_memory_scale(0, UINT32_MAX) == 0); + assert_se(physical_memory_scale(UINT32_MAX, UINT32_MAX) == p); + + /* overflow */ + assert_se(physical_memory_scale(UINT64_MAX/4, UINT64_MAX) == UINT64_MAX); +} + +TEST(system_tasks_max) { + uint64_t t; + + t = system_tasks_max(); + assert_se(t > 0); + assert_se(t < UINT64_MAX); + + log_info("Max tasks: %" PRIu64, t); +} + +TEST(system_tasks_max_scale) { + uint64_t t; + + t = system_tasks_max(); + + assert_se(system_tasks_max_scale(0, 100) == 0); + assert_se(system_tasks_max_scale(100, 100) == t); + + assert_se(system_tasks_max_scale(0, 1) == 0); + assert_se(system_tasks_max_scale(1, 1) == t); + assert_se(system_tasks_max_scale(2, 1) == 2*t); + + assert_se(system_tasks_max_scale(0, 2) == 0); + assert_se(system_tasks_max_scale(1, 2) == t/2); + assert_se(system_tasks_max_scale(2, 2) == t); + assert_se(system_tasks_max_scale(3, 2) == (3*t)/2); + assert_se(system_tasks_max_scale(4, 2) == t*2); + + assert_se(system_tasks_max_scale(0, UINT32_MAX) == 0); + assert_se(system_tasks_max_scale((UINT32_MAX-1)/2, UINT32_MAX-1) == t/2); + assert_se(system_tasks_max_scale(UINT32_MAX, UINT32_MAX) == t); + + /* overflow */ + + assert_se(system_tasks_max_scale(UINT64_MAX/4, UINT64_MAX) == UINT64_MAX); +} + +DEFINE_TEST_MAIN(LOG_INFO); diff --git a/src/test/test-list.c b/src/test/test-list.c index 2c764d7b71..ea45f5b95c 100644 --- a/src/test/test-list.c +++ b/src/test/test-list.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "list.h" -#include "util.h" int main(int argc, const char *argv[]) { size_t i; diff --git a/src/test/test-locale-util.c b/src/test/test-locale-util.c index 9f50c6227f..aa501b650a 100644 --- a/src/test/test-locale-util.c +++ b/src/test/test-locale-util.c @@ -6,7 +6,6 @@ #include "macro.h" #include "strv.h" #include "tests.h" -#include "util.h" TEST(get_locales) { _cleanup_strv_free_ char **locales = NULL; diff --git a/src/test/test-log.c b/src/test/test-log.c index ae3d073d82..f21d88f39a 100644 --- a/src/test/test-log.c +++ b/src/test/test-log.c @@ -7,7 +7,6 @@ #include "log.h" #include "process-util.h" #include "string-util.h" -#include "util.h" assert_cc(IS_SYNTHETIC_ERRNO(SYNTHETIC_ERRNO(EINVAL))); assert_cc(!IS_SYNTHETIC_ERRNO(EINVAL)); diff --git a/src/test/test-logarithm.c b/src/test/test-logarithm.c new file mode 100644 index 0000000000..b6818b422c --- /dev/null +++ b/src/test/test-logarithm.c @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "logarithm.h" +#include "tests.h" + +TEST(LOG2ULL) { + assert_se(LOG2ULL(0) == 0); + assert_se(LOG2ULL(1) == 0); + assert_se(LOG2ULL(8) == 3); + assert_se(LOG2ULL(9) == 3); + assert_se(LOG2ULL(15) == 3); + assert_se(LOG2ULL(16) == 4); + assert_se(LOG2ULL(1024*1024) == 20); + assert_se(LOG2ULL(1024*1024+5) == 20); +} + +TEST(CONST_LOG2ULL) { + assert_se(CONST_LOG2ULL(0) == 0); + assert_se(CONST_LOG2ULL(1) == 0); + assert_se(CONST_LOG2ULL(8) == 3); + assert_se(CONST_LOG2ULL(9) == 3); + assert_se(CONST_LOG2ULL(15) == 3); + assert_se(CONST_LOG2ULL(16) == 4); + assert_se(CONST_LOG2ULL(1024*1024) == 20); + assert_se(CONST_LOG2ULL(1024*1024+5) == 20); +} + +TEST(NONCONST_LOG2ULL) { + assert_se(NONCONST_LOG2ULL(0) == 0); + assert_se(NONCONST_LOG2ULL(1) == 0); + assert_se(NONCONST_LOG2ULL(8) == 3); + assert_se(NONCONST_LOG2ULL(9) == 3); + assert_se(NONCONST_LOG2ULL(15) == 3); + assert_se(NONCONST_LOG2ULL(16) == 4); + assert_se(NONCONST_LOG2ULL(1024*1024) == 20); + assert_se(NONCONST_LOG2ULL(1024*1024+5) == 20); +} + +TEST(log2u64) { + assert_se(log2u64(0) == 0); + assert_se(log2u64(1) == 0); + assert_se(log2u64(8) == 3); + assert_se(log2u64(9) == 3); + assert_se(log2u64(15) == 3); + assert_se(log2u64(16) == 4); + assert_se(log2u64(1024*1024) == 20); + assert_se(log2u64(1024*1024+5) == 20); +} + +TEST(log2u) { + assert_se(log2u(0) == 0); + assert_se(log2u(1) == 0); + assert_se(log2u(2) == 1); + assert_se(log2u(3) == 1); + assert_se(log2u(4) == 2); + assert_se(log2u(32) == 5); + assert_se(log2u(33) == 5); + assert_se(log2u(63) == 5); + assert_se(log2u(INT_MAX) == sizeof(int)*8-2); +} + +TEST(log2i) { + assert_se(log2i(0) == 0); + assert_se(log2i(1) == 0); + assert_se(log2i(2) == 1); + assert_se(log2i(3) == 1); + assert_se(log2i(4) == 2); + assert_se(log2i(32) == 5); + assert_se(log2i(33) == 5); + assert_se(log2i(63) == 5); + assert_se(log2i(INT_MAX) == sizeof(int)*8-2); +} + +DEFINE_TEST_MAIN(LOG_INFO); diff --git a/src/test/test-memory-util.c b/src/test/test-memory-util.c new file mode 100644 index 0000000000..241f46c0d0 --- /dev/null +++ b/src/test/test-memory-util.c @@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include "memory-util.h" +#include "tests.h" + +TEST(eqzero) { + const uint32_t zeros[] = {0, 0, 0}; + const uint32_t ones[] = {1, 1}; + const uint32_t mixed[] = {0, 1, 0, 0, 0}; + const uint8_t longer[] = {[55] = 255}; + + assert_se(eqzero(zeros)); + assert_se(!eqzero(ones)); + assert_se(!eqzero(mixed)); + assert_se(!eqzero(longer)); +} + +DEFINE_TEST_MAIN(LOG_INFO); diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index 391e1c97ba..ccf18ecd9c 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -5,7 +5,7 @@ #include <unistd.h> #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "fd-util.h" #include "fileio.h" #include "hashmap.h" diff --git a/src/test/test-namespace.c b/src/test/test-namespace.c index 37acc782eb..e4d763ecd5 100644 --- a/src/test/test-namespace.c +++ b/src/test/test-namespace.c @@ -11,7 +11,6 @@ #include "string-util.h" #include "tests.h" #include "user-util.h" -#include "util.h" #include "virt.h" TEST(namespace_cleanup_tmpdir) { diff --git a/src/test/test-netlink-manual.c b/src/test/test-netlink-manual.c index 49aca68c49..6543c617c8 100644 --- a/src/test/test-netlink-manual.c +++ b/src/test/test-netlink-manual.c @@ -11,7 +11,6 @@ #include "macro.h" #include "module-util.h" #include "tests.h" -#include "util.h" static int load_module(const char *mod_name) { _cleanup_(kmod_unrefp) struct kmod_ctx *ctx = NULL; diff --git a/src/test/test-path-util.c b/src/test/test-path-util.c index f398761982..06b9793fe3 100644 --- a/src/test/test-path-util.c +++ b/src/test/test-path-util.c @@ -16,7 +16,6 @@ #include "strv.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" TEST(print_paths) { log_info("DEFAULT_PATH=%s", DEFAULT_PATH); diff --git a/src/test/test-path.c b/src/test/test-path.c index 4066f6ad93..f325b4e51a 100644 --- a/src/test/test-path.c +++ b/src/test/test-path.c @@ -17,7 +17,6 @@ #include "strv.h" #include "tests.h" #include "unit.h" -#include "util.h" typedef void (*test_function_t)(Manager *m); diff --git a/src/test/test-proc-cmdline.c b/src/test/test-proc-cmdline.c index 1f43bb3eb0..1d54066ae6 100644 --- a/src/test/test-proc-cmdline.c +++ b/src/test/test-proc-cmdline.c @@ -3,13 +3,13 @@ #include "alloc-util.h" #include "env-util.h" #include "errno-util.h" +#include "initrd-util.h" #include "log.h" #include "macro.h" #include "proc-cmdline.h" #include "special.h" #include "string-util.h" #include "tests.h" -#include "util.h" static int obj; diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c index 990eb1e2b6..7e4b5d8255 100644 --- a/src/test/test-process-util.c +++ b/src/test/test-process-util.c @@ -34,7 +34,6 @@ #include "terminal-util.h" #include "tests.h" #include "user-util.h" -#include "util.h" #include "virt.h" static void test_get_process_comm_one(pid_t pid) { @@ -524,108 +523,6 @@ TEST(get_process_cmdline_harder) { _exit(EXIT_SUCCESS); } -static void test_rename_process_now(const char *p, int ret) { - _cleanup_free_ char *comm = NULL, *cmdline = NULL; - int r; - - log_info("/* %s(%s) */", __func__, p); - - r = rename_process(p); - assert_se(r == ret || - (ret == 0 && r >= 0) || - (ret > 0 && r > 0)); - - log_debug_errno(r, "rename_process(%s): %m", p); - - if (r < 0) - return; - -#if HAVE_VALGRIND_VALGRIND_H - /* see above, valgrind is weird, we can't verify what we are doing here */ - if (RUNNING_ON_VALGRIND) - return; -#endif - - assert_se(get_process_comm(0, &comm) >= 0); - log_debug("comm = <%s>", comm); - assert_se(strneq(comm, p, TASK_COMM_LEN-1)); - /* We expect comm to be at most 16 bytes (TASK_COMM_LEN). The kernel may raise this limit in the - * future. We'd only check the initial part, at least until we recompile, but this will still pass. */ - - r = get_process_cmdline(0, SIZE_MAX, 0, &cmdline); - assert_se(r >= 0); - /* we cannot expect cmdline to be renamed properly without privileges */ - if (geteuid() == 0) { - if (r == 0 && detect_container() > 0) - log_info("cmdline = <%s> (not verified, Running in unprivileged container?)", cmdline); - else { - log_info("cmdline = <%s> (expected <%.*s>)", cmdline, (int) strlen("test-process-util"), p); - - bool skip = cmdline[0] == '"'; /* A shortcut to check if the string is quoted */ - - assert_se(strneq(cmdline + skip, p, strlen("test-process-util"))); - assert_se(startswith(cmdline + skip, p)); - } - } else - log_info("cmdline = <%s> (not verified)", cmdline); -} - -static void test_rename_process_one(const char *p, int ret) { - siginfo_t si; - pid_t pid; - - log_info("/* %s(%s) */", __func__, p); - - pid = fork(); - assert_se(pid >= 0); - - if (pid == 0) { - /* child */ - test_rename_process_now(p, ret); - _exit(EXIT_SUCCESS); - } - - assert_se(wait_for_terminate(pid, &si) >= 0); - assert_se(si.si_code == CLD_EXITED); - assert_se(si.si_status == EXIT_SUCCESS); -} - -TEST(rename_process_invalid) { - assert_se(rename_process(NULL) == -EINVAL); - assert_se(rename_process("") == -EINVAL); -} - -TEST(rename_process_multi) { - pid_t pid; - - pid = fork(); - assert_se(pid >= 0); - - if (pid > 0) { - siginfo_t si; - - assert_se(wait_for_terminate(pid, &si) >= 0); - assert_se(si.si_code == CLD_EXITED); - assert_se(si.si_status == EXIT_SUCCESS); - - return; - } - - /* child */ - test_rename_process_now("one", 1); - test_rename_process_now("more", 0); /* longer than "one", hence truncated */ - (void) setresuid(99, 99, 99); /* change uid when running privileged */ - test_rename_process_now("time!", 0); - test_rename_process_now("0", 1); /* shorter than "one", should fit */ - _exit(EXIT_SUCCESS); -} - -TEST(rename_process) { - test_rename_process_one("foo", 1); /* should always fit */ - test_rename_process_one("this is a really really long process name, followed by some more words", 0); /* unlikely to fit */ - test_rename_process_one("1234567", 1); /* should always fit */ -} - TEST(getpid_cached) { siginfo_t si; pid_t a, b, c, d, e, f, child; diff --git a/src/test/test-raw-clone.c b/src/test/test-raw-clone.c new file mode 100644 index 0000000000..23ec7d1aa0 --- /dev/null +++ b/src/test/test-raw-clone.c @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ + +#include <sys/wait.h> +#include <unistd.h> + +#include "errno-util.h" +#include "format-util.h" +#include "missing_syscall.h" +#include "raw-clone.h" +#include "tests.h" + +TEST(raw_clone) { + pid_t parent, pid, pid2; + + parent = getpid(); + log_info("before clone: getpid()→"PID_FMT, parent); + assert_se(raw_getpid() == parent); + + pid = raw_clone(0); + assert_se(pid >= 0); + + pid2 = raw_getpid(); + log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" raw_getpid()→"PID_FMT, + pid, getpid(), pid2); + if (pid == 0) { + assert_se(pid2 != parent); + _exit(EXIT_SUCCESS); + } else { + int status; + + assert_se(pid2 == parent); + waitpid(pid, &status, __WCLONE); + assert_se(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); + } + + errno = 0; + assert_se(raw_clone(CLONE_FS|CLONE_NEWNS) == -1); + assert_se(errno == EINVAL || ERRNO_IS_PRIVILEGE(errno)); /* Certain container environments prohibit namespaces to us, don't fail in that case */ +} + +DEFINE_TEST_MAIN(LOG_INFO); diff --git a/src/test/test-selinux.c b/src/test/test-selinux.c index 3eb7ad30cf..717cb0db16 100644 --- a/src/test/test-selinux.c +++ b/src/test/test-selinux.c @@ -9,7 +9,6 @@ #include "string-util.h" #include "tests.h" #include "time-util.h" -#include "util.h" static void test_testing(void) { bool b; diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index 799e93dced..de64f920d1 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -15,7 +15,6 @@ #include "sleep-config.h" #include "strv.h" #include "tests.h" -#include "util.h" TEST(parse_sleep_config) { _cleanup_(free_sleep_configp) SleepConfig *sleep_config = NULL; diff --git a/src/test/test-strbuf.c b/src/test/test-strbuf.c index 9233c63f90..5c12a0597a 100644 --- a/src/test/test-strbuf.c +++ b/src/test/test-strbuf.c @@ -6,7 +6,6 @@ #include "string-util.h" #include "strv.h" #include "tests.h" -#include "util.h" static ssize_t add_string(struct strbuf *sb, const char *s) { return strbuf_add_string(sb, s, strlen(s)); diff --git a/src/test/test-string-util.c b/src/test/test-string-util.c index d0a2272794..4047139c26 100644 --- a/src/test/test-string-util.c +++ b/src/test/test-string-util.c @@ -9,7 +9,6 @@ #include "strv.h" #include "tests.h" #include "utf8.h" -#include "util.h" TEST(string_erase) { char *x; diff --git a/src/test/test-strip-tab-ansi.c b/src/test/test-strip-tab-ansi.c index 5152cf2cf8..6f73d2686d 100644 --- a/src/test/test-strip-tab-ansi.c +++ b/src/test/test-strip-tab-ansi.c @@ -7,7 +7,6 @@ #include "string-util.h" #include "terminal-util.h" #include "tests.h" -#include "util.h" TEST(strip_tab_ansi) { _cleanup_free_ char *urlified = NULL, *q = NULL, *qq = NULL; diff --git a/src/test/test-strxcpyx.c b/src/test/test-strxcpyx.c index dd8dbdea61..b679522fc6 100644 --- a/src/test/test-strxcpyx.c +++ b/src/test/test-strxcpyx.c @@ -5,7 +5,6 @@ #include "string-util.h" #include "strxcpyx.h" #include "tests.h" -#include "util.h" TEST(strpcpy) { char target[25]; diff --git a/src/test/test-tables.c b/src/test/test-tables.c index 30ca1871cb..6301dedb09 100644 --- a/src/test/test-tables.c +++ b/src/test/test-tables.c @@ -36,7 +36,6 @@ #include "timer.h" #include "unit-name.h" #include "unit.h" -#include "util.h" #include "virt.h" int main(int argc, char **argv) { diff --git a/src/test/test-terminal-util.c b/src/test/test-terminal-util.c index 292e5348bc..8d0e452038 100644 --- a/src/test/test-terminal-util.c +++ b/src/test/test-terminal-util.c @@ -14,7 +14,6 @@ #include "terminal-util.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" #define LOREM_IPSUM "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor " \ "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation " \ diff --git a/src/test/test-tmpfiles.c b/src/test/test-tmpfiles.c index f26701767f..c58ac933bb 100644 --- a/src/test/test-tmpfiles.c +++ b/src/test/test-tmpfiles.c @@ -15,7 +15,6 @@ #include "string-util.h" #include "tests.h" #include "tmpfile-util.h" -#include "util.h" TEST(tmpfiles) { _cleanup_free_ char *cmd = NULL, *cmd2 = NULL, *ans = NULL, *ans2 = NULL, *d = NULL, *tmp = NULL, *line = NULL; diff --git a/src/test/test-uid-range.c b/src/test/test-uid-range.c index ce8b8e4bca..c759573173 100644 --- a/src/test/test-uid-range.c +++ b/src/test/test-uid-range.c @@ -11,7 +11,6 @@ #include "tmpfile-util.h" #include "uid-range.h" #include "user-util.h" -#include "util.h" #include "virt.h" TEST(uid_range) { diff --git a/src/test/test-unit-file.c b/src/test/test-unit-file.c index dffa2822e6..27a73d61a0 100644 --- a/src/test/test-unit-file.c +++ b/src/test/test-unit-file.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "initrd-util.h" #include "path-lookup.h" #include "set.h" #include "special.h" diff --git a/src/test/test-unit-name.c b/src/test/test-unit-name.c index 43fdb15d1c..98fffc7c87 100644 --- a/src/test/test-unit-name.c +++ b/src/test/test-unit-name.c @@ -22,7 +22,6 @@ #include "unit-printf.h" #include "unit.h" #include "user-util.h" -#include "util.h" static char *runtime_dir = NULL; diff --git a/src/test/test-utf8.c b/src/test/test-utf8.c index f070c171fe..7ba0cb7dd2 100644 --- a/src/test/test-utf8.c +++ b/src/test/test-utf8.c @@ -5,7 +5,6 @@ #include "strv.h" #include "tests.h" #include "utf8.h" -#include "util.h" TEST(utf8_is_printable) { assert_se(utf8_is_printable("ascii is valid\tunicode", 22)); diff --git a/src/test/test-util.c b/src/test/test-util.c deleted file mode 100644 index 21ab016c22..0000000000 --- a/src/test/test-util.c +++ /dev/null @@ -1,242 +0,0 @@ -/* SPDX-License-Identifier: LGPL-2.1-or-later */ - -#include <errno.h> -#include <sys/wait.h> -#include <unistd.h> - -#include "fileio.h" -#include "fs-util.h" -#include "limits-util.h" -#include "memory-util.h" -#include "missing_syscall.h" -#include "parse-util.h" -#include "process-util.h" -#include "raw-clone.h" -#include "rm-rf.h" -#include "string-util.h" -#include "tests.h" -#include "util.h" - -TEST(LOG2ULL) { - assert_se(LOG2ULL(0) == 0); - assert_se(LOG2ULL(1) == 0); - assert_se(LOG2ULL(8) == 3); - assert_se(LOG2ULL(9) == 3); - assert_se(LOG2ULL(15) == 3); - assert_se(LOG2ULL(16) == 4); - assert_se(LOG2ULL(1024*1024) == 20); - assert_se(LOG2ULL(1024*1024+5) == 20); -} - -TEST(CONST_LOG2ULL) { - assert_se(CONST_LOG2ULL(0) == 0); - assert_se(CONST_LOG2ULL(1) == 0); - assert_se(CONST_LOG2ULL(8) == 3); - assert_se(CONST_LOG2ULL(9) == 3); - assert_se(CONST_LOG2ULL(15) == 3); - assert_se(CONST_LOG2ULL(16) == 4); - assert_se(CONST_LOG2ULL(1024*1024) == 20); - assert_se(CONST_LOG2ULL(1024*1024+5) == 20); -} - -TEST(NONCONST_LOG2ULL) { - assert_se(NONCONST_LOG2ULL(0) == 0); - assert_se(NONCONST_LOG2ULL(1) == 0); - assert_se(NONCONST_LOG2ULL(8) == 3); - assert_se(NONCONST_LOG2ULL(9) == 3); - assert_se(NONCONST_LOG2ULL(15) == 3); - assert_se(NONCONST_LOG2ULL(16) == 4); - assert_se(NONCONST_LOG2ULL(1024*1024) == 20); - assert_se(NONCONST_LOG2ULL(1024*1024+5) == 20); -} - -TEST(log2u64) { - assert_se(log2u64(0) == 0); - assert_se(log2u64(1) == 0); - assert_se(log2u64(8) == 3); - assert_se(log2u64(9) == 3); - assert_se(log2u64(15) == 3); - assert_se(log2u64(16) == 4); - assert_se(log2u64(1024*1024) == 20); - assert_se(log2u64(1024*1024+5) == 20); -} - -TEST(log2u) { - assert_se(log2u(0) == 0); - assert_se(log2u(1) == 0); - assert_se(log2u(2) == 1); - assert_se(log2u(3) == 1); - assert_se(log2u(4) == 2); - assert_se(log2u(32) == 5); - assert_se(log2u(33) == 5); - assert_se(log2u(63) == 5); - assert_se(log2u(INT_MAX) == sizeof(int)*8-2); -} - -TEST(log2i) { - assert_se(log2i(0) == 0); - assert_se(log2i(1) == 0); - assert_se(log2i(2) == 1); - assert_se(log2i(3) == 1); - assert_se(log2i(4) == 2); - assert_se(log2i(32) == 5); - assert_se(log2i(33) == 5); - assert_se(log2i(63) == 5); - assert_se(log2i(INT_MAX) == sizeof(int)*8-2); -} - -TEST(protect_errno) { - errno = 12; - { - PROTECT_ERRNO; - errno = 11; - } - assert_se(errno == 12); -} - -static void test_unprotect_errno_inner_function(void) { - PROTECT_ERRNO; - - errno = 2222; -} - -TEST(unprotect_errno) { - errno = 4711; - - PROTECT_ERRNO; - - errno = 815; - - UNPROTECT_ERRNO; - - assert_se(errno == 4711); - - test_unprotect_errno_inner_function(); - - assert_se(errno == 4711); -} - -TEST(eqzero) { - const uint32_t zeros[] = {0, 0, 0}; - const uint32_t ones[] = {1, 1}; - const uint32_t mixed[] = {0, 1, 0, 0, 0}; - const uint8_t longer[] = {[55] = 255}; - - assert_se(eqzero(zeros)); - assert_se(!eqzero(ones)); - assert_se(!eqzero(mixed)); - assert_se(!eqzero(longer)); -} - -TEST(raw_clone) { - pid_t parent, pid, pid2; - - parent = getpid(); - log_info("before clone: getpid()→"PID_FMT, parent); - assert_se(raw_getpid() == parent); - - pid = raw_clone(0); - assert_se(pid >= 0); - - pid2 = raw_getpid(); - log_info("raw_clone: "PID_FMT" getpid()→"PID_FMT" raw_getpid()→"PID_FMT, - pid, getpid(), pid2); - if (pid == 0) { - assert_se(pid2 != parent); - _exit(EXIT_SUCCESS); - } else { - int status; - - assert_se(pid2 == parent); - waitpid(pid, &status, __WCLONE); - assert_se(WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS); - } - - errno = 0; - assert_se(raw_clone(CLONE_FS|CLONE_NEWNS) == -1); - assert_se(errno == EINVAL || ERRNO_IS_PRIVILEGE(errno)); /* Certain container environments prohibit namespaces to us, don't fail in that case */ -} - -TEST(physical_memory) { - uint64_t p; - - p = physical_memory(); - assert_se(p > 0); - assert_se(p < UINT64_MAX); - assert_se(p % page_size() == 0); - - log_info("Memory: %s (%" PRIu64 ")", FORMAT_BYTES(p), p); -} - -TEST(physical_memory_scale) { - uint64_t p; - - p = physical_memory(); - - assert_se(physical_memory_scale(0, 100) == 0); - assert_se(physical_memory_scale(100, 100) == p); - - log_info("Memory original: %" PRIu64, physical_memory()); - log_info("Memory scaled by 50%%: %" PRIu64, physical_memory_scale(50, 100)); - log_info("Memory divided by 2: %" PRIu64, physical_memory() / 2); - log_info("Page size: %zu", page_size()); - - /* There might be an uneven number of pages, hence permit these calculations to be half a page off... */ - assert_se(page_size()/2 + physical_memory_scale(50, 100) - p/2 <= page_size()); - assert_se(physical_memory_scale(200, 100) == p*2); - - assert_se(physical_memory_scale(0, 1) == 0); - assert_se(physical_memory_scale(1, 1) == p); - assert_se(physical_memory_scale(2, 1) == p*2); - - assert_se(physical_memory_scale(0, 2) == 0); - - assert_se(page_size()/2 + physical_memory_scale(1, 2) - p/2 <= page_size()); - assert_se(physical_memory_scale(2, 2) == p); - assert_se(physical_memory_scale(4, 2) == p*2); - - assert_se(physical_memory_scale(0, UINT32_MAX) == 0); - assert_se(physical_memory_scale(UINT32_MAX, UINT32_MAX) == p); - - /* overflow */ - assert_se(physical_memory_scale(UINT64_MAX/4, UINT64_MAX) == UINT64_MAX); -} - -TEST(system_tasks_max) { - uint64_t t; - - t = system_tasks_max(); - assert_se(t > 0); - assert_se(t < UINT64_MAX); - - log_info("Max tasks: %" PRIu64, t); -} - -TEST(system_tasks_max_scale) { - uint64_t t; - - t = system_tasks_max(); - - assert_se(system_tasks_max_scale(0, 100) == 0); - assert_se(system_tasks_max_scale(100, 100) == t); - - assert_se(system_tasks_max_scale(0, 1) == 0); - assert_se(system_tasks_max_scale(1, 1) == t); - assert_se(system_tasks_max_scale(2, 1) == 2*t); - - assert_se(system_tasks_max_scale(0, 2) == 0); - assert_se(system_tasks_max_scale(1, 2) == t/2); - assert_se(system_tasks_max_scale(2, 2) == t); - assert_se(system_tasks_max_scale(3, 2) == (3*t)/2); - assert_se(system_tasks_max_scale(4, 2) == t*2); - - assert_se(system_tasks_max_scale(0, UINT32_MAX) == 0); - assert_se(system_tasks_max_scale((UINT32_MAX-1)/2, UINT32_MAX-1) == t/2); - assert_se(system_tasks_max_scale(UINT32_MAX, UINT32_MAX) == t); - - /* overflow */ - - assert_se(system_tasks_max_scale(UINT64_MAX/4, UINT64_MAX) == UINT64_MAX); -} - -DEFINE_TEST_MAIN(LOG_INFO); diff --git a/src/test/test-xml.c b/src/test/test-xml.c index e69d6d0fe4..5dee5c1bed 100644 --- a/src/test/test-xml.c +++ b/src/test/test-xml.c @@ -4,7 +4,6 @@ #include "alloc-util.h" #include "string-util.h" -#include "util.h" #include "xml.h" static void test_one(const char *data, ...) { diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c index ac4d3dc3ed..e3c722610a 100644 --- a/src/timedate/timedatectl.c +++ b/src/timedate/timedatectl.c @@ -8,6 +8,7 @@ #include "sd-bus.h" +#include "build.h" #include "bus-error.h" #include "bus-locator.h" #include "bus-map-properties.h" @@ -24,7 +25,6 @@ #include "string-table.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" #include "verbs.h" static PagerFlags arg_pager_flags = 0; diff --git a/src/timedate/timedated.c b/src/timedate/timedated.c index 373574cc06..ad483301ef 100644 --- a/src/timedate/timedated.c +++ b/src/timedate/timedated.c @@ -20,7 +20,7 @@ #include "bus-polkit.h" #include "clock-util.h" #include "conf-files.h" -#include "def.h" +#include "constants.h" #include "fd-util.h" #include "fileio-label.h" #include "fileio.h" diff --git a/src/timesync/timesyncd-conf.c b/src/timesync/timesyncd-conf.c index 21fe7daec4..3e6cb43597 100644 --- a/src/timesync/timesyncd-conf.c +++ b/src/timesync/timesyncd-conf.c @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include "alloc-util.h" -#include "def.h" +#include "constants.h" #include "dns-domain.h" #include "extract-word.h" #include "string-util.h" diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index e9fa00aaca..da540856ee 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -22,6 +22,7 @@ #include "fs-util.h" #include "list.h" #include "log.h" +#include "logarithm.h" #include "network-util.h" #include "ratelimit.h" #include "resolve-private.h" @@ -32,7 +33,6 @@ #include "timesyncd-conf.h" #include "timesyncd-manager.h" #include "user-util.h" -#include "util.h" #ifndef ADJ_SETOFFSET #define ADJ_SETOFFSET 0x0100 /* add 'time' to current time */ diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index 784b895577..1fec6d4831 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -20,13 +20,14 @@ #include "acl-util.h" #include "alloc-util.h" #include "btrfs-util.h" +#include "build.h" #include "capability-util.h" #include "chase-symlinks.h" #include "chattr-util.h" #include "conf-files.h" +#include "constants.h" #include "copy.h" #include "creds-util.h" -#include "def.h" #include "devnum-util.h" #include "dirent-util.h" #include "dissect-image.h" diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c index b7d279cc22..c7609d7d79 100644 --- a/src/tty-ask-password-agent/tty-ask-password-agent.c +++ b/src/tty-ask-password-agent/tty-ask-password-agent.c @@ -18,8 +18,9 @@ #include "alloc-util.h" #include "ask-password-api.h" +#include "build.h" #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "dirent-util.h" #include "exit-status.h" #include "fd-util.h" diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index e408725b08..1fbfc58c0d 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -11,8 +11,8 @@ #include "arphrd-util.h" #include "conf-files.h" #include "conf-parser.h" +#include "constants.h" #include "creds-util.h" -#include "def.h" #include "device-private.h" #include "device-util.h" #include "ethtool-util.h" diff --git a/src/udev/test-udev-event.c b/src/udev/test-udev-event.c index b6b2c91b2e..42f435916b 100644 --- a/src/udev/test-udev-event.c +++ b/src/udev/test-udev-event.c @@ -5,7 +5,6 @@ #include "strv.h" #include "tests.h" #include "udev-event.h" -#include "util.h" #define BUF_SIZE 1024 diff --git a/src/udev/udev-builtin-btrfs.c b/src/udev/udev-builtin-btrfs.c index 8cd627807f..faaafb23f6 100644 --- a/src/udev/udev-builtin-btrfs.c +++ b/src/udev/udev-builtin-btrfs.c @@ -11,7 +11,6 @@ #include "string-util.h" #include "strxcpyx.h" #include "udev-builtin.h" -#include "util.h" static int builtin_btrfs(sd_device *dev, sd_netlink **rtnl, int argc, char *argv[], bool test) { struct btrfs_ioctl_vol_args args = {}; diff --git a/src/udev/udev-builtin-input_id.c b/src/udev/udev-builtin-input_id.c index 0742120248..465913ce31 100644 --- a/src/udev/udev-builtin-input_id.c +++ b/src/udev/udev-builtin-input_id.c @@ -19,7 +19,6 @@ #include "stdio-util.h" #include "string-util.h" #include "udev-builtin.h" -#include "util.h" /* we must use this kernel-compatible implementation */ #define BITS_PER_LONG (sizeof(unsigned long) * 8) diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index c8b773611f..625c4faad8 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -18,7 +18,6 @@ #include "socket-util.h" #include "strxcpyx.h" #include "udev-ctrl.h" -#include "util.h" /* wire protocol magic must match */ #define UDEV_CTRL_MAGIC 0xdead1dea diff --git a/src/udev/udev-event.h b/src/udev/udev-event.h index 6d823331aa..c54c7891b6 100644 --- a/src/udev/udev-event.h +++ b/src/udev/udev-event.h @@ -12,7 +12,6 @@ #include "macro.h" #include "udev-rules.h" #include "udev-util.h" -#include "util.h" #define READ_END 0 #define WRITE_END 1 diff --git a/src/udev/udev-rules.c b/src/udev/udev-rules.c index f44a174d1f..5f837f4c31 100644 --- a/src/udev/udev-rules.c +++ b/src/udev/udev-rules.c @@ -6,7 +6,7 @@ #include "architecture.h" #include "conf-files.h" #include "conf-parser.h" -#include "def.h" +#include "constants.h" #include "device-private.h" #include "device-util.h" #include "dirent-util.h" diff --git a/src/udev/udevadm-control.c b/src/udev/udevadm-control.c index 06c61e5c07..8dc3a8d955 100644 --- a/src/udev/udevadm-control.c +++ b/src/udev/udevadm-control.c @@ -25,7 +25,6 @@ #include "time-util.h" #include "udevadm.h" #include "udev-ctrl.h" -#include "util.h" #include "virt.h" static int help(void) { diff --git a/src/udev/udevadm-hwdb.c b/src/udev/udevadm-hwdb.c index 972cda129d..a4468cf24f 100644 --- a/src/udev/udevadm-hwdb.c +++ b/src/udev/udevadm-hwdb.c @@ -4,7 +4,6 @@ #include "hwdb-util.h" #include "udevadm.h" -#include "util.h" static const char *arg_test = NULL; static const char *arg_root = NULL; diff --git a/src/udev/udevadm.c b/src/udev/udevadm.c index cd3786b416..b742c1a287 100644 --- a/src/udev/udevadm.c +++ b/src/udev/udevadm.c @@ -14,7 +14,6 @@ #include "udev-util.h" #include "udevadm.h" #include "udevd.h" -#include "util.h" #include "verbs.h" static int help(void) { diff --git a/src/udev/v4l_id/v4l_id.c b/src/udev/v4l_id/v4l_id.c index c2312c7909..13b4839989 100644 --- a/src/udev/v4l_id/v4l_id.c +++ b/src/udev/v4l_id/v4l_id.c @@ -27,7 +27,6 @@ #include <linux/videodev2.h> #include "fd-util.h" -#include "util.h" int main(int argc, char *argv[]) { static const struct option options[] = { diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c index 0995e3557e..675526f3ac 100644 --- a/src/update-utmp/update-utmp.c +++ b/src/update-utmp/update-utmp.c @@ -23,7 +23,6 @@ #include "stdio-util.h" #include "strv.h" #include "unit-name.h" -#include "util.h" #include "utmp-wtmp.h" typedef struct Context { diff --git a/src/userdb/userdbctl.c b/src/userdb/userdbctl.c index 63b0c4dde1..49bdaf666f 100644 --- a/src/userdb/userdbctl.c +++ b/src/userdb/userdbctl.c @@ -3,6 +3,7 @@ #include <getopt.h> #include <utmp.h> +#include "build.h" #include "dirent-util.h" #include "errno-list.h" #include "escape.h" diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c index cdf28ac6ac..98f978df0a 100644 --- a/src/vconsole/vconsole-setup.c +++ b/src/vconsole/vconsole-setup.c @@ -33,7 +33,6 @@ #include "string-util.h" #include "strv.h" #include "terminal-util.h" -#include "util.h" #include "virt.h" static int verify_vc_device(int fd) { |