1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

Merge pull request #34140 from yuwata/conf-parser-log-message

conf-parser: introduce log_syntax_parse_error() and use it
This commit is contained in:
Yu Watanabe 2024-09-03 08:20:07 +09:00 committed by GitHub
commit a833dc9b35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
44 changed files with 449 additions and 488 deletions

View File

@ -1679,6 +1679,7 @@ int log_syntax_invalid_utf8_internal(
const char *func, const char *func,
const char *rvalue) { const char *rvalue) {
PROTECT_ERRNO;
_cleanup_free_ char *p = NULL; _cleanup_free_ char *p = NULL;
if (rvalue) if (rvalue)
@ -1689,6 +1690,44 @@ int log_syntax_invalid_utf8_internal(
"String is not UTF-8 clean, ignoring assignment: %s", strna(p)); "String is not UTF-8 clean, ignoring assignment: %s", strna(p));
} }
int log_syntax_parse_error_internal(
const char *unit,
const char *config_file,
unsigned config_line,
int error,
bool critical,
const char *file,
int line,
const char *func,
const char *lvalue,
const char *rvalue) {
PROTECT_ERRNO;
_cleanup_free_ char *escaped = NULL;
/* OOM is always handled as critical. */
if (ERRNO_VALUE(error) == ENOMEM)
return log_oom_internal(LOG_ERR, file, line, func);
if (rvalue && !utf8_is_valid(rvalue)) {
escaped = utf8_escape_invalid(rvalue);
if (!escaped)
rvalue = "(oom)";
else
rvalue = " (escaped)";
}
log_syntax_internal(unit, critical ? LOG_ERR : LOG_WARNING, config_file, config_line, error,
file, line, func,
"Failed to parse %s=%s%s%s%s%s",
strna(lvalue), strempty(escaped), strempty(rvalue),
critical ? "" : ", ignoring",
error == 0 ? "." : ": ",
error == 0 ? "" : STRERROR(error));
return critical ? -ERRNO_VALUE(error) : 0;
}
void log_set_upgrade_syslog_to_journal(bool b) { void log_set_upgrade_syslog_to_journal(bool b) {
upgrade_syslog_to_journal = b; upgrade_syslog_to_journal = b;

View File

@ -359,6 +359,18 @@ int log_syntax_invalid_utf8_internal(
const char *func, const char *func,
const char *rvalue); const char *rvalue);
int log_syntax_parse_error_internal(
const char *unit,
const char *config_file,
unsigned config_line,
int error,
bool critical, /* When true, propagate the passed error, otherwise this always returns 0. */
const char *file,
int line,
const char *func,
const char *lvalue,
const char *rvalue);
#define log_syntax(unit, level, config_file, config_line, error, ...) \ #define log_syntax(unit, level, config_file, config_line, error, ...) \
({ \ ({ \
int _level = (level), _e = (error); \ int _level = (level), _e = (error); \
@ -375,6 +387,12 @@ int log_syntax_invalid_utf8_internal(
: -EINVAL; \ : -EINVAL; \
}) })
#define log_syntax_parse_error_full(unit, config_file, config_line, error, critical, lvalue, rvalue) \
log_syntax_parse_error_internal(unit, config_file, config_line, error, critical, PROJECT_FILE, __LINE__, __func__, lvalue, rvalue)
#define log_syntax_parse_error(unit, config_file, config_line, error, lvalue, rvalue) \
log_syntax_parse_error_full(unit, config_file, config_line, error, /* critical = */ false, lvalue, rvalue)
#define DEBUG_LOGGING _unlikely_(log_get_max_level() >= LOG_DEBUG) #define DEBUG_LOGGING _unlikely_(log_get_max_level() >= LOG_DEBUG)
void log_setup(void); void log_setup(void);

View File

@ -126,38 +126,38 @@ int parse_confirm_spawn(const char *value, char **console) {
return 0; return 0;
} }
DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol, "Failed to parse socket protocol"); DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol);
DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits"); DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string);
DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy"); DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy);
DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode, "Failed to parse keyring mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc, protect_proc, ProtectProc, "Failed to parse /proc/ protection mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc, protect_proc, ProtectProc);
DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset, proc_subset, ProcSubset, "Failed to parse /proc/ subset mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset, proc_subset, ProcSubset);
DEFINE_CONFIG_PARSE_ENUM(config_parse_private_tmp, private_tmp, PrivateTmp, "Failed to parse private tmp value"); DEFINE_CONFIG_PARSE_ENUM(config_parse_private_tmp, private_tmp, PrivateTmp);
DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode, "Failed to parse utmp mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode, "Failed to parse job mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess);
DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome, "Failed to parse protect home value"); DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome);
DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem, "Failed to parse protect system value"); DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem);
DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode, "Failed to parse resource preserve mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType, "Failed to parse service type"); DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type, service_exit_type, ServiceExitType, "Failed to parse service exit type"); DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type, service_exit_type, ServiceExitType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart_mode, service_restart_mode, ServiceRestartMode, "Failed to parse service restart mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart_mode, service_restart_mode, ServiceRestartMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode, "Failed to parse timeout failure mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_service_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only, "Failed to parse bind IPv6 only value"); DEFINE_CONFIG_PARSE_ENUM(config_parse_socket_bind, socket_address_bind_ipv6_only_or_bool, SocketAddressBindIPv6Only);
DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy, "Failed to parse OOM policy"); DEFINE_CONFIG_PARSE_ENUM(config_parse_oom_policy, oom_policy, OOMPolicy);
DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference, managed_oom_preference, ManagedOOMPreference, "Failed to parse ManagedOOMPreference="); DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference, managed_oom_preference, ManagedOOMPreference);
DEFINE_CONFIG_PARSE_ENUM(config_parse_memory_pressure_watch, cgroup_pressure_watch, CGroupPressureWatch, "Failed to parse memory pressure watch setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_memory_pressure_watch, cgroup_pressure_watch, CGroupPressureWatch);
DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1, "Failed to parse IP TOS value"); DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1);
DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t, "Invalid block IO weight"); DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t, "Invalid weight"); DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight, cg_cpu_weight_parse, uint64_t, "Invalid CPU weight"); DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight, cg_cpu_weight_parse, uint64_t);
static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal, cg_cpu_shares_parse, uint64_t, "Invalid CPU shares"); static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal, cg_cpu_shares_parse, uint64_t);
DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag, mount_propagation_flag_from_string, unsigned long, "Failed to parse mount propagation flag"); DEFINE_CONFIG_PARSE_PTR(config_parse_exec_mount_propagation_flag, mount_propagation_flag_from_string, unsigned long);
DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1, "Invalid NUMA policy type"); DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1);
DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat, "Failed to parse status unit format"); DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat);
DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping, "Failed to parse timestamping precision"); DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping);
int config_parse_cpu_shares( int config_parse_cpu_shares(
const char *unit, const char *unit,

View File

@ -174,7 +174,7 @@ static const char* const crash_action_table[_CRASH_ACTION_MAX] = {
DEFINE_STRING_TABLE_LOOKUP(crash_action, CrashAction); DEFINE_STRING_TABLE_LOOKUP(crash_action, CrashAction);
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_crash_action, crash_action, CrashAction, CRASH_FREEZE, "Invalid crash action"); static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_crash_action, crash_action, CrashAction, CRASH_FREEZE);
static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) { static int manager_find_user_config_paths(char ***ret_files, char ***ret_dirs) {
_cleanup_free_ char *base = NULL; _cleanup_free_ char *base = NULL;

View File

@ -158,7 +158,7 @@ static const char* const coredump_storage_table[_COREDUMP_STORAGE_MAX] = {
}; };
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(coredump_storage, CoredumpStorage); DEFINE_PRIVATE_STRING_TABLE_LOOKUP(coredump_storage, CoredumpStorage);
static DEFINE_CONFIG_PARSE_ENUM(config_parse_coredump_storage, coredump_storage, CoredumpStorage, "Failed to parse storage setting"); static DEFINE_CONFIG_PARSE_ENUM(config_parse_coredump_storage, coredump_storage, CoredumpStorage);
static CoredumpStorage arg_storage = COREDUMP_STORAGE_EXTERNAL; static CoredumpStorage arg_storage = COREDUMP_STORAGE_EXTERNAL;
static bool arg_compress = true; static bool arg_compress = true;

View File

@ -17,7 +17,7 @@ int manager_parse_config_file(Manager *m) {
m); m);
} }
DEFINE_CONFIG_PARSE_ENUM(config_parse_default_storage, user_storage, UserStorage, "Failed to parse default storage setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_default_storage, user_storage, UserStorage);
int config_parse_default_file_system_type( int config_parse_default_file_system_type(
const char *unit, const char *unit,

View File

@ -72,10 +72,7 @@ static const char* const journal_write_split_mode_table[_JOURNAL_WRITE_SPLIT_MAX
}; };
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(journal_write_split_mode, JournalWriteSplitMode); DEFINE_PRIVATE_STRING_TABLE_LOOKUP(journal_write_split_mode, JournalWriteSplitMode);
static DEFINE_CONFIG_PARSE_ENUM(config_parse_write_split_mode, static DEFINE_CONFIG_PARSE_ENUM(config_parse_write_split_mode, journal_write_split_mode, JournalWriteSplitMode);
journal_write_split_mode,
JournalWriteSplitMode,
"Failed to parse split mode setting");
/********************************************************************** /**********************************************************************
********************************************************************** **********************************************************************

View File

@ -2953,7 +2953,7 @@ static const char* const storage_table[_STORAGE_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(storage, Storage); DEFINE_STRING_TABLE_LOOKUP(storage, Storage);
DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage, "Failed to parse storage setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_storage, storage, Storage);
static const char* const split_mode_table[_SPLIT_MAX] = { static const char* const split_mode_table[_SPLIT_MAX] = {
[SPLIT_LOGIN] = "login", [SPLIT_LOGIN] = "login",
@ -2962,7 +2962,7 @@ static const char* const split_mode_table[_SPLIT_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode); DEFINE_STRING_TABLE_LOOKUP(split_mode, SplitMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode, "Failed to parse split mode setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_split_mode, split_mode, SplitMode);
int config_parse_line_max( int config_parse_line_max(
const char* unit, const char* unit,

View File

@ -438,7 +438,7 @@ static const char* const handle_action_table[_HANDLE_ACTION_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(handle_action, HandleAction); DEFINE_STRING_TABLE_LOOKUP(handle_action, HandleAction);
DEFINE_CONFIG_PARSE_ENUM(config_parse_handle_action, handle_action, HandleAction, "Failed to parse handle action setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_handle_action, handle_action, HandleAction);
int config_parse_handle_action_sleep( int config_parse_handle_action_sleep(
const char *unit, const char *unit,

View File

@ -17,8 +17,7 @@ static const char* const bare_udp_protocol_table[_BARE_UDP_PROTOCOL_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(bare_udp_protocol, BareUDPProtocol); DEFINE_STRING_TABLE_LOOKUP(bare_udp_protocol, BareUDPProtocol);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bare_udp_iftype, bare_udp_protocol, BareUDPProtocol, DEFINE_CONFIG_PARSE_ENUM(config_parse_bare_udp_iftype, bare_udp_protocol, BareUDPProtocol);
"Failed to parse EtherType=");
static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
assert(m); assert(m);

View File

@ -47,12 +47,10 @@ static const char* const batadv_routing_algorithm_kernel_table[_BATADV_ROUTING_A
}; };
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(batadv_gateway_mode, BatadvGatewayModes); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(batadv_gateway_mode, BatadvGatewayModes);
DEFINE_CONFIG_PARSE_ENUM(config_parse_batadv_gateway_mode, batadv_gateway_mode, BatadvGatewayModes, DEFINE_CONFIG_PARSE_ENUM(config_parse_batadv_gateway_mode, batadv_gateway_mode, BatadvGatewayModes);
"Failed to parse GatewayMode=");
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(batadv_routing_algorithm, BatadvRoutingAlgorithm); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(batadv_routing_algorithm, BatadvRoutingAlgorithm);
DEFINE_CONFIG_PARSE_ENUM(config_parse_batadv_routing_algorithm, batadv_routing_algorithm, BatadvRoutingAlgorithm, DEFINE_CONFIG_PARSE_ENUM(config_parse_batadv_routing_algorithm, batadv_routing_algorithm, BatadvRoutingAlgorithm);
"Failed to parse RoutingAlgorithm=");
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(batadv_routing_algorithm_kernel, BatadvRoutingAlgorithm); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(batadv_routing_algorithm_kernel, BatadvRoutingAlgorithm);

View File

@ -44,17 +44,16 @@
#define GRATUITOUS_ARP_MAX 255 #define GRATUITOUS_ARP_MAX 255
#define GRATUITOUS_ARP_DEFAULT 1 #define GRATUITOUS_ARP_DEFAULT 1
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_mode, bond_mode, BondMode, "Failed to parse bond mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_mode, bond_mode, BondMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_xmit_hash_policy, DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_xmit_hash_policy,
bond_xmit_hash_policy, bond_xmit_hash_policy,
BondXmitHashPolicy, BondXmitHashPolicy);
"Failed to parse bond transmit hash policy"); DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_lacp_rate, bond_lacp_rate, BondLacpRate);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_lacp_rate, bond_lacp_rate, BondLacpRate, "Failed to parse bond lacp rate"); DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_ad_select, bond_ad_select, BondAdSelect);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_ad_select, bond_ad_select, BondAdSelect, "Failed to parse bond AD select"); DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_fail_over_mac, bond_fail_over_mac, BondFailOverMac);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_fail_over_mac, bond_fail_over_mac, BondFailOverMac, "Failed to parse bond fail over MAC"); DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_validate, bond_arp_validate, BondArpValidate);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_validate, bond_arp_validate, BondArpValidate, "Failed to parse bond arp validate"); DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_all_targets, bond_arp_all_targets, BondArpAllTargets);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_all_targets, bond_arp_all_targets, BondArpAllTargets, "Failed to parse bond Arp all targets"); DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_primary_reselect, bond_primary_reselect, BondPrimaryReselect);
DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_primary_reselect, bond_primary_reselect, BondPrimaryReselect, "Failed to parse bond primary reselect");
static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
assert(!link); assert(!link);

View File

@ -25,8 +25,7 @@ static const char* const multicast_router_table[_MULTICAST_ROUTER_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(multicast_router, MulticastRouter, _MULTICAST_ROUTER_INVALID); DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(multicast_router, MulticastRouter, _MULTICAST_ROUTER_INVALID);
DEFINE_CONFIG_PARSE_ENUM(config_parse_multicast_router, multicast_router, MulticastRouter, DEFINE_CONFIG_PARSE_ENUM(config_parse_multicast_router, multicast_router, MulticastRouter);
"Failed to parse bridge multicast router setting");
/* callback for bridge netdev's parameter set */ /* callback for bridge netdev's parameter set */
static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) { static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) {

View File

@ -21,8 +21,7 @@ static const char* const fou_encap_type_table[_NETDEV_FOO_OVER_UDP_ENCAP_MAX] =
}; };
DEFINE_STRING_TABLE_LOOKUP(fou_encap_type, FooOverUDPEncapType); DEFINE_STRING_TABLE_LOOKUP(fou_encap_type, FooOverUDPEncapType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_fou_encap_type, fou_encap_type, FooOverUDPEncapType, DEFINE_CONFIG_PARSE_ENUM(config_parse_fou_encap_type, fou_encap_type, FooOverUDPEncapType);
"Failed to parse Encapsulation=");
static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message *m) { static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message *m) {
FouTunnel *t = FOU(netdev); FouTunnel *t = FOU(netdev);

View File

@ -26,7 +26,7 @@ static const char* const geneve_df_table[_NETDEV_GENEVE_DF_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(geneve_df, GeneveDF, NETDEV_GENEVE_DF_YES); DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(geneve_df, GeneveDF, NETDEV_GENEVE_DF_YES);
DEFINE_CONFIG_PARSE_ENUM(config_parse_geneve_df, geneve_df, GeneveDF, "Failed to parse Geneve IPDoNotFragment= setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_geneve_df, geneve_df, GeneveDF);
static int netdev_geneve_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { static int netdev_geneve_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) {
assert(m); assert(m);

View File

@ -94,7 +94,7 @@ static const char * const ipoib_mode_table[_IP_OVER_INFINIBAND_MODE_MAX] = {
}; };
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(ipoib_mode, IPoIBMode); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(ipoib_mode, IPoIBMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipoib_mode, ipoib_mode, IPoIBMode, "Failed to parse IPoIB mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_ipoib_mode, ipoib_mode, IPoIBMode);
int config_parse_ipoib_pkey( int config_parse_ipoib_pkey(
const char *unit, const char *unit,

View File

@ -11,8 +11,8 @@
#include "networkd-link.h" #include "networkd-link.h"
#include "string-util.h" #include "string-util.h"
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_mode, ipvlan_mode, IPVlanMode, "Failed to parse ipvlan mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_mode, ipvlan_mode, IPVlanMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_flags, ipvlan_flags, IPVlanFlags, "Failed to parse ipvlan flags"); DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_flags, ipvlan_flags, IPVlanFlags);
static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) { static int netdev_ipvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
assert(netdev); assert(netdev);

View File

@ -29,7 +29,7 @@ static const char* const l2tp_encap_type_table[_NETDEV_L2TP_ENCAPTYPE_MAX] = {
}; };
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(l2tp_encap_type, L2tpEncapType); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(l2tp_encap_type, L2tpEncapType);
DEFINE_CONFIG_PARSE_ENUM(config_parse_l2tp_encap_type, l2tp_encap_type, L2tpEncapType, "Failed to parse L2TP Encapsulation Type"); DEFINE_CONFIG_PARSE_ENUM(config_parse_l2tp_encap_type, l2tp_encap_type, L2tpEncapType);
static const char* const l2tp_local_address_type_table[_NETDEV_L2TP_LOCAL_ADDRESS_MAX] = { static const char* const l2tp_local_address_type_table[_NETDEV_L2TP_LOCAL_ADDRESS_MAX] = {
[NETDEV_L2TP_LOCAL_ADDRESS_AUTO] = "auto", [NETDEV_L2TP_LOCAL_ADDRESS_AUTO] = "auto",

View File

@ -16,7 +16,7 @@ typedef enum BCQueueThreshold {
BC_QUEUE_THRESHOLD_DISABLE = -1, BC_QUEUE_THRESHOLD_DISABLE = -1,
} BCQueueThreshold; } BCQueueThreshold;
DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode, "Failed to parse macvlan mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_macvlan_mode, macvlan_mode, MacVlanMode);
static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) { static int netdev_macvlan_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *req) {
assert(netdev); assert(netdev);

View File

@ -30,7 +30,7 @@ static const char* const ip6tnl_mode_table[_NETDEV_IP6_TNL_MODE_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(ip6tnl_mode, Ip6TnlMode); DEFINE_STRING_TABLE_LOOKUP(ip6tnl_mode, Ip6TnlMode);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ip6tnl_mode, ip6tnl_mode, Ip6TnlMode, "Failed to parse ip6 tunnel Mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_ip6tnl_mode, ip6tnl_mode, Ip6TnlMode);
#define HASH_KEY SD_ID128_MAKE(74,c4,de,12,f3,d9,41,34,bb,3d,c1,a4,42,93,50,87) #define HASH_KEY SD_ID128_MAKE(74,c4,de,12,f3,d9,41,34,bb,3d,c1,a4,42,93,50,87)

View File

@ -21,7 +21,7 @@ static const char* const df_table[_NETDEV_VXLAN_DF_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(df, VxLanDF, NETDEV_VXLAN_DF_YES); DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(df, VxLanDF, NETDEV_VXLAN_DF_YES);
DEFINE_CONFIG_PARSE_ENUM(config_parse_df, df, VxLanDF, "Failed to parse VXLAN IPDoNotFragment= setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_df, df, VxLanDF);
static int vxlan_get_local_address(VxLan *v, Link *link, int *ret_family, union in_addr_union *ret_address) { static int vxlan_get_local_address(VxLan *v, Link *link, int *ret_family, union in_addr_union *ret_address) {
assert(v); assert(v);

View File

@ -2018,5 +2018,4 @@ static const char* const dhcp_client_identifier_table[_DHCP_CLIENT_ID_MAX] = {
}; };
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier, DHCPClientIdentifier); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_client_identifier, DHCPClientIdentifier);
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DHCPClientIdentifier, DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DHCPClientIdentifier);
"Failed to parse client identifier type");

View File

@ -878,8 +878,7 @@ int config_parse_dhcp6_pd_prefix_hint(
return 0; return 0;
} }
DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode, DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode);
"Failed to parse WithoutRA= setting");
static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = { static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = {
[DHCP6_CLIENT_START_MODE_NO] = "no", [DHCP6_CLIENT_START_MODE_NO] = "no",

View File

@ -291,4 +291,4 @@ static const char* const use_domains_table[_USE_DOMAINS_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(use_domains, UseDomains, USE_DOMAINS_YES); DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(use_domains, UseDomains, USE_DOMAINS_YES);
DEFINE_CONFIG_PARSE_ENUM(config_parse_use_domains, use_domains, UseDomains, "Failed to parse UseDomains=") DEFINE_CONFIG_PARSE_ENUM(config_parse_use_domains, use_domains, UseDomains);

View File

@ -243,5 +243,4 @@ DEFINE_STRING_TABLE_LOOKUP(ipv6_link_local_address_gen_mode, IPv6LinkLocalAddres
DEFINE_CONFIG_PARSE_ENUM( DEFINE_CONFIG_PARSE_ENUM(
config_parse_ipv6_link_local_address_gen_mode, config_parse_ipv6_link_local_address_gen_mode,
ipv6_link_local_address_gen_mode, ipv6_link_local_address_gen_mode,
IPv6LinkLocalAddressGenMode, IPv6LinkLocalAddressGenMode);
"Failed to parse IPv6 link-local address generation mode");

View File

@ -17,7 +17,7 @@
#include "strv.h" #include "strv.h"
#include "tmpfile-util.h" #include "tmpfile-util.h"
DEFINE_CONFIG_PARSE_ENUM(config_parse_lldp_mode, lldp_mode, LLDPMode, "Failed to parse LLDP= setting."); DEFINE_CONFIG_PARSE_ENUM(config_parse_lldp_mode, lldp_mode, LLDPMode);
static const char* const lldp_mode_table[_LLDP_MODE_MAX] = { static const char* const lldp_mode_table[_LLDP_MODE_MAX] = {
[LLDP_MODE_NO] = "no", [LLDP_MODE_NO] = "no",

View File

@ -2525,5 +2525,4 @@ static const char* const ndisc_start_dhcp6_client_table[_IPV6_ACCEPT_RA_START_DH
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client, IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING_WITH_BOOLEAN(ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client, IPV6_ACCEPT_RA_START_DHCP6_CLIENT_YES);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ndisc_start_dhcp6_client, ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client, DEFINE_CONFIG_PARSE_ENUM(config_parse_ndisc_start_dhcp6_client, ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client);
"Failed to parse DHCPv6Client= setting");

View File

@ -1056,11 +1056,8 @@ int config_parse_ignore_carrier_loss(
return 0; return 0;
} }
DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily, DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily);
"Failed to parse RequiredFamilyForOnline= setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_keep_configuration, keep_configuration, KeepConfiguration);
DEFINE_CONFIG_PARSE_ENUM(config_parse_keep_configuration, keep_configuration, KeepConfiguration,
"Failed to parse KeepConfiguration= setting");
static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = { static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = {
[KEEP_CONFIGURATION_NO] = "no", [KEEP_CONFIGURATION_NO] = "no",
@ -1082,4 +1079,4 @@ static const char* const activation_policy_table[_ACTIVATION_POLICY_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(activation_policy, ActivationPolicy); DEFINE_STRING_TABLE_LOOKUP(activation_policy, ActivationPolicy);
DEFINE_CONFIG_PARSE_ENUM(config_parse_activation_policy, activation_policy, ActivationPolicy, "Failed to parse activation policy"); DEFINE_CONFIG_PARSE_ENUM(config_parse_activation_policy, activation_policy, ActivationPolicy);

View File

@ -1637,8 +1637,7 @@ static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(
config_parse_routing_policy_rule_family, config_parse_routing_policy_rule_family,
routing_policy_rule_address_family, routing_policy_rule_address_family,
AddressFamily, AddressFamily,
ADDRESS_FAMILY_NO, ADDRESS_FAMILY_NO);
"Invalid family");
typedef struct RoutingPolicyRuleConfParser { typedef struct RoutingPolicyRuleConfParser {
ConfigParserCallback parser; ConfigParserCallback parser;

View File

@ -458,8 +458,7 @@ static const char* const ipv6_privacy_extensions_table[_IPV6_PRIVACY_EXTENSIONS_
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(ipv6_privacy_extensions, IPv6PrivacyExtensions, DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(ipv6_privacy_extensions, IPv6PrivacyExtensions,
IPV6_PRIVACY_EXTENSIONS_YES); IPV6_PRIVACY_EXTENSIONS_YES);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ipv6_privacy_extensions, ipv6_privacy_extensions, IPv6PrivacyExtensions, DEFINE_CONFIG_PARSE_ENUM(config_parse_ipv6_privacy_extensions, ipv6_privacy_extensions, IPv6PrivacyExtensions);
"Failed to parse IPv6 privacy extensions option");
static const char* const ip_reverse_path_filter_table[_IP_REVERSE_PATH_FILTER_MAX] = { static const char* const ip_reverse_path_filter_table[_IP_REVERSE_PATH_FILTER_MAX] = {
[IP_REVERSE_PATH_FILTER_NO] = "no", [IP_REVERSE_PATH_FILTER_NO] = "no",
@ -468,8 +467,7 @@ static const char* const ip_reverse_path_filter_table[_IP_REVERSE_PATH_FILTER_MA
}; };
DEFINE_STRING_TABLE_LOOKUP(ip_reverse_path_filter, IPReversePathFilter); DEFINE_STRING_TABLE_LOOKUP(ip_reverse_path_filter, IPReversePathFilter);
DEFINE_CONFIG_PARSE_ENUM(config_parse_ip_reverse_path_filter, ip_reverse_path_filter, IPReversePathFilter, DEFINE_CONFIG_PARSE_ENUM(config_parse_ip_reverse_path_filter, ip_reverse_path_filter, IPReversePathFilter);
"Failed to parse IP reverse path filter option");
int config_parse_ip_forward_deprecated( int config_parse_ip_forward_deprecated(
const char* unit, const char* unit,

View File

@ -110,8 +110,7 @@ AddressFamily link_local_address_family_from_string(const char *s) {
DEFINE_STRING_TABLE_LOOKUP(routing_policy_rule_address_family, AddressFamily); DEFINE_STRING_TABLE_LOOKUP(routing_policy_rule_address_family, AddressFamily);
DEFINE_STRING_TABLE_LOOKUP(nexthop_address_family, AddressFamily); DEFINE_STRING_TABLE_LOOKUP(nexthop_address_family, AddressFamily);
DEFINE_STRING_TABLE_LOOKUP(duplicate_address_detection_address_family, AddressFamily); DEFINE_STRING_TABLE_LOOKUP(duplicate_address_detection_address_family, AddressFamily);
DEFINE_CONFIG_PARSE_ENUM(config_parse_link_local_address_family, link_local_address_family, DEFINE_CONFIG_PARSE_ENUM(config_parse_link_local_address_family, link_local_address_family, AddressFamily);
AddressFamily, "Failed to parse option");
DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_deprecated_address_family, AddressFamily); DEFINE_STRING_TABLE_LOOKUP_FROM_STRING(dhcp_deprecated_address_family, AddressFamily);
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(ip_masquerade_address_family, AddressFamily); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(ip_masquerade_address_family, AddressFamily);
DEFINE_STRING_TABLE_LOOKUP(dhcp_lease_server_type, sd_dhcp_lease_server_type_t); DEFINE_STRING_TABLE_LOOKUP(dhcp_lease_server_type, sd_dhcp_lease_server_type_t);

View File

@ -11,76 +11,65 @@
#include "strv.h" #include "strv.h"
#include "tests.h" #include "tests.h"
static void test_config_parse_duid_type_one(const char *rvalue, int ret, DUIDType expected, usec_t expected_time) { static void test_config_parse_duid_type_one(const char *rvalue, DUIDType expected, usec_t expected_time) {
DUID actual = {}; DUID actual = {};
int r;
r = config_parse_duid_type("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL); ASSERT_OK(config_parse_duid_type("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL));
log_info_errno(r, "\"%s\" → %d (%m)", rvalue, actual.type); ASSERT_EQ(actual.type, expected);
assert_se(r == ret);
assert_se(expected == actual.type);
if (expected == DUID_TYPE_LLT) if (expected == DUID_TYPE_LLT)
assert_se(expected_time == actual.llt_time); ASSERT_EQ(actual.llt_time, expected_time);
} }
TEST(config_parse_duid_type) { TEST(config_parse_duid_type) {
test_config_parse_duid_type_one("", 0, 0, 0); test_config_parse_duid_type_one("", 0, 0);
test_config_parse_duid_type_one("link-layer-time", 0, DUID_TYPE_LLT, 0); test_config_parse_duid_type_one("link-layer-time", DUID_TYPE_LLT, 0);
test_config_parse_duid_type_one("link-layer-time:2000-01-01 00:00:00 UTC", 0, DUID_TYPE_LLT, (usec_t) 946684800000000); test_config_parse_duid_type_one("link-layer-time:2000-01-01 00:00:00 UTC", DUID_TYPE_LLT, (usec_t) 946684800000000);
test_config_parse_duid_type_one("vendor", 0, DUID_TYPE_EN, 0); test_config_parse_duid_type_one("vendor", DUID_TYPE_EN, 0);
test_config_parse_duid_type_one("vendor:2000-01-01 00:00:00 UTC", 0, 0, 0); test_config_parse_duid_type_one("vendor:2000-01-01 00:00:00 UTC", 0, 0);
test_config_parse_duid_type_one("link-layer", 0, DUID_TYPE_LL, 0); test_config_parse_duid_type_one("link-layer", DUID_TYPE_LL, 0);
test_config_parse_duid_type_one("link-layer:2000-01-01 00:00:00 UTC", 0, 0, 0); test_config_parse_duid_type_one("link-layer:2000-01-01 00:00:00 UTC", 0, 0);
test_config_parse_duid_type_one("uuid", 0, DUID_TYPE_UUID, 0); test_config_parse_duid_type_one("uuid", DUID_TYPE_UUID, 0);
test_config_parse_duid_type_one("uuid:2000-01-01 00:00:00 UTC", 0, 0, 0); test_config_parse_duid_type_one("uuid:2000-01-01 00:00:00 UTC", 0, 0);
test_config_parse_duid_type_one("foo", 0, 0, 0); test_config_parse_duid_type_one("foo", 0, 0);
test_config_parse_duid_type_one("foo:2000-01-01 00:00:00 UTC", 0, 0, 0); test_config_parse_duid_type_one("foo:2000-01-01 00:00:00 UTC", 0, 0);
} }
static void test_config_parse_duid_rawdata_one(const char *rvalue, int ret, const DUID* expected) { static void test_config_parse_duid_rawdata_one(const char *rvalue, const DUID* expected) {
DUID actual = {}; DUID actual = {};
int r;
_cleanup_free_ char *d = NULL;
r = config_parse_duid_rawdata("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL); ASSERT_OK(config_parse_duid_rawdata("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL));
d = hexmem(actual.raw_data, actual.raw_data_len);
log_info_errno(r, "\"%s\"\"%s\" (%m)",
rvalue, strnull(d));
assert_se(r == ret);
if (expected) { if (expected) {
assert_se(actual.raw_data_len == expected->raw_data_len); _cleanup_free_ char *d = NULL, *e = NULL;
assert_se(memcmp(actual.raw_data, expected->raw_data, expected->raw_data_len) == 0); d = hexmem(actual.raw_data, actual.raw_data_len);
e = hexmem(expected->raw_data, expected->raw_data_len);
ASSERT_STREQ(strna(d), strna(e));
} }
} }
static void test_config_parse_ether_addr_one(const char *rvalue, int ret, const struct ether_addr* expected) { static void test_config_parse_ether_addr_one(const char *rvalue, const struct ether_addr* expected) {
struct ether_addr *actual = NULL; _cleanup_free_ struct ether_addr *actual = NULL;
int r;
r = config_parse_ether_addr("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL); ASSERT_OK(config_parse_ether_addr("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL));
assert_se(ret == r);
if (expected) { if (expected) {
assert_se(actual); ASSERT_NOT_NULL(actual);
assert_se(ether_addr_equal(expected, actual)); ASSERT_STREQ(ETHER_ADDR_TO_STR(actual), ETHER_ADDR_TO_STR(expected));
} else } else
assert_se(actual == NULL); ASSERT_NULL(actual);
free(actual);
} }
static void test_config_parse_ether_addrs_one(const char *rvalue, const struct ether_addr* list, size_t n) { static void test_config_parse_ether_addrs_one(const char *rvalue, const struct ether_addr* list, size_t n) {
_cleanup_set_free_free_ Set *s = NULL; _cleanup_set_free_free_ Set *s = NULL;
assert_se(config_parse_ether_addrs("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &s, NULL) == 0); ASSERT_OK(config_parse_ether_addrs("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &s, NULL));
assert_se(set_size(s) == n); ASSERT_EQ(set_size(s), n);
for (size_t m = 0; m < n; m++) { for (size_t m = 0; m < n; m++) {
_cleanup_free_ struct ether_addr *q = NULL; _cleanup_free_ struct ether_addr *q = NULL;
assert_se(q = set_remove(s, &list[m])); ASSERT_NOT_NULL(q = set_remove(s, &list[m]));
} }
assert_se(set_isempty(s)); ASSERT_TRUE(set_isempty(s));
} }
#define STR_OK \ #define STR_OK \
@ -115,19 +104,19 @@ static void test_config_parse_ether_addrs_one(const char *rvalue, const struct e
} }
TEST(config_parse_duid_rawdata) { TEST(config_parse_duid_rawdata) {
test_config_parse_duid_rawdata_one("", 0, &(DUID){}); test_config_parse_duid_rawdata_one("", &(DUID){});
test_config_parse_duid_rawdata_one("00:11:22:33:44:55:66:77", 0, test_config_parse_duid_rawdata_one("00:11:22:33:44:55:66:77",
&(DUID){0, 8, {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77}}); &(DUID){0, 8, {0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77}});
test_config_parse_duid_rawdata_one("00:11:22:", 0, test_config_parse_duid_rawdata_one("00:11:22:",
&(DUID){0, 3, {0x00,0x11,0x22}}); &(DUID){0, 3, {0x00,0x11,0x22}});
test_config_parse_duid_rawdata_one("000:11:22", 0, &(DUID){}); /* error, output is all zeros */ test_config_parse_duid_rawdata_one("000:11:22", &(DUID){}); /* error, output is all zeros */
test_config_parse_duid_rawdata_one("00:111:22", 0, &(DUID){}); test_config_parse_duid_rawdata_one("00:111:22", &(DUID){});
test_config_parse_duid_rawdata_one("0:1:2:3:4:5:6:7", 0, test_config_parse_duid_rawdata_one("0:1:2:3:4:5:6:7",
&(DUID){0, 8, {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7}}); &(DUID){0, 8, {0x0, 0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7}});
test_config_parse_duid_rawdata_one("11::", 0, &(DUID){0, 1, {0x11}}); /* FIXME: should this be an error? */ test_config_parse_duid_rawdata_one("11::", &(DUID){0, 1, {0x11}}); /* FIXME: should this be an error? */
test_config_parse_duid_rawdata_one("abcdef", 0, &(DUID){}); test_config_parse_duid_rawdata_one("abcdef", &(DUID){});
test_config_parse_duid_rawdata_one(STR_TOO_LONG, 0, &(DUID){}); test_config_parse_duid_rawdata_one(STR_TOO_LONG, &(DUID){});
test_config_parse_duid_rawdata_one(STR_OK, 0, &(DUID){0, 128, BYTES_OK}); test_config_parse_duid_rawdata_one(STR_OK, &(DUID){0, 128, BYTES_OK});
} }
TEST(config_parse_ether_addr) { TEST(config_parse_ether_addr) {
@ -136,32 +125,32 @@ TEST(config_parse_ether_addr) {
{ .ether_addr_octet = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab } }, { .ether_addr_octet = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab } },
}; };
test_config_parse_ether_addr_one("", 0, NULL); test_config_parse_ether_addr_one("", NULL);
test_config_parse_ether_addr_one("no:ta:ma:ca:dd:re", 0, NULL); test_config_parse_ether_addr_one("no:ta:ma:ca:dd:re", NULL);
test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:fx", 0, NULL); test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:fx", NULL);
test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff", 0, &t[0]); test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff", &t[0]);
test_config_parse_ether_addr_one(" aa:bb:cc:dd:ee:ff", 0, NULL); test_config_parse_ether_addr_one(" aa:bb:cc:dd:ee:ff", NULL);
test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff \t\n", 0, NULL); test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff \t\n", NULL);
test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff \t\nxxx", 0, NULL); test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff \t\nxxx", NULL);
test_config_parse_ether_addr_one("aa:bb:cc: dd:ee:ff", 0, NULL); test_config_parse_ether_addr_one("aa:bb:cc: dd:ee:ff", NULL);
test_config_parse_ether_addr_one("aa:bb:cc:d d:ee:ff", 0, NULL); test_config_parse_ether_addr_one("aa:bb:cc:d d:ee:ff", NULL);
test_config_parse_ether_addr_one("aa:bb:cc:dd:ee", 0, NULL); test_config_parse_ether_addr_one("aa:bb:cc:dd:ee", NULL);
test_config_parse_ether_addr_one("9:aa:bb:cc:dd:ee:ff", 0, NULL); test_config_parse_ether_addr_one("9:aa:bb:cc:dd:ee:ff", NULL);
test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff:gg", 0, NULL); test_config_parse_ether_addr_one("aa:bb:cc:dd:ee:ff:gg", NULL);
test_config_parse_ether_addr_one("aa:Bb:CC:dd:ee:ff", 0, &t[0]); test_config_parse_ether_addr_one("aa:Bb:CC:dd:ee:ff", &t[0]);
test_config_parse_ether_addr_one("01:23:45:67:89:aB", 0, &t[1]); test_config_parse_ether_addr_one("01:23:45:67:89:aB", &t[1]);
test_config_parse_ether_addr_one("1:23:45:67:89:aB", 0, &t[1]); test_config_parse_ether_addr_one("1:23:45:67:89:aB", &t[1]);
test_config_parse_ether_addr_one("aa-bb-cc-dd-ee-ff", 0, &t[0]); test_config_parse_ether_addr_one("aa-bb-cc-dd-ee-ff", &t[0]);
test_config_parse_ether_addr_one("AA-BB-CC-DD-EE-FF", 0, &t[0]); test_config_parse_ether_addr_one("AA-BB-CC-DD-EE-FF", &t[0]);
test_config_parse_ether_addr_one("01-23-45-67-89-ab", 0, &t[1]); test_config_parse_ether_addr_one("01-23-45-67-89-ab", &t[1]);
test_config_parse_ether_addr_one("aabb.ccdd.eeff", 0, &t[0]); test_config_parse_ether_addr_one("aabb.ccdd.eeff", &t[0]);
test_config_parse_ether_addr_one("0123.4567.89ab", 0, &t[1]); test_config_parse_ether_addr_one("0123.4567.89ab", &t[1]);
test_config_parse_ether_addr_one("123.4567.89ab.", 0, NULL); test_config_parse_ether_addr_one("123.4567.89ab.", NULL);
test_config_parse_ether_addr_one("aabbcc.ddeeff", 0, NULL); test_config_parse_ether_addr_one("aabbcc.ddeeff", NULL);
test_config_parse_ether_addr_one("aabbccddeeff", 0, NULL); test_config_parse_ether_addr_one("aabbccddeeff", NULL);
test_config_parse_ether_addr_one("aabbccddee:ff", 0, NULL); test_config_parse_ether_addr_one("aabbccddee:ff", NULL);
test_config_parse_ether_addr_one("012345.6789ab", 0, NULL); test_config_parse_ether_addr_one("012345.6789ab", NULL);
test_config_parse_ether_addr_one("123.4567.89ab", 0, &t[1]); test_config_parse_ether_addr_one("123.4567.89ab", &t[1]);
test_config_parse_ether_addrs_one("", t, 0); test_config_parse_ether_addrs_one("", t, 0);
test_config_parse_ether_addrs_one("no:ta:ma:ca:dd:re", t, 0); test_config_parse_ether_addrs_one("no:ta:ma:ca:dd:re", t, 0);

View File

@ -232,7 +232,7 @@ int settings_allocate_properties(Settings *s) {
return 0; return 0;
} }
DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode, volatile_mode, VolatileMode, "Failed to parse volatile mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_volatile_mode, volatile_mode, VolatileMode);
int config_parse_expose_port( int config_parse_expose_port(
const char *unit, const char *unit,
@ -832,7 +832,7 @@ int config_parse_cpu_affinity(
return parse_cpu_set_extend(rvalue, &settings->cpu_set, true, unit, filename, line, lvalue); return parse_cpu_set_extend(rvalue, &settings->cpu_set, true, unit, filename, line, lvalue);
} }
DEFINE_CONFIG_PARSE_ENUM(config_parse_resolv_conf, resolv_conf_mode, ResolvConfMode, "Failed to parse resolv.conf mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_resolv_conf, resolv_conf_mode, ResolvConfMode);
static const char *const resolv_conf_mode_table[_RESOLV_CONF_MODE_MAX] = { static const char *const resolv_conf_mode_table[_RESOLV_CONF_MODE_MAX] = {
[RESOLV_CONF_OFF] = "off", [RESOLV_CONF_OFF] = "off",
@ -914,7 +914,7 @@ int config_parse_link_journal(
return 0; return 0;
} }
DEFINE_CONFIG_PARSE_ENUM(config_parse_timezone_mode, timezone_mode, TimezoneMode, "Failed to parse timezone mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_timezone_mode, timezone_mode, TimezoneMode);
static const char *const timezone_mode_table[_TIMEZONE_MODE_MAX] = { static const char *const timezone_mode_table[_TIMEZONE_MODE_MAX] = {
[TIMEZONE_OFF] = "off", [TIMEZONE_OFF] = "off",
@ -927,7 +927,7 @@ static const char *const timezone_mode_table[_TIMEZONE_MODE_MAX] = {
DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(timezone_mode, TimezoneMode, TIMEZONE_AUTO); DEFINE_STRING_TABLE_LOOKUP_WITH_BOOLEAN(timezone_mode, TimezoneMode, TIMEZONE_AUTO);
DEFINE_CONFIG_PARSE_ENUM(config_parse_userns_ownership, user_namespace_ownership, UserNamespaceOwnership, "Failed to parse user namespace ownership mode"); DEFINE_CONFIG_PARSE_ENUM(config_parse_userns_ownership, user_namespace_ownership, UserNamespaceOwnership);
static const char *const user_namespace_ownership_table[_USER_NAMESPACE_OWNERSHIP_MAX] = { static const char *const user_namespace_ownership_table[_USER_NAMESPACE_OWNERSHIP_MAX] = {
[USER_NAMESPACE_OWNERSHIP_OFF] = "off", [USER_NAMESPACE_OWNERSHIP_OFF] = "off",

View File

@ -1712,7 +1712,7 @@ static int config_parse_default_subvolume(
return free_and_replace(*subvol, p); return free_and_replace(*subvol, p);
} }
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_encrypt, encrypt_mode, EncryptMode, ENCRYPT_OFF, "Invalid encryption mode"); static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_encrypt, encrypt_mode, EncryptMode, ENCRYPT_OFF);
static int config_parse_gpt_flags( static int config_parse_gpt_flags(
const char *unit, const char *unit,
@ -1899,8 +1899,8 @@ static int config_parse_encrypted_volume(
return 0; return 0;
} }
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_verity, verity_mode, VerityMode, VERITY_OFF, "Invalid verity mode"); static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_verity, verity_mode, VerityMode, VERITY_OFF);
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_minimize, minimize_mode, MinimizeMode, MINIMIZE_OFF, "Invalid minimize mode"); static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_minimize, minimize_mode, MinimizeMode, MINIMIZE_OFF);
static int partition_finalize_fstype(Partition *p, const char *path) { static int partition_finalize_fstype(Partition *p, const char *path) {
_cleanup_free_ char *e = NULL, *upper = NULL; _cleanup_free_ char *e = NULL, *upper = NULL;

View File

@ -62,7 +62,7 @@ static const char* const pstore_storage_table[_PSTORE_STORAGE_MAX] = {
}; };
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(pstore_storage, PStoreStorage); DEFINE_PRIVATE_STRING_TABLE_LOOKUP(pstore_storage, PStoreStorage);
static DEFINE_CONFIG_PARSE_ENUM(config_parse_pstore_storage, pstore_storage, PStoreStorage, "Failed to parse storage setting"); static DEFINE_CONFIG_PARSE_ENUM(config_parse_pstore_storage, pstore_storage, PStoreStorage);
static PStoreStorage arg_storage = PSTORE_STORAGE_EXTERNAL; static PStoreStorage arg_storage = PSTORE_STORAGE_EXTERNAL;

View File

@ -21,7 +21,7 @@
#include "strv.h" #include "strv.h"
#include "utf8.h" #include "utf8.h"
DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_stub_listener_mode, dns_stub_listener_mode, DnsStubListenerMode, "Failed to parse DNS stub listener mode setting"); DEFINE_CONFIG_PARSE_ENUM(config_parse_dns_stub_listener_mode, dns_stub_listener_mode, DnsStubListenerMode);
static int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char *word) { static int manager_add_dns_server_by_string(Manager *m, DnsServerType type, const char *word) {
_cleanup_free_ char *server_name = NULL; _cleanup_free_ char *server_name = NULL;

View File

@ -852,7 +852,7 @@ int _hashmap_by_section_find_unused_line(
} }
#define DEFINE_PARSER(type, vartype, conv_func) \ #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(int, int, safe_atoi);
DEFINE_PARSER(long, long, safe_atoli); DEFINE_PARSER(long, long, safe_atoli);
@ -892,13 +892,11 @@ int config_parse_iec_size(
r = parse_size(rvalue, 1024, &v); r = parse_size(rvalue, 1024, &v);
if (r >= 0 && (uint64_t) (size_t) v != v) if (r >= 0 && (uint64_t) (size_t) v != v)
r = -ERANGE; r = -ERANGE;
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse size value '%s', ignoring: %m", rvalue); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
return 0;
}
*sz = (size_t) v; *sz = (size_t) v;
return 0; return 1;
} }
int config_parse_si_uint64( int config_parse_si_uint64(
@ -922,9 +920,9 @@ int config_parse_si_uint64(
r = parse_size(rvalue, 1000, sz); r = parse_size(rvalue, 1000, sz);
if (r < 0) if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse size value '%s', ignoring: %m", rvalue); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
return 0; return 1;
} }
int config_parse_iec_uint64( int config_parse_iec_uint64(
@ -948,9 +946,9 @@ int config_parse_iec_uint64(
r = parse_size(rvalue, 1024, bytes); r = parse_size(rvalue, 1024, bytes);
if (r < 0) if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse size value '%s', ignoring: %m", rvalue); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
return 0; return 1;
} }
int config_parse_iec_uint64_infinity( int config_parse_iec_uint64_infinity(
@ -971,7 +969,7 @@ int config_parse_iec_uint64_infinity(
if (streq(rvalue, "infinity")) { if (streq(rvalue, "infinity")) {
*bytes = UINT64_MAX; *bytes = UINT64_MAX;
return 0; return 1;
} }
return config_parse_iec_uint64(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata); return config_parse_iec_uint64(unit, filename, line, section, section_line, lvalue, ltype, rvalue, data, userdata);
@ -989,23 +987,21 @@ int config_parse_bool(
void *data, void *data,
void *userdata) { void *userdata) {
int k;
bool *b = ASSERT_PTR(data); bool *b = ASSERT_PTR(data);
bool fatal = ltype; bool fatal = ltype;
int r;
assert(filename); assert(filename);
assert(lvalue); assert(lvalue);
assert(rvalue); assert(rvalue);
k = parse_boolean(rvalue); r = parse_boolean(rvalue);
if (k < 0) { if (r < 0) {
log_syntax(unit, fatal ? LOG_ERR : LOG_WARNING, filename, line, k, log_syntax_parse_error_full(unit, filename, line, r, fatal, lvalue, rvalue);
"Failed to parse boolean value%s: %s",
fatal ? "" : ", ignoring", rvalue);
return fatal ? -ENOEXEC : 0; return fatal ? -ENOEXEC : 0;
} }
*b = k; *b = r;
return 1; /* set */ return 1; /* set */
} }
@ -1027,12 +1023,8 @@ int config_parse_uint32_flag(
assert(ltype != 0); assert(ltype != 0);
r = isempty(rvalue) ? 0 : parse_boolean(rvalue); r = isempty(rvalue) ? 0 : parse_boolean(rvalue);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Failed to parse %s=%s. Ignoring assignment: %m",
lvalue, rvalue);
return 0;
}
SET_FLAG(*flags, ltype, r); SET_FLAG(*flags, ltype, r);
return 1; return 1;
@ -1058,12 +1050,14 @@ int config_parse_id128(
assert(rvalue); assert(rvalue);
r = id128_from_string_nonzero(rvalue, result); r = id128_from_string_nonzero(rvalue, result);
if (r == -ENXIO) if (r == -ENXIO) {
log_syntax(unit, LOG_WARNING, filename, line, r, "128-bit ID/UUID is all 0, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "128-bit ID/UUID is all 0, ignoring: %s", rvalue);
else if (r < 0) return 0;
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 128-bit ID/UUID, ignoring: %s", rvalue); }
if (r < 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
return 0; return 1;
} }
int config_parse_tristate( int config_parse_tristate(
@ -1093,11 +1087,8 @@ int config_parse_tristate(
} }
r = parse_tristate(rvalue, t); r = parse_tristate(rvalue, t);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Failed to parse boolean value for %s=, ignoring: %s", lvalue, rvalue);
return 0;
}
return 1; return 1;
} }
@ -1144,7 +1135,7 @@ int config_parse_string(
return 0; return 0;
} }
r = free_and_strdup_warn(s, empty_to_null(rvalue)); r = free_and_strdup_warn(s, rvalue);
if (r < 0) if (r < 0)
return r; return r;
@ -1172,7 +1163,7 @@ int config_parse_dns_name(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*hostname = mfree(*hostname); *hostname = mfree(*hostname);
return 0; return 1;
} }
r = dns_name_is_valid(rvalue); r = dns_name_is_valid(rvalue);
@ -1187,7 +1178,11 @@ int config_parse_dns_name(
return 0; return 0;
} }
return free_and_strdup_warn(hostname, rvalue); r = free_and_strdup_warn(hostname, rvalue);
if (r < 0)
return r;
return 1;
} }
int config_parse_hostname( int config_parse_hostname(
@ -1210,7 +1205,7 @@ int config_parse_hostname(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*hostname = mfree(*hostname); *hostname = mfree(*hostname);
return 0; return 1;
} }
if (!hostname_is_valid(rvalue, 0)) { if (!hostname_is_valid(rvalue, 0)) {
@ -1244,8 +1239,10 @@ int config_parse_path(
assert(lvalue); assert(lvalue);
assert(rvalue); assert(rvalue);
if (isempty(rvalue)) if (isempty(rvalue)) {
goto finalize; *s = mfree(*s);
return 1;
}
n = strdup(rvalue); n = strdup(rvalue);
if (!n) if (!n)
@ -1255,8 +1252,8 @@ int config_parse_path(
if (r < 0) if (r < 0)
return fatal ? -ENOEXEC : 0; return fatal ? -ENOEXEC : 0;
finalize: free_and_replace(*s, n);
return free_and_replace(*s, n); return 1;
} }
int config_parse_strv( int config_parse_strv(
@ -1266,7 +1263,7 @@ int config_parse_strv(
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *lvalue, const char *lvalue,
int ltype, int ltype, /* When true, duplicated entries will be filtered. */
const char *rvalue, const char *rvalue,
void *data, void *data,
void *userdata) { void *userdata) {
@ -1280,26 +1277,29 @@ int config_parse_strv(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*sv = strv_free(*sv); *sv = strv_free(*sv);
return 0; return 1;
} }
_cleanup_strv_free_ char **strv = NULL;
for (const char *p = rvalue;;) { for (const char *p = rvalue;;) {
char *word = NULL; char *word;
r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE); r = extract_first_word(&p, &word, NULL, EXTRACT_UNQUOTE|EXTRACT_RETAIN_ESCAPE);
if (r < 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
if (r == 0) if (r == 0)
return 0; break;
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue);
return 0;
}
r = strv_consume(sv, word); r = strv_consume(&strv, word);
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
} }
r = strv_extend_strv(sv, strv, /* filter_duplicates = */ ltype);
if (r < 0)
return log_oom();
return 1;
} }
int config_parse_warn_compat( int config_parse_warn_compat(
@ -1357,14 +1357,12 @@ int config_parse_log_facility(
assert(data); assert(data);
x = log_facility_unshifted_from_string(rvalue); x = log_facility_unshifted_from_string(rvalue);
if (x < 0) { if (x < 0)
log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse log facility, ignoring: %s", rvalue); return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue);
return 0;
}
*o = (x << 3) | LOG_PRI(*o); *o = (x << 3) | LOG_PRI(*o);
return 0; return 1;
} }
int config_parse_log_level( int config_parse_log_level(
@ -1387,17 +1385,15 @@ int config_parse_log_level(
assert(data); assert(data);
x = log_level_from_string(rvalue); x = log_level_from_string(rvalue);
if (x < 0) { if (x < 0)
log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse log level, ignoring: %s", rvalue); return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue);
return 0;
}
if (*o < 0) /* if it wasn't initialized so far, assume zero facility */ if (*o < 0) /* if it wasn't initialized so far, assume zero facility */
*o = x; *o = x;
else else
*o = (*o & LOG_FACMASK) | x; *o = (*o & LOG_FACMASK) | x;
return 0; return 1;
} }
int config_parse_signal( int config_parse_signal(
@ -1420,13 +1416,11 @@ int config_parse_signal(
assert(sig); assert(sig);
r = signal_from_string(rvalue); r = signal_from_string(rvalue);
if (r <= 0) { if (r <= 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse signal name, ignoring: %s", rvalue); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
return 0;
}
*sig = r; *sig = r;
return 0; return 1;
} }
int config_parse_personality( int config_parse_personality(
@ -1448,18 +1442,17 @@ int config_parse_personality(
assert(rvalue); assert(rvalue);
assert(personality); assert(personality);
if (isempty(rvalue)) if (isempty(rvalue)) {
p = PERSONALITY_INVALID; *personality = PERSONALITY_INVALID;
else { return 1;
p = personality_from_string(rvalue);
if (p == PERSONALITY_INVALID) {
log_syntax(unit, LOG_WARNING, filename, line, 0, "Failed to parse personality, ignoring: %s", rvalue);
return 0;
}
} }
p = personality_from_string(rvalue);
if (p == PERSONALITY_INVALID)
return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue);
*personality = p; *personality = p;
return 0; return 1;
} }
int config_parse_ifname( int config_parse_ifname(
@ -1491,9 +1484,9 @@ int config_parse_ifname(
return 0; return 0;
} }
r = free_and_strdup(s, rvalue); r = free_and_strdup_warn(s, rvalue);
if (r < 0) if (r < 0)
return log_oom(); return r;
return 1; return 1;
} }
@ -1520,21 +1513,15 @@ int config_parse_ifnames(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*s = strv_free(*s); *s = strv_free(*s);
return 0; return 1;
} }
for (const char *p = rvalue;;) { for (const char *p = rvalue;;) {
_cleanup_free_ char *word = NULL; _cleanup_free_ char *word = NULL;
r = extract_first_word(&p, &word, NULL, 0); r = extract_first_word(&p, &word, NULL, 0);
if (r == -ENOMEM) if (r < 0)
return log_oom(); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to extract interface name, ignoring assignment: %s",
rvalue);
return 0;
}
if (r == 0) if (r == 0)
break; break;
@ -1554,7 +1541,7 @@ int config_parse_ifnames(
if (r < 0) if (r < 0)
return log_oom(); return log_oom();
return 0; return 1;
} }
int config_parse_ip_port( int config_parse_ip_port(
@ -1579,18 +1566,15 @@ int config_parse_ip_port(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*s = 0; *s = 0;
return 0; return 1;
} }
r = parse_ip_port(rvalue, &port); r = parse_ip_port(rvalue, &port);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse port '%s'.", rvalue); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
return 0;
}
*s = port; *s = port;
return 1;
return 0;
} }
int config_parse_mtu( int config_parse_mtu(
@ -1618,11 +1602,8 @@ int config_parse_mtu(
rvalue); rvalue);
return 0; return 0;
} }
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Failed to parse MTU value '%s', ignoring: %m", rvalue);
return 0;
}
return 1; return 1;
} }
@ -1650,10 +1631,8 @@ int config_parse_rlimit(
log_syntax(unit, LOG_WARNING, filename, line, r, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Soft resource limit chosen higher than hard limit, ignoring: %s", rvalue);
return 0; return 0;
} }
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
return 0;
}
if (rl[ltype]) if (rl[ltype])
*rl[ltype] = d; *rl[ltype] = d;
@ -1663,7 +1642,7 @@ int config_parse_rlimit(
return log_oom(); return log_oom();
} }
return 0; return 1;
} }
int config_parse_permille( int config_parse_permille(
@ -1686,15 +1665,11 @@ int config_parse_permille(
assert(rvalue); assert(rvalue);
r = parse_permille(rvalue); r = parse_permille(rvalue);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Failed to parse permille value, ignoring: %s", rvalue);
return 0;
}
*permille = (unsigned) r; *permille = (unsigned) r;
return 1;
return 0;
} }
int config_parse_vlanprotocol( int config_parse_vlanprotocol(
@ -1716,20 +1691,17 @@ int config_parse_vlanprotocol(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*vlan_protocol = -1; *vlan_protocol = -1;
return 0; return 1;
} }
if (STR_IN_SET(rvalue, "802.1ad", "802.1AD")) if (STR_IN_SET(rvalue, "802.1ad", "802.1AD"))
*vlan_protocol = ETH_P_8021AD; *vlan_protocol = ETH_P_8021AD;
else if (STR_IN_SET(rvalue, "802.1q", "802.1Q")) else if (STR_IN_SET(rvalue, "802.1q", "802.1Q"))
*vlan_protocol = ETH_P_8021Q; *vlan_protocol = ETH_P_8021Q;
else { else
log_syntax(unit, LOG_WARNING, filename, line, 0, return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue);
"Failed to parse VLAN protocol value, ignoring: %s", rvalue);
return 0;
}
return 0; return 1;
} }
int config_parse_hw_addr( int config_parse_hw_addr(
@ -1753,18 +1725,15 @@ int config_parse_hw_addr(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*hwaddr = HW_ADDR_NULL; *hwaddr = HW_ADDR_NULL;
return 0; return 1;
} }
r = parse_hw_addr_full(rvalue, ltype, &a); r = parse_hw_addr_full(rvalue, ltype, &a);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Not a valid hardware address, ignoring assignment: %s", rvalue);
return 0;
}
*hwaddr = a; *hwaddr = a;
return 0; return 1;
} }
int config_parse_hw_addrs( int config_parse_hw_addrs(
@ -1789,7 +1758,7 @@ int config_parse_hw_addrs(
if (isempty(rvalue)) { if (isempty(rvalue)) {
/* Empty assignment resets the list */ /* Empty assignment resets the list */
*hwaddrs = set_free(*hwaddrs); *hwaddrs = set_free(*hwaddrs);
return 0; return 1;
} }
for (const char *p = rvalue;;) { for (const char *p = rvalue;;) {
@ -1797,15 +1766,10 @@ int config_parse_hw_addrs(
_cleanup_free_ struct hw_addr_data *n = NULL; _cleanup_free_ struct hw_addr_data *n = NULL;
r = extract_first_word(&p, &word, NULL, 0); r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
if (r == 0) if (r == 0)
return 0; return 1;
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
n = new(struct hw_addr_data, 1); n = new(struct hw_addr_data, 1);
if (!n) if (!n)
@ -1846,7 +1810,7 @@ int config_parse_ether_addr(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*hwaddr = mfree(*hwaddr); *hwaddr = mfree(*hwaddr);
return 0; return 1;
} }
n = new0(struct ether_addr, 1); n = new0(struct ether_addr, 1);
@ -1854,15 +1818,11 @@ int config_parse_ether_addr(
return log_oom(); return log_oom();
r = parse_ether_addr(rvalue, n); r = parse_ether_addr(rvalue, n);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Not a valid MAC address, ignoring assignment: %s", rvalue);
return 0;
}
free_and_replace(*hwaddr, n); free_and_replace(*hwaddr, n);
return 1;
return 0;
} }
int config_parse_ether_addrs( int config_parse_ether_addrs(
@ -1887,7 +1847,7 @@ int config_parse_ether_addrs(
if (isempty(rvalue)) { if (isempty(rvalue)) {
/* Empty assignment resets the list */ /* Empty assignment resets the list */
*hwaddrs = set_free(*hwaddrs); *hwaddrs = set_free(*hwaddrs);
return 0; return 1;
} }
for (const char *p = rvalue;;) { for (const char *p = rvalue;;) {
@ -1895,15 +1855,10 @@ int config_parse_ether_addrs(
_cleanup_free_ struct ether_addr *n = NULL; _cleanup_free_ struct ether_addr *n = NULL;
r = extract_first_word(&p, &word, NULL, 0); r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
if (r == 0) if (r == 0)
return 0; return 1;
if (r == -ENOMEM)
return log_oom();
if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid syntax, ignoring: %s", rvalue);
return 0;
}
n = new(struct ether_addr, 1); n = new(struct ether_addr, 1);
if (!n) if (!n)
@ -1950,15 +1905,12 @@ int config_parse_in_addr_non_null(
*ipv4 = (struct in_addr) {}; *ipv4 = (struct in_addr) {};
else else
*ipv6 = (struct in6_addr) {}; *ipv6 = (struct in6_addr) {};
return 0; return 1;
} }
r = in_addr_from_string(ltype, rvalue, &a); r = in_addr_from_string(ltype, rvalue, &a);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue);
return 0;
}
if (!in_addr_is_set(ltype, &a)) { if (!in_addr_is_set(ltype, &a)) {
log_syntax(unit, LOG_WARNING, filename, line, 0, log_syntax(unit, LOG_WARNING, filename, line, 0,
@ -1970,7 +1922,7 @@ int config_parse_in_addr_non_null(
*ipv4 = a.in; *ipv4 = a.in;
else else
*ipv6 = a.in6; *ipv6 = a.in6;
return 0; return 1;
} }
int config_parse_unsigned_bounded( int config_parse_unsigned_bounded(
@ -1979,8 +1931,8 @@ int config_parse_unsigned_bounded(
unsigned line, unsigned line,
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *name, const char *lvalue,
const char *value, const char *rvalue,
unsigned min, unsigned min,
unsigned max, unsigned max,
bool ignoring, bool ignoring,
@ -1989,26 +1941,21 @@ int config_parse_unsigned_bounded(
int r; int r;
assert(filename); assert(filename);
assert(name); assert(lvalue);
assert(value); assert(rvalue);
assert(ret); assert(ret);
r = safe_atou_bounded(value, min, max, ret); r = safe_atou_bounded(rvalue, min, max, ret);
if (r == -ERANGE) if (r == -ERANGE) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Invalid '%s=%s', allowed range is %u..%u%s.", "Invalid '%s=%s', allowed range is %u..%u%s.",
name, value, min, max, ignoring ? ", ignoring" : ""); lvalue, rvalue, min, max, ignoring ? ", ignoring" : "");
else if (r < 0) return ignoring ? 0 : r;
log_syntax(unit, LOG_WARNING, filename, line, r, }
"Failed to parse '%s=%s'%s: %m", if (r < 0)
name, value, ignoring ? ", ignoring" : ""); return log_syntax_parse_error_full(unit, filename, line, r, /* critical = */ !ignoring, lvalue, rvalue);
if (r >= 0) return 1; /* Return 1 if something was set */
return 1; /* Return 1 if something was set */
else if (ignoring)
return 0;
else
return r;
} }
int config_parse_calendar( int config_parse_calendar(
@ -2034,21 +1981,20 @@ int config_parse_calendar(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*cr = calendar_spec_free(*cr); *cr = calendar_spec_free(*cr);
return 0; return 1;
} }
r = calendar_spec_from_string(rvalue, &c); r = calendar_spec_from_string(rvalue, &c);
if (r < 0) if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse calendar specification, ignoring: %s", rvalue); return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
else
*cr = TAKE_PTR(c);
return 0; free_and_replace_full(*cr, c, calendar_spec_free);
return 1;
} }
DEFINE_CONFIG_PARSE(config_parse_percent, parse_percent, "Failed to parse percent value"); DEFINE_CONFIG_PARSE(config_parse_percent, parse_percent);
DEFINE_CONFIG_PARSE(config_parse_permyriad, parse_permyriad, "Failed to parse permyriad value"); DEFINE_CONFIG_PARSE(config_parse_permyriad, parse_permyriad);
DEFINE_CONFIG_PARSE_PTR(config_parse_sec_fix_0, parse_sec_fix_0, usec_t, "Failed to parse time value"); DEFINE_CONFIG_PARSE_PTR(config_parse_sec_fix_0, parse_sec_fix_0, usec_t);
int config_parse_timezone( int config_parse_timezone(
const char *unit, const char *unit,
@ -2071,17 +2017,18 @@ int config_parse_timezone(
if (isempty(rvalue)) { if (isempty(rvalue)) {
*tz = mfree(*tz); *tz = mfree(*tz);
return 0; return 1;
} }
r = verify_timezone(rvalue, LOG_WARNING); r = verify_timezone(rvalue, LOG_WARNING);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Timezone is not valid, ignoring assignment: %s", rvalue);
return 0;
}
return free_and_strdup_warn(tz, rvalue); r = free_and_strdup_warn(tz, rvalue);
if (r < 0)
return r;
return 1;
} }
int config_parse_ip_protocol( int config_parse_ip_protocol(
@ -2100,12 +2047,8 @@ int config_parse_ip_protocol(
int r; int r;
r = isempty(rvalue) ? 0 : parse_ip_protocol_full(rvalue, /* relaxed= */ ltype); r = isempty(rvalue) ? 0 : parse_ip_protocol_full(rvalue, /* relaxed= */ ltype);
if (r < 0) { if (r < 0)
log_syntax(unit, LOG_WARNING, filename, line, r, return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
"Failed to parse '%s=%s', ignoring: %m",
lvalue, rvalue);
return 0;
}
if (r > UINT8_MAX) { if (r > UINT8_MAX) {
/* linux/fib_rules.h and linux/fou.h define the netlink field as one byte, so we need to /* linux/fib_rules.h and linux/fou.h define the netlink field as one byte, so we need to

View File

@ -305,7 +305,7 @@ typedef enum ConfigParseStringFlags {
CONFIG_PARSE_STRING_SAFE_AND_ASCII = CONFIG_PARSE_STRING_SAFE | CONFIG_PARSE_STRING_ASCII, CONFIG_PARSE_STRING_SAFE_AND_ASCII = CONFIG_PARSE_STRING_SAFE | CONFIG_PARSE_STRING_ASCII,
} ConfigParseStringFlags; } ConfigParseStringFlags;
#define DEFINE_CONFIG_PARSE(function, parser, msg) \ #define DEFINE_CONFIG_PARSE(function, parser) \
CONFIG_PARSER_PROTOTYPE(function) { \ CONFIG_PARSER_PROTOTYPE(function) { \
int *i = data, r; \ int *i = data, r; \
\ \
@ -315,17 +315,14 @@ typedef enum ConfigParseStringFlags {
assert(data); \ assert(data); \
\ \
r = parser(rvalue); \ r = parser(rvalue); \
if (r < 0) { \ if (r < 0) \
log_syntax(unit, LOG_WARNING, filename, line, r, \ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); \
msg ", ignoring: %s", rvalue); \
return 0; \
} \
\ \
*i = r; \ *i = r; \
return 1; \ return 1; \
} }
#define DEFINE_CONFIG_PARSE_PTR(function, parser, type, msg) \ #define DEFINE_CONFIG_PARSE_PTR(function, parser, type) \
CONFIG_PARSER_PROTOTYPE(function) { \ CONFIG_PARSER_PROTOTYPE(function) { \
type *i = ASSERT_PTR(data); \ type *i = ASSERT_PTR(data); \
int r; \ int r; \
@ -336,13 +333,12 @@ typedef enum ConfigParseStringFlags {
\ \
r = parser(rvalue, i); \ r = parser(rvalue, i); \
if (r < 0) \ if (r < 0) \
log_syntax(unit, LOG_WARNING, filename, line, r, \ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); \
msg ", ignoring: %s", rvalue); \
\ \
return 1; \ 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) { \ CONFIG_PARSER_PROTOTYPE(function) { \
type *i = data, x; \ type *i = data, x; \
\ \
@ -352,20 +348,17 @@ typedef enum ConfigParseStringFlags {
assert(data); \ assert(data); \
\ \
x = from_string(rvalue); \ x = from_string(rvalue); \
if (x < 0) { \ if (x < 0) \
log_syntax(unit, LOG_WARNING, filename, line, x, \ return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue); \
msg ", ignoring: %s", rvalue); \
return 0; \
} \
\ \
*i = x; \ *i = x; \
return 1; \ return 1; \
} }
#define DEFINE_CONFIG_PARSE_ENUM(function, name, type, msg) \ #define DEFINE_CONFIG_PARSE_ENUM(function, name, type) \
DEFINE_CONFIG_PARSE_ENUM_FULL(function, name##_from_string, type, msg) 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) { \ CONFIG_PARSER_PROTOTYPE(function) { \
type *i = data, x; \ type *i = data, x; \
\ \
@ -380,76 +373,67 @@ typedef enum ConfigParseStringFlags {
} \ } \
\ \
x = name##_from_string(rvalue); \ x = name##_from_string(rvalue); \
if (x < 0) { \ if (x < 0) \
log_syntax(unit, LOG_WARNING, filename, line, x, \ return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue); \
msg ", ignoring: %s", rvalue); \
return 0; \
} \
\ \
*i = x; \ *i = x; \
return 1; \ 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) { \ CONFIG_PARSER_PROTOTYPE(function) { \
type **enums = ASSERT_PTR(data); \ type **enums = ASSERT_PTR(data); \
_cleanup_free_ type *xs = NULL; \ _cleanup_free_ type *xs = NULL; \
size_t i = 0; \ size_t n = 0; \
int r; \ int r; \
\ \
assert(filename); \
assert(lvalue); \ assert(lvalue); \
assert(rvalue); \
\
xs = new0(type, 1); \
if (!xs) \
return -ENOMEM; \
\
*xs = invalid; \
\ \
for (const char *p = rvalue;;) { \ for (const char *p = rvalue;;) { \
_cleanup_free_ char *en = NULL; \ _cleanup_free_ char *en = NULL; \
type x, *new_xs; \ type x; \
\ \
r = extract_first_word(&p, &en, NULL, 0); \ r = extract_first_word(&p, &en, NULL, 0); \
if (r == -ENOMEM) \ if (r < 0) \
return log_oom(); \ return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); \
if (r < 0) { \
log_syntax(unit, LOG_WARNING, filename, line, r, \
msg ", ignoring: %s", en); \
return 0; \
} \
if (r == 0) \ if (r == 0) \
break; \ break; \
\ \
x = name##_from_string(en); \ x = name##_from_string(en); \
if (x < 0) { \ if (x < 0) { \
log_syntax(unit, LOG_WARNING, filename, line, x, \ log_syntax(unit, LOG_WARNING, filename, line, x, \
msg ", ignoring: %s", en); \ "Failed to parse %s in %s=, ignoring.", \
en, lvalue); \
continue; \ continue; \
} \ } \
\ \
for (type *ys = xs; x != invalid && *ys != invalid; ys++) \ FOREACH_ARRAY(i, xs, n) \
if (*ys == x) { \ if (*i == x) { \
log_syntax(unit, LOG_NOTICE, filename, line, 0, \ log_syntax(unit, LOG_NOTICE, filename, line, 0, \
"Duplicate entry, ignoring: %s", \ "Duplicate entry %s in %s=, ignoring.", \
en); \ en, lvalue); \
x = invalid; \ x = invalid; \
break; \
} \ } \
\ \
if (x == invalid) \ if (x == invalid) \
continue; \ continue; \
\ \
*(xs + i) = x; \ /* Allocate one more for the trailing 'invalid'. */ \
new_xs = realloc(xs, (++i + 1) * sizeof(type)); \ if (!GREEDY_REALLOC(xs, n + 2)) \
if (new_xs) \
xs = new_xs; \
else \
return log_oom(); \ return log_oom(); \
\ \
*(xs + i) = invalid; \ xs[n++] = x; \
} \ } \
\ \
if (n <= 0) { \
/* An empty string, or invalid values only. */ \
*enums = mfree(*enums); \
return 1; \
} \
\
/* Terminate with 'invalid' */ \
xs[n] = invalid; \
free_and_replace(*enums, xs); \ free_and_replace(*enums, xs); \
return 1; \ return 1; \
} }
@ -460,8 +444,8 @@ int config_parse_unsigned_bounded(
unsigned line, unsigned line,
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *name, const char *lvalue,
const char *value, const char *rvalue,
unsigned min, unsigned min,
unsigned max, unsigned max,
bool ignoring, bool ignoring,
@ -473,8 +457,8 @@ static inline int config_parse_uint32_bounded(
unsigned line, unsigned line,
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *name, const char *lvalue,
const char *value, const char *rvalue,
uint32_t min, uint32_t min,
uint32_t max, uint32_t max,
bool ignoring, bool ignoring,
@ -484,7 +468,7 @@ static inline int config_parse_uint32_bounded(
int r; int r;
r = config_parse_unsigned_bounded( r = config_parse_unsigned_bounded(
unit, filename, line, section, section_line, name, value, unit, filename, line, section, section_line, lvalue, rvalue,
min, max, ignoring, min, max, ignoring,
&t); &t);
if (r <= 0) if (r <= 0)
@ -500,8 +484,8 @@ static inline int config_parse_uint16_bounded(
unsigned line, unsigned line,
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *name, const char *lvalue,
const char *value, const char *rvalue,
uint16_t min, uint16_t min,
uint16_t max, uint16_t max,
bool ignoring, bool ignoring,
@ -511,7 +495,7 @@ static inline int config_parse_uint16_bounded(
int r; int r;
r = config_parse_unsigned_bounded( r = config_parse_unsigned_bounded(
unit, filename, line, section, section_line, name, value, unit, filename, line, section, section_line, lvalue, rvalue,
min, max, ignoring, min, max, ignoring,
&t); &t);
if (r <= 0) if (r <= 0)
@ -527,8 +511,8 @@ static inline int config_parse_uint8_bounded(
unsigned line, unsigned line,
const char *section, const char *section,
unsigned section_line, unsigned section_line,
const char *name, const char *lvalue,
const char *value, const char *rvalue,
uint8_t min, uint8_t min,
uint8_t max, uint8_t max,
bool ignoring, bool ignoring,
@ -538,7 +522,7 @@ static inline int config_parse_uint8_bounded(
int r; int r;
r = config_parse_unsigned_bounded( r = config_parse_unsigned_bounded(
unit, filename, line, section, section_line, name, value, unit, filename, line, section, section_line, lvalue, rvalue,
min, max, ignoring, min, max, ignoring,
&t); &t);
if (r <= 0) if (r <= 0)

View File

@ -23,7 +23,7 @@ static const char* const duplex_table[_DUP_MAX] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(duplex, Duplex); 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 { static const struct {
uint32_t opt; uint32_t opt;
@ -72,7 +72,7 @@ static const char* const port_table[] = {
}; };
DEFINE_STRING_TABLE_LOOKUP(port, NetDevPort); 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[] = { static const char* const mdi_table[] = {
[ETH_TP_MDI_INVALID] = "unknown", [ETH_TP_MDI_INVALID] = "unknown",

View File

@ -4,9 +4,9 @@
#include "resolve-util.h" #include "resolve-util.h"
#include "string-table.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_resolve_support, resolve_support, ResolveSupport);
DEFINE_CONFIG_PARSE_ENUM(config_parse_dnssec_mode, dnssec_mode, DnssecMode, "Failed to parse DNSSEC mode setting"); 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, "Failed to parse DNS-over-TLS mode setting"); 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] = { static const char* const resolve_support_table[_RESOLVE_SUPPORT_MAX] = {
[RESOLVE_SUPPORT_NO] = "no", [RESOLVE_SUPPORT_NO] = "no",
@ -42,7 +42,7 @@ bool dns_server_address_valid(int family, const union in_addr_union *sa) {
return true; 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] = { static const char* const dns_cache_mode_table[_DNS_CACHE_MODE_MAX] = {
[DNS_CACHE_MODE_YES] = "yes", [DNS_CACHE_MODE_YES] = "yes",

View File

@ -377,10 +377,10 @@ static int config_parse_resource_path(
return free_and_replace(rr->path, resolved); return free_and_replace(rr->path, resolved);
} }
static DEFINE_CONFIG_PARSE_ENUM(config_parse_resource_type, resource_type, ResourceType, "Invalid resource type"); static DEFINE_CONFIG_PARSE_ENUM(config_parse_resource_type, resource_type, ResourceType);
static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_resource_path_relto, path_relative_to, PathRelativeTo, static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(config_parse_resource_path_relto, path_relative_to, PathRelativeTo,
PATH_RELATIVE_TO_ROOT, "Invalid PathRelativeTo= value"); PATH_RELATIVE_TO_ROOT);
static int config_parse_resource_ptype( static int config_parse_resource_ptype(
const char *unit, const char *unit,

View File

@ -16,78 +16,85 @@
static void test_config_parse_path_one(const char *rvalue, const char *expected) { static void test_config_parse_path_one(const char *rvalue, const char *expected) {
_cleanup_free_ char *path = NULL; _cleanup_free_ char *path = NULL;
assert_se(config_parse_path("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &path, NULL) >= 0); ASSERT_OK(config_parse_path("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &path, NULL));
ASSERT_STREQ(expected, path); ASSERT_STREQ(expected, path);
} }
static void test_config_parse_log_level_one(const char *rvalue, int expected) { static void test_config_parse_log_level_one(const char *rvalue, int expected) {
int log_level = 0; int log_level = 0;
assert_se(config_parse_log_level("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_level, NULL) >= 0); ASSERT_OK(config_parse_log_level("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_level, NULL));
assert_se(expected == log_level); ASSERT_EQ(expected, log_level);
} }
static void test_config_parse_log_facility_one(const char *rvalue, int expected) { static void test_config_parse_log_facility_one(const char *rvalue, int expected) {
int log_facility = 0; int log_facility = 0;
assert_se(config_parse_log_facility("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_facility, NULL) >= 0); ASSERT_OK(config_parse_log_facility("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_facility, NULL));
assert_se(expected == log_facility); ASSERT_EQ(expected, log_facility);
} }
static void test_config_parse_iec_size_one(const char *rvalue, size_t expected) { static void test_config_parse_iec_size_one(const char *rvalue, size_t expected) {
size_t iec_size = 0; size_t iec_size = 0;
assert_se(config_parse_iec_size("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &iec_size, NULL) >= 0); ASSERT_OK(config_parse_iec_size("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &iec_size, NULL));
assert_se(expected == iec_size); ASSERT_EQ(expected, iec_size);
} }
static void test_config_parse_si_uint64_one(const char *rvalue, uint64_t expected) { static void test_config_parse_si_uint64_one(const char *rvalue, uint64_t expected) {
uint64_t si_uint64 = 0; uint64_t si_uint64 = 0;
assert_se(config_parse_si_uint64("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_uint64, NULL) >= 0); ASSERT_OK(config_parse_si_uint64("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_uint64, NULL));
assert_se(expected == si_uint64); ASSERT_EQ(expected, si_uint64);
} }
static void test_config_parse_int_one(const char *rvalue, int expected) { static void test_config_parse_int_one(const char *rvalue, int expected) {
int v = -1; int v = -1;
assert_se(config_parse_int("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); ASSERT_OK(config_parse_int("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL));
assert_se(expected == v); ASSERT_EQ(expected, v);
} }
static void test_config_parse_unsigned_one(const char *rvalue, unsigned expected) { static void test_config_parse_unsigned_one(const char *rvalue, unsigned expected) {
unsigned v = 0; unsigned v = 0;
assert_se(config_parse_unsigned("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); ASSERT_OK(config_parse_unsigned("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL));
assert_se(expected == v); ASSERT_EQ(expected, v);
} }
static void test_config_parse_strv_one(const char *rvalue, char **expected) { static void test_config_parse_strv_one(const char *rvalue, bool filter_duplicates, char **expected) {
_cleanup_strv_free_ char **strv = NULL; _cleanup_strv_free_ char **strv = NULL;
assert_se(config_parse_strv("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &strv, NULL) >= 0); ASSERT_OK(config_parse_strv("unit", "filename", 1, "section", 1, "lvalue", filter_duplicates, rvalue, &strv, NULL));
assert_se(strv_equal(expected, strv)); ASSERT_TRUE(strv_equal(expected, strv));
} }
static void test_config_parse_mode_one(const char *rvalue, mode_t expected) { static void test_config_parse_mode_one(const char *rvalue, mode_t expected) {
mode_t v = 0; mode_t v = 0;
assert_se(config_parse_mode("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); ASSERT_OK(config_parse_mode("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL));
assert_se(expected == v); ASSERT_EQ(expected, v);
} }
static void test_config_parse_sec_one(const char *rvalue, usec_t expected) { static void test_config_parse_sec_one(const char *rvalue, usec_t expected) {
usec_t v = 0; usec_t v = 0;
assert_se(config_parse_sec("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); ASSERT_OK(config_parse_sec("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL));
assert_se(expected == v); ASSERT_EQ(expected, v);
} }
static void test_config_parse_nsec_one(const char *rvalue, nsec_t expected) { static void test_config_parse_nsec_one(const char *rvalue, nsec_t expected) {
nsec_t v = 0; nsec_t v = 0;
assert_se(config_parse_nsec("unit", "filename", 1, "nsection", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); ASSERT_OK(config_parse_nsec("unit", "filename", 1, "nsection", 1, "lvalue", 0, rvalue, &v, NULL));
assert_se(expected == v); ASSERT_EQ(expected, v);
}
static void test_config_parse_iec_uint64_one(const char *rvalue, uint64_t expected) {
uint64_t v = 0;
ASSERT_OK(config_parse_iec_uint64("unit", "filename", 1, "nsection", 1, "lvalue", 0, rvalue, &v, NULL));
ASSERT_EQ(expected, v);
} }
TEST(config_parse_path) { TEST(config_parse_path) {
@ -164,12 +171,19 @@ TEST(config_parse_unsigned) {
} }
TEST(config_parse_strv) { TEST(config_parse_strv) {
test_config_parse_strv_one("", STRV_MAKE_EMPTY); test_config_parse_strv_one("", false, STRV_MAKE_EMPTY);
test_config_parse_strv_one("foo", STRV_MAKE("foo")); test_config_parse_strv_one("foo", false, STRV_MAKE("foo"));
test_config_parse_strv_one("foo bar foo", STRV_MAKE("foo", "bar", "foo")); test_config_parse_strv_one("foo bar foo", false, STRV_MAKE("foo", "bar", "foo"));
test_config_parse_strv_one("\"foo bar\" foo", STRV_MAKE("foo bar", "foo")); test_config_parse_strv_one("\"foo bar\" foo", false, STRV_MAKE("foo bar", "foo"));
test_config_parse_strv_one("\xc3\x80", STRV_MAKE("\xc3\x80")); test_config_parse_strv_one("\xc3\x80", false, STRV_MAKE("\xc3\x80"));
test_config_parse_strv_one("\xc3\x7f", STRV_MAKE("\xc3\x7f")); test_config_parse_strv_one("\xc3\x7f", false, STRV_MAKE("\xc3\x7f"));
test_config_parse_strv_one("", true, STRV_MAKE_EMPTY);
test_config_parse_strv_one("foo", true, STRV_MAKE("foo"));
test_config_parse_strv_one("foo bar foo", true, STRV_MAKE("foo", "bar"));
test_config_parse_strv_one("\"foo bar\" foo", true, STRV_MAKE("foo bar", "foo"));
test_config_parse_strv_one("\xc3\x80", true, STRV_MAKE("\xc3\x80"));
test_config_parse_strv_one("\xc3\x7f", true, STRV_MAKE("\xc3\x7f"));
} }
TEST(config_parse_mode) { TEST(config_parse_mode) {
@ -206,11 +220,8 @@ TEST(config_parse_nsec) {
} }
TEST(config_parse_iec_uint64) { TEST(config_parse_iec_uint64) {
uint64_t offset = 0; test_config_parse_iec_uint64_one("4M", UINT64_C(4 * 1024 * 1024));
assert_se(config_parse_iec_uint64(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4M", &offset, NULL) == 0); test_config_parse_iec_uint64_one("4.5M", UINT64_C((4 * 1024 + 512) * 1024));
assert_se(offset == 4 * 1024 * 1024);
assert_se(config_parse_iec_uint64(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4.5M", &offset, NULL) == 0);
} }
#define x10(x) x x x x x x x x x x #define x10(x) x x x x x x x x x x

View File

@ -1446,13 +1446,10 @@ DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT(
config_parse_mac_address_policy, config_parse_mac_address_policy,
mac_address_policy, mac_address_policy,
MACAddressPolicy, MACAddressPolicy,
MAC_ADDRESS_POLICY_NONE, MAC_ADDRESS_POLICY_NONE);
"Failed to parse MAC address policy");
DEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy, DEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy,
_NAMEPOLICY_INVALID, _NAMEPOLICY_INVALID);
"Failed to parse interface name policy");
DEFINE_CONFIG_PARSE_ENUMV(config_parse_alternative_names_policy, alternative_names_policy, NamePolicy, DEFINE_CONFIG_PARSE_ENUMV(config_parse_alternative_names_policy, alternative_names_policy, NamePolicy,
_NAMEPOLICY_INVALID, _NAMEPOLICY_INVALID);
"Failed to parse alternative names policy");

View File

@ -65,7 +65,7 @@ static int listen_fds(int *ret_ctrl, int *ret_netlink) {
return 0; return 0;
} }
static DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve_name_timing, resolve_name_timing, ResolveNameTiming, "Failed to parse resolve name timing"); static DEFINE_CONFIG_PARSE_ENUM(config_parse_resolve_name_timing, resolve_name_timing, ResolveNameTiming);
static int manager_parse_udev_config(Manager *manager) { static int manager_parse_udev_config(Manager *manager) {
int r, log_val = -1; int r, log_val = -1;