tree-wide: drop msg argument for DEFINE_CONFIG_PARSE() macro and friends

This makes the macros use log_syntax_parse_error(), hopefully which provides
more informative log message in general, and reduces binary size.
This commit is contained in:
Yu Watanabe
2024-09-02 05:45:09 +09:00
parent 382886fe11
commit 42efe5be1d
40 changed files with 120 additions and 157 deletions
+4 -4
View File
@@ -852,7 +852,7 @@ int _hashmap_by_section_find_unused_line(
}
#define DEFINE_PARSER(type, vartype, conv_func) \
DEFINE_CONFIG_PARSE_PTR(config_parse_##type, conv_func, vartype, "Failed to parse " #type " value")
DEFINE_CONFIG_PARSE_PTR(config_parse_##type, conv_func, vartype)
DEFINE_PARSER(int, int, safe_atoi);
DEFINE_PARSER(long, long, safe_atoli);
@@ -2054,9 +2054,9 @@ int config_parse_calendar(
return 0;
}
DEFINE_CONFIG_PARSE(config_parse_percent, parse_percent, "Failed to parse percent value");
DEFINE_CONFIG_PARSE(config_parse_permyriad, parse_permyriad, "Failed to parse permyriad value");
DEFINE_CONFIG_PARSE_PTR(config_parse_sec_fix_0, parse_sec_fix_0, usec_t, "Failed to parse time value");
DEFINE_CONFIG_PARSE(config_parse_percent, parse_percent);
DEFINE_CONFIG_PARSE(config_parse_permyriad, parse_permyriad);
DEFINE_CONFIG_PARSE_PTR(config_parse_sec_fix_0, parse_sec_fix_0, usec_t);
int config_parse_timezone(
const char *unit,
+22 -36
View File
@@ -305,7 +305,7 @@ typedef enum ConfigParseStringFlags {
CONFIG_PARSE_STRING_SAFE_AND_ASCII = CONFIG_PARSE_STRING_SAFE | CONFIG_PARSE_STRING_ASCII,
} ConfigParseStringFlags;
#define DEFINE_CONFIG_PARSE(function, parser, msg) \
#define DEFINE_CONFIG_PARSE(function, parser) \
CONFIG_PARSER_PROTOTYPE(function) { \
int *i = data, r; \
\
@@ -315,17 +315,14 @@ typedef enum ConfigParseStringFlags {
assert(data); \
\
r = parser(rvalue); \
if (r < 0) { \
log_syntax(unit, LOG_WARNING, filename, line, r, \
msg ", ignoring: %s", rvalue); \
return 0; \
} \
if (r < 0) \
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); \
\
*i = r; \
return 1; \
}
#define DEFINE_CONFIG_PARSE_PTR(function, parser, type, msg) \
#define DEFINE_CONFIG_PARSE_PTR(function, parser, type) \
CONFIG_PARSER_PROTOTYPE(function) { \
type *i = ASSERT_PTR(data); \
int r; \
@@ -336,13 +333,12 @@ typedef enum ConfigParseStringFlags {
\
r = parser(rvalue, i); \
if (r < 0) \
log_syntax(unit, LOG_WARNING, filename, line, r, \
msg ", ignoring: %s", rvalue); \
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); \
\
return 1; \
}
#define DEFINE_CONFIG_PARSE_ENUM_FULL(function, from_string, type, msg) \
#define DEFINE_CONFIG_PARSE_ENUM_FULL(function, from_string, type) \
CONFIG_PARSER_PROTOTYPE(function) { \
type *i = data, x; \
\
@@ -352,20 +348,17 @@ typedef enum ConfigParseStringFlags {
assert(data); \
\
x = from_string(rvalue); \
if (x < 0) { \
log_syntax(unit, LOG_WARNING, filename, line, x, \
msg ", ignoring: %s", rvalue); \
return 0; \
} \
if (x < 0) \
return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue); \
\
*i = x; \
return 1; \
}
#define DEFINE_CONFIG_PARSE_ENUM(function, name, type, msg) \
DEFINE_CONFIG_PARSE_ENUM_FULL(function, name##_from_string, type, msg)
#define DEFINE_CONFIG_PARSE_ENUM(function, name, type) \
DEFINE_CONFIG_PARSE_ENUM_FULL(function, name##_from_string, type)
#define DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(function, name, type, default_value, msg) \
#define DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(function, name, type, default_value) \
CONFIG_PARSER_PROTOTYPE(function) { \
type *i = data, x; \
\
@@ -380,17 +373,14 @@ typedef enum ConfigParseStringFlags {
} \
\
x = name##_from_string(rvalue); \
if (x < 0) { \
log_syntax(unit, LOG_WARNING, filename, line, x, \
msg ", ignoring: %s", rvalue); \
return 0; \
} \
if (x < 0) \
return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue); \
\
*i = x; \
return 1; \
}
#define DEFINE_CONFIG_PARSE_ENUMV(function, name, type, invalid, msg) \
#define DEFINE_CONFIG_PARSE_ENUMV(function, name, type, invalid) \
CONFIG_PARSER_PROTOTYPE(function) { \
type **enums = ASSERT_PTR(data); \
_cleanup_free_ type *xs = NULL; \
@@ -412,28 +402,24 @@ typedef enum ConfigParseStringFlags {
type x, *new_xs; \
\
r = extract_first_word(&p, &en, NULL, 0); \
if (r == -ENOMEM) \
return log_oom(); \
if (r < 0) { \
log_syntax(unit, LOG_WARNING, filename, line, r, \
msg ", ignoring: %s", en); \
return 0; \
} \
if (r < 0) \
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); \
if (r == 0) \
break; \
\
x = name##_from_string(en); \
if (x < 0) { \
log_syntax(unit, LOG_WARNING, filename, line, x, \
msg ", ignoring: %s", en); \
"Failed to parse %s in %s=, ignoring.", \
en, lvalue); \
continue; \
} \
\
for (type *ys = xs; x != invalid && *ys != invalid; ys++) \
if (*ys == x) { \
for (type *ys = xs; x != invalid && *ys != invalid; ys++) \
if (*ys == x) { \
log_syntax(unit, LOG_NOTICE, filename, line, 0, \
"Duplicate entry, ignoring: %s", \
en); \
"Duplicate entry %s in %s=, ignoring.", \
en, lvalue); \
x = invalid; \
} \
\
+2 -2
View File
@@ -23,7 +23,7 @@ static const char* const duplex_table[_DUP_MAX] = {
};
DEFINE_STRING_TABLE_LOOKUP(duplex, Duplex);
DEFINE_CONFIG_PARSE_ENUM(config_parse_duplex, duplex, Duplex, "Failed to parse duplex setting");
DEFINE_CONFIG_PARSE_ENUM(config_parse_duplex, duplex, Duplex);
static const struct {
uint32_t opt;
@@ -72,7 +72,7 @@ static const char* const port_table[] = {
};
DEFINE_STRING_TABLE_LOOKUP(port, NetDevPort);
DEFINE_CONFIG_PARSE_ENUM(config_parse_port, port, NetDevPort, "Failed to parse Port setting");
DEFINE_CONFIG_PARSE_ENUM(config_parse_port, port, NetDevPort);
static const char* const mdi_table[] = {
[ETH_TP_MDI_INVALID] = "unknown",
+4 -4
View File
@@ -4,9 +4,9 @@
#include "resolve-util.h"
#include "string-table.h"
DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve_support, resolve_support, ResolveSupport, "Failed to parse resolve support setting");
DEFINE_CONFIG_PARSE_ENUM(config_parse_dnssec_mode, dnssec_mode, DnssecMode, "Failed to parse DNSSEC mode setting");
DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_over_tls_mode, dns_over_tls_mode, DnsOverTlsMode, "Failed to parse DNS-over-TLS mode setting");
DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve_support, resolve_support, ResolveSupport);
DEFINE_CONFIG_PARSE_ENUM(config_parse_dnssec_mode, dnssec_mode, DnssecMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_over_tls_mode, dns_over_tls_mode, DnsOverTlsMode);
static const char* const resolve_support_table[_RESOLVE_SUPPORT_MAX] = {
[RESOLVE_SUPPORT_NO] = "no",
@@ -42,7 +42,7 @@ bool dns_server_address_valid(int family, const union in_addr_union *sa) {
return true;
}
DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_cache_mode, dns_cache_mode, DnsCacheMode, "Failed to parse DNS cache mode setting")
DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_cache_mode, dns_cache_mode, DnsCacheMode);
static const char* const dns_cache_mode_table[_DNS_CACHE_MODE_MAX] = {
[DNS_CACHE_MODE_YES] = "yes",