From c94f6ab1bf659963bd040301cfe24c991b8db069 Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Sat, 3 May 2025 17:59:19 +0200 Subject: [PATCH] string-table: Move more implementation logic into functions Let's move some more implementation logic into functions. We keep the logic that requires the macro in the macro and move the rest into functions. While we're at it, let's also make the parameter declarations of all the string table macros less clausthrophobic. --- src/basic/confidential-virt.c | 1 + src/basic/rlimit-util.c | 1 + src/basic/string-table.c | 56 ++++++++++- src/basic/string-table.h | 123 +++++++++-------------- src/basic/time-util.c | 2 +- src/basic/virt.c | 1 + src/core/kill.c | 1 + src/core/scope.c | 1 + src/creds/creds.c | 1 + src/home/homed-home.c | 1 + src/import/import-compress.c | 1 + src/journal-remote/journal-remote-main.c | 1 + src/journal/journalctl.c | 1 + src/libsystemd/sd-journal/journal-file.c | 1 + src/libsystemd/sd-json/sd-json.c | 1 + src/network/netdev/macsec.c | 1 + src/network/networkd-link.c | 1 + src/repart/repart.c | 1 + src/shared/ask-password-api.c | 1 + src/shared/bootspec.c | 1 + src/shared/bpf-program.c | 1 + src/shared/coredump-util.c | 2 + src/shared/ethtool-util.c | 1 + src/shared/exec-util.c | 2 +- src/shared/firewall-util-nft.c | 1 + src/shared/numa-util.c | 1 + src/shared/parse-argument.c | 1 + src/shared/pe-binary.c | 2 +- src/systemctl/systemctl.c | 1 + src/sysupdate/sysupdated.c | 1 + 30 files changed, 133 insertions(+), 78 deletions(-) diff --git a/src/basic/confidential-virt.c b/src/basic/confidential-virt.c index bb8953bba4..9ca213f30d 100644 --- a/src/basic/confidential-virt.c +++ b/src/basic/confidential-virt.c @@ -16,6 +16,7 @@ #include "fileio.h" #include "log.h" #include "string-table.h" +#include "string-util.h" #include "utf8.h" #if defined(__x86_64__) diff --git a/src/basic/rlimit-util.c b/src/basic/rlimit-util.c index 0032f23c26..d5763b5f9e 100644 --- a/src/basic/rlimit-util.c +++ b/src/basic/rlimit-util.c @@ -10,6 +10,7 @@ #include "format-util.h" #include "log.h" #include "macro.h" +#include "parse-util.h" #include "process-util.h" #include "rlimit-util.h" #include "string-table.h" diff --git a/src/basic/string-table.c b/src/basic/string-table.c index 3a6376714a..8f2b4cb15b 100644 --- a/src/basic/string-table.c +++ b/src/basic/string-table.c @@ -1,9 +1,17 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "parse-util.h" #include "string-table.h" #include "string-util.h" -ssize_t string_table_lookup(const char * const *table, size_t len, const char *key) { +const char* string_table_lookup_to_string(const char * const *table, size_t len, ssize_t i) { + if (i < 0 || i >= (ssize_t) len) + return NULL; + + return table[i]; +} + +ssize_t string_table_lookup_from_string(const char * const *table, size_t len, const char *key) { if (!key) return -EINVAL; @@ -13,3 +21,49 @@ ssize_t string_table_lookup(const char * const *table, size_t len, const char *k return -EINVAL; } + +ssize_t string_table_lookup_from_string_with_boolean(const char * const *table, size_t len, const char *key, ssize_t yes) { + if (!key) + return -EINVAL; + + int b = parse_boolean(key); + if (b == 0) + return 0; + if (b > 0) + return yes; + + return string_table_lookup_from_string(table, len, key); +} + +int string_table_lookup_to_string_fallback(const char * const *table, size_t len, ssize_t i, size_t max, char **ret) { + char *s; + + if (i < 0 || i > (ssize_t) max) + return -ERANGE; + if (i < (ssize_t) len && table[i]) { + s = strdup(table[i]); + if (!s) + return -ENOMEM; + } else if (asprintf(&s, "%zd", i) < 0) + return -ENOMEM; + + *ret = s; + return 0; +} + +ssize_t string_table_lookup_from_string_fallback(const char * const *table, size_t len, const char *s, size_t max) { + unsigned u = 0; + + if (!s) + return -EINVAL; + + ssize_t i = string_table_lookup_from_string(table, len, s); + if (i >= 0) + return i; + if (safe_atou(s, &u) < 0) + return -EINVAL; + if (u > max) + return -EINVAL; + + return u; +} diff --git a/src/basic/string-table.h b/src/basic/string-table.h index 83891eeb73..a1a966beef 100644 --- a/src/basic/string-table.h +++ b/src/basic/string-table.h @@ -2,105 +2,80 @@ #pragma once -#include #include #include #include #include "macro.h" -#include "parse-util.h" -#include "string-util.h" -ssize_t string_table_lookup(const char * const *table, size_t len, const char *key); +const char* string_table_lookup_to_string(const char * const *table, size_t len, ssize_t i); + +ssize_t string_table_lookup_from_string(const char * const *table, size_t len, const char *key); + +ssize_t string_table_lookup_from_string_with_boolean(const char * const *table, size_t len, const char *key, ssize_t yes); + +int string_table_lookup_to_string_fallback(const char * const *table, size_t len, ssize_t i, size_t max, char **ret); + +ssize_t string_table_lookup_from_string_fallback(const char * const *table, size_t len, const char *s, size_t max); /* For basic lookup tables with strictly enumerated entries */ -#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ - scope const char* name##_to_string(type i) { \ - if (i < 0 || i >= (type) ELEMENTSOF(name##_table)) \ - return NULL; \ - return name##_table[i]; \ +#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \ + scope const char* name##_to_string(type i) { \ + return string_table_lookup_to_string(name##_table, ELEMENTSOF(name##_table), i); \ } -#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) \ - scope type name##_from_string(const char *s) { \ - return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \ +#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope) \ + scope type name##_from_string(const char *s) { \ + return (type) string_table_lookup_from_string(name##_table, ELEMENTSOF(name##_table), s); \ } -#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,scope) \ - scope type name##_from_string(const char *s) { \ - if (!s) \ - return -EINVAL; \ - int b = parse_boolean(s); \ - if (b == 0) \ - return (type) 0; \ - if (b > 0) \ - return yes; \ - return (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \ +#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, scope) \ + scope type name##_from_string(const char *s) { \ + return (type) string_table_lookup_from_string_with_boolean(name##_table, ELEMENTSOF(name##_table), s, yes); \ } -#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,scope) \ - scope int name##_to_string_alloc(type i, char **str) { \ - char *s; \ - if (i < 0 || i > max) \ - return -ERANGE; \ - if (i < (type) ELEMENTSOF(name##_table) && name##_table[i]) { \ - s = strdup(name##_table[i]); \ - if (!s) \ - return -ENOMEM; \ - } else if (asprintf(&s, "%i", i) < 0) \ - return -ENOMEM; \ - *str = s; \ - return 0; \ +#define _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max, scope) \ + scope int name##_to_string_alloc(type i, char **ret) { \ + return string_table_lookup_to_string_fallback(name##_table, ELEMENTSOF(name##_table), i, max, ret); \ } -#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,scope) \ - scope type name##_from_string(const char *s) { \ - unsigned u = 0; \ - type i; \ - if (!s) \ - return -EINVAL; \ - i = (type) string_table_lookup(name##_table, ELEMENTSOF(name##_table), s); \ - if (i >= 0) \ - return i; \ - if (safe_atou(s, &u) < 0) \ - return -EINVAL; \ - if (u > max) \ - return -EINVAL; \ - return (type) u; \ +#define _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max, scope) \ + scope type name##_from_string(const char *s) { \ + return (type) string_table_lookup_from_string_fallback(name##_table, ELEMENTSOF(name##_table), s, max); \ } -#define _DEFINE_STRING_TABLE_LOOKUP(name,type,scope) \ - _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ - _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,scope) +#define _DEFINE_STRING_TABLE_LOOKUP(name, type, scope) \ + _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \ + _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, scope) -#define _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,scope) \ - _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,scope) \ - _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,scope) +#define _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes, scope) \ + _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, scope) \ + _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, scope) -#define DEFINE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,) -#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,) -#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name,type) _DEFINE_STRING_TABLE_LOOKUP(name,type,static) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name,type,static) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name,type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name,type,static) +#define DEFINE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type,) +#define DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type,) +#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type,) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP(name, type) _DEFINE_STRING_TABLE_LOOKUP(name, type, static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_TO_STRING(name, type, static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(name, type) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(name, type, static) -#define DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name,type,yes,static) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes) \ - _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name,type,yes,static) +#define DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes,) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes) _DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(name, type, yes, static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes) \ + _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(name, type, yes, static) /* For string conversions where numbers are also acceptable */ -#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name,type,max) \ - _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,) \ - _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,) -#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(name,type,max) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,) +#define DEFINE_STRING_TABLE_LOOKUP_WITH_FALLBACK(name, type, max) \ + _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max,) \ + _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max,) +#define DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_FALLBACK(name, type, max) _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max,) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max) \ - _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name,type,max,static) -#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max) \ - _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name,type,max,static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max) \ + _DEFINE_STRING_TABLE_LOOKUP_TO_STRING_FALLBACK(name, type, max, static) +#define DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max) \ + _DEFINE_STRING_TABLE_LOOKUP_FROM_STRING_FALLBACK(name, type, max, static) -#define DUMP_STRING_TABLE(name,type,max) \ +#define DUMP_STRING_TABLE(name, type, max) \ ({ \ flockfile(stdout); \ for (type _k = 0; _k < (max); _k++) { \ diff --git a/src/basic/time-util.c b/src/basic/time-util.c index fcbedf9e9d..17850c7e16 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -1785,7 +1785,7 @@ DEFINE_STRING_TABLE_LOOKUP_TO_STRING(timestamp_style, TimestampStyle); TimestampStyle timestamp_style_from_string(const char *s) { TimestampStyle t; - t = (TimestampStyle) string_table_lookup(timestamp_style_table, ELEMENTSOF(timestamp_style_table), s); + t = (TimestampStyle) string_table_lookup_from_string(timestamp_style_table, ELEMENTSOF(timestamp_style_table), s); if (t >= 0) return t; if (STRPTR_IN_SET(s, "µs", "μs")) /* accept both µ symbols in unicode, i.e. micro symbol + Greek small letter mu. */ diff --git a/src/basic/virt.c b/src/basic/virt.c index 4c5c5b3b9a..dbb035a94a 100644 --- a/src/basic/virt.c +++ b/src/basic/virt.c @@ -18,6 +18,7 @@ #include "log.h" #include "macro.h" #include "namespace-util.h" +#include "parse-util.h" #include "process-util.h" #include "stat-util.h" #include "string-table.h" diff --git a/src/core/kill.c b/src/core/kill.c index a93132ccd8..74b1b13a8d 100644 --- a/src/core/kill.c +++ b/src/core/kill.c @@ -3,6 +3,7 @@ #include "kill.h" #include "signal-util.h" #include "string-table.h" +#include "string-util.h" void kill_context_init(KillContext *c) { assert(c); diff --git a/src/core/scope.c b/src/core/scope.c index 3424d978de..174a95c649 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -11,6 +11,7 @@ #include "load-dropin.h" #include "log.h" #include "manager.h" +#include "parse-util.h" #include "process-util.h" #include "random-util.h" #include "scope.h" diff --git a/src/creds/creds.c b/src/creds/creds.c index 7c2e49da4f..343030b5fb 100644 --- a/src/creds/creds.c +++ b/src/creds/creds.c @@ -23,6 +23,7 @@ #include "missing_magic.h" #include "pager.h" #include "parse-argument.h" +#include "parse-util.h" #include "polkit-agent.h" #include "pretty-print.h" #include "process-util.h" diff --git a/src/home/homed-home.c b/src/home/homed-home.c index d33b4974b9..da5e304f1b 100644 --- a/src/home/homed-home.c +++ b/src/home/homed-home.c @@ -28,6 +28,7 @@ #include "missing_magic.h" #include "missing_mman.h" #include "mkdir.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "quota-util.h" diff --git a/src/import/import-compress.c b/src/import/import-compress.c index 73bfc1f0fa..f6385c6b03 100644 --- a/src/import/import-compress.c +++ b/src/import/import-compress.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ +#include "assert-util.h" #include "import-compress.h" #include "log.h" #include "string-table.h" diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index e244b668ee..3dd72ddcf4 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -20,6 +20,7 @@ #include "microhttpd-util.h" #include "parse-argument.h" #include "parse-helpers.h" +#include "parse-util.h" #include "pretty-print.h" #include "process-util.h" #include "rlimit-util.h" diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 400894e2a2..9125831a9d 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -19,6 +19,7 @@ #include "mount-util.h" #include "mountpoint-util.h" #include "parse-argument.h" +#include "parse-util.h" #include "pretty-print.h" #include "static-destruct.h" #include "string-table.h" diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index 720c67c7be..6945308187 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -30,6 +30,7 @@ #include "lookup3.h" #include "memory-util.h" #include "missing_fs.h" +#include "parse-util.h" #include "path-util.h" #include "prioq.h" #include "random-util.h" diff --git a/src/libsystemd/sd-json/sd-json.c b/src/libsystemd/sd-json/sd-json.c index 4a91bc8b81..03f94ce663 100644 --- a/src/libsystemd/sd-json/sd-json.c +++ b/src/libsystemd/sd-json/sd-json.c @@ -30,6 +30,7 @@ #include "memory-util.h" #include "memstream-util.h" #include "ordered-set.h" +#include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "ratelimit.h" diff --git a/src/network/netdev/macsec.c b/src/network/netdev/macsec.c index 0df52fd360..638ad7dd50 100644 --- a/src/network/netdev/macsec.c +++ b/src/network/netdev/macsec.c @@ -15,6 +15,7 @@ #include "netlink-util.h" #include "networkd-manager.h" #include "parse-helpers.h" +#include "parse-util.h" #include "socket-util.h" #include "string-table.h" #include "string-util.h" diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 0bd27a45c8..91f9d1d88d 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -61,6 +61,7 @@ #include "networkd-state-file.h" #include "networkd-sysctl.h" #include "networkd-wifi.h" +#include "parse-util.h" #include "set.h" #include "socket-util.h" #include "stdio-util.h" diff --git a/src/repart/repart.c b/src/repart/repart.c index 80fbafdb4b..8eaf4308f9 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -62,6 +62,7 @@ #include "openssl-util.h" #include "parse-argument.h" #include "parse-helpers.h" +#include "parse-util.h" #include "pretty-print.h" #include "proc-cmdline.h" #include "process-util.h" diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c index 62a99eb7a0..a52d874ad8 100644 --- a/src/shared/ask-password-api.c +++ b/src/shared/ask-password-api.c @@ -38,6 +38,7 @@ #include "missing_syscall.h" #include "mkdir-label.h" #include "nulstr-util.h" +#include "parse-util.h" #include "path-lookup.h" #include "plymouth-util.h" #include "process-util.h" diff --git a/src/shared/bootspec.c b/src/shared/bootspec.c index 7bdb32192a..a9cbd62fe4 100644 --- a/src/shared/bootspec.c +++ b/src/shared/bootspec.c @@ -15,6 +15,7 @@ #include "fileio.h" #include "find-esp.h" #include "log.h" +#include "parse-util.h" #include "path-util.h" #include "pe-binary.h" #include "pretty-print.h" diff --git a/src/shared/bpf-program.c b/src/shared/bpf-program.c index 05a937cc50..96ce5e9006 100644 --- a/src/shared/bpf-program.c +++ b/src/shared/bpf-program.c @@ -12,6 +12,7 @@ #include "fd-util.h" #include "memory-util.h" #include "missing_syscall.h" +#include "parse-util.h" #include "path-util.h" #include "serialize.h" #include "string-table.h" diff --git a/src/shared/coredump-util.c b/src/shared/coredump-util.c index c27678f011..77573a95c0 100644 --- a/src/shared/coredump-util.c +++ b/src/shared/coredump-util.c @@ -6,8 +6,10 @@ #include "extract-word.h" #include "fileio.h" #include "log.h" +#include "parse-util.h" #include "stdio-util.h" #include "string-table.h" +#include "string-util.h" #include "unaligned.h" #include "virt.h" diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index 0dab790305..a91cd5bbf8 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -13,6 +13,7 @@ #include "log.h" #include "macro-fundamental.h" #include "memory-util.h" +#include "parse-util.h" #include "socket-util.h" #include "string-table.h" #include "strv.h" diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 25d919cac4..0b8b20addd 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -505,7 +505,7 @@ ExecCommandFlags exec_command_flags_from_string(const char *s) { if (streq(s, "ambient")) /* Compatibility with ambient hack, removed in v258, map to no bits set */ return 0; - idx = string_table_lookup(exec_command_strings, ELEMENTSOF(exec_command_strings), s); + idx = string_table_lookup_from_string(exec_command_strings, ELEMENTSOF(exec_command_strings), s); if (idx < 0) return _EXEC_COMMAND_FLAGS_INVALID; diff --git a/src/shared/firewall-util-nft.c b/src/shared/firewall-util-nft.c index 410a2d1390..f8273f340c 100644 --- a/src/shared/firewall-util-nft.c +++ b/src/shared/firewall-util-nft.c @@ -22,6 +22,7 @@ #include "macro.h" #include "netlink-internal.h" #include "netlink-util.h" +#include "parse-util.h" #include "socket-util.h" #include "string-table.h" #include "time-util.h" diff --git a/src/shared/numa-util.c b/src/shared/numa-util.c index 7e42f9ae5a..b479e5f776 100644 --- a/src/shared/numa-util.c +++ b/src/shared/numa-util.c @@ -12,6 +12,7 @@ #include "macro.h" #include "missing_syscall.h" #include "numa-util.h" +#include "parse-util.h" #include "stdio-util.h" #include "string-table.h" diff --git a/src/shared/parse-argument.c b/src/shared/parse-argument.c index ced3665725..288b68ceed 100644 --- a/src/shared/parse-argument.c +++ b/src/shared/parse-argument.c @@ -3,6 +3,7 @@ #include "format-table.h" #include "log.h" #include "parse-argument.h" +#include "parse-util.h" #include "path-util.h" #include "signal-util.h" #include "stdio-util.h" diff --git a/src/shared/pe-binary.c b/src/shared/pe-binary.c index 6bfc4868ae..627c59cac8 100644 --- a/src/shared/pe-binary.c +++ b/src/shared/pe-binary.c @@ -539,7 +539,7 @@ int uki_hash(int fd, if (!n) return log_oom_debug(); - i = string_table_lookup(unified_sections, _UNIFIED_SECTION_MAX, n); + i = string_table_lookup_from_string(unified_sections, _UNIFIED_SECTION_MAX, n); if (i < 0) continue; diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 55c597e5f9..fdbde7dc5e 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -18,6 +18,7 @@ #include "output-mode.h" #include "pager.h" #include "parse-argument.h" +#include "parse-util.h" #include "path-util.h" #include "pretty-print.h" #include "process-util.h" diff --git a/src/sysupdate/sysupdated.c b/src/sysupdate/sysupdated.c index fcb949fc0f..7dd2d981e0 100644 --- a/src/sysupdate/sysupdated.c +++ b/src/sysupdate/sysupdated.c @@ -26,6 +26,7 @@ #include "mkdir-label.h" #include "notify-recv.h" #include "os-util.h" +#include "parse-util.h" #include "process-util.h" #include "service-util.h" #include "signal-util.h"