diff --git a/src/basic/log.c b/src/basic/log.c index 571f5e43dc..c3e61ab5d4 100644 --- a/src/basic/log.c +++ b/src/basic/log.c @@ -1679,6 +1679,7 @@ int log_syntax_invalid_utf8_internal( const char *func, const char *rvalue) { + PROTECT_ERRNO; _cleanup_free_ char *p = NULL; if (rvalue) @@ -1689,6 +1690,44 @@ int log_syntax_invalid_utf8_internal( "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) { upgrade_syslog_to_journal = b; diff --git a/src/basic/log.h b/src/basic/log.h index 0412e8a871..ac9d72202b 100644 --- a/src/basic/log.h +++ b/src/basic/log.h @@ -359,6 +359,18 @@ int log_syntax_invalid_utf8_internal( const char *func, 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, ...) \ ({ \ int _level = (level), _e = (error); \ @@ -375,6 +387,12 @@ int log_syntax_invalid_utf8_internal( : -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) void log_setup(void); diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 7633589b0d..cc6597dbb7 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -126,38 +126,38 @@ int parse_confirm_spawn(const char *value, char **console) { return 0; } -DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol, "Failed to parse socket protocol"); -DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string, "Failed to parse secure bits"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode, "Failed to parse garbage collection mode"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_device_policy, cgroup_device_policy, CGroupDevicePolicy, "Failed to parse device policy"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_keyring_mode, exec_keyring_mode, ExecKeyringMode, "Failed to parse keyring mode"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc, protect_proc, ProtectProc, "Failed to parse /proc/ protection mode"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset, proc_subset, ProcSubset, "Failed to parse /proc/ subset mode"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_private_tmp, private_tmp, PrivateTmp, "Failed to parse private tmp value"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode, "Failed to parse utmp mode"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode, "Failed to parse job mode"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess, "Failed to parse notify access specifier"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome, "Failed to parse protect home value"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem, "Failed to parse protect system value"); -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_service_type, service_type, ServiceType, "Failed to parse service type"); -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_restart, service_restart, ServiceRestart, "Failed to parse service restart specifier"); -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_timeout_failure_mode, service_timeout_failure_mode, ServiceTimeoutFailureMode, "Failed to parse timeout failure mode"); -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_oom_policy, oom_policy, OOMPolicy, "Failed to parse OOM policy"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_managed_oom_preference, managed_oom_preference, ManagedOOMPreference, "Failed to parse 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_WITH_DEFAULT(config_parse_ip_tos, ip_tos, int, -1, "Failed to parse IP TOS value"); -DEFINE_CONFIG_PARSE_PTR(config_parse_blockio_weight, cg_blkio_weight_parse, uint64_t, "Invalid block IO weight"); -DEFINE_CONFIG_PARSE_PTR(config_parse_cg_weight, cg_weight_parse, uint64_t, "Invalid weight"); -DEFINE_CONFIG_PARSE_PTR(config_parse_cg_cpu_weight, cg_cpu_weight_parse, uint64_t, "Invalid CPU weight"); -static DEFINE_CONFIG_PARSE_PTR(config_parse_cpu_shares_internal, cg_cpu_shares_parse, uint64_t, "Invalid CPU shares"); -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_ENUM_WITH_DEFAULT(config_parse_numa_policy, mpol, int, -1, "Invalid NUMA policy type"); -DEFINE_CONFIG_PARSE_ENUM(config_parse_status_unit_format, status_unit_format, StatusUnitFormat, "Failed to parse status unit format"); -DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping, "Failed to parse timestamping precision"); +DEFINE_CONFIG_PARSE(config_parse_socket_protocol, parse_socket_protocol); +DEFINE_CONFIG_PARSE(config_parse_exec_secure_bits, secure_bits_from_string); +DEFINE_CONFIG_PARSE_ENUM(config_parse_collect_mode, collect_mode, CollectMode); +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); +DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_proc, protect_proc, ProtectProc); +DEFINE_CONFIG_PARSE_ENUM(config_parse_proc_subset, proc_subset, ProcSubset); +DEFINE_CONFIG_PARSE_ENUM(config_parse_private_tmp, private_tmp, PrivateTmp); +DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_utmp_mode, exec_utmp_mode, ExecUtmpMode); +DEFINE_CONFIG_PARSE_ENUM(config_parse_job_mode, job_mode, JobMode); +DEFINE_CONFIG_PARSE_ENUM(config_parse_notify_access, notify_access, NotifyAccess); +DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_home, protect_home, ProtectHome); +DEFINE_CONFIG_PARSE_ENUM(config_parse_protect_system, protect_system, ProtectSystem); +DEFINE_CONFIG_PARSE_ENUM(config_parse_exec_preserve_mode, exec_preserve_mode, ExecPreserveMode); +DEFINE_CONFIG_PARSE_ENUM(config_parse_service_type, service_type, ServiceType); +DEFINE_CONFIG_PARSE_ENUM(config_parse_service_exit_type, service_exit_type, ServiceExitType); +DEFINE_CONFIG_PARSE_ENUM(config_parse_service_restart, service_restart, ServiceRestart); +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); +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); +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); +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); +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); +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); +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); +DEFINE_CONFIG_PARSE_ENUM_FULL(config_parse_socket_timestamping, socket_timestamping_from_string_harder, SocketTimestamping); int config_parse_cpu_shares( const char *unit, diff --git a/src/core/main.c b/src/core/main.c index 14c124dc32..b9dc450636 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -174,7 +174,7 @@ static const char* const crash_action_table[_CRASH_ACTION_MAX] = { 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) { _cleanup_free_ char *base = NULL; diff --git a/src/coredump/coredump.c b/src/coredump/coredump.c index e751b67417..d21ea680bd 100644 --- a/src/coredump/coredump.c +++ b/src/coredump/coredump.c @@ -158,7 +158,7 @@ static const char* const coredump_storage_table[_COREDUMP_STORAGE_MAX] = { }; 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 bool arg_compress = true; diff --git a/src/home/homed-conf.c b/src/home/homed-conf.c index 3f74096b64..21cb510688 100644 --- a/src/home/homed-conf.c +++ b/src/home/homed-conf.c @@ -17,7 +17,7 @@ int manager_parse_config_file(Manager *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( const char *unit, diff --git a/src/journal-remote/journal-remote-main.c b/src/journal-remote/journal-remote-main.c index 1cc978d383..7156bc7727 100644 --- a/src/journal-remote/journal-remote-main.c +++ b/src/journal-remote/journal-remote-main.c @@ -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); -static DEFINE_CONFIG_PARSE_ENUM(config_parse_write_split_mode, - journal_write_split_mode, - JournalWriteSplitMode, - "Failed to parse split mode setting"); +static DEFINE_CONFIG_PARSE_ENUM(config_parse_write_split_mode, journal_write_split_mode, JournalWriteSplitMode); /********************************************************************** ********************************************************************** diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index 09b80881b3..66f09e4945 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -2953,7 +2953,7 @@ static const char* const storage_table[_STORAGE_MAX] = { }; 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] = { [SPLIT_LOGIN] = "login", @@ -2962,7 +2962,7 @@ static const char* const split_mode_table[_SPLIT_MAX] = { }; 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( const char* unit, diff --git a/src/login/logind-action.c b/src/login/logind-action.c index 2a7766841f..db9a0e1bba 100644 --- a/src/login/logind-action.c +++ b/src/login/logind-action.c @@ -438,7 +438,7 @@ static const char* const handle_action_table[_HANDLE_ACTION_MAX] = { }; 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( const char *unit, diff --git a/src/network/netdev/bareudp.c b/src/network/netdev/bareudp.c index fdde881520..b2a161ee7a 100644 --- a/src/network/netdev/bareudp.c +++ b/src/network/netdev/bareudp.c @@ -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_CONFIG_PARSE_ENUM(config_parse_bare_udp_iftype, bare_udp_protocol, BareUDPProtocol, - "Failed to parse EtherType="); +DEFINE_CONFIG_PARSE_ENUM(config_parse_bare_udp_iftype, bare_udp_protocol, BareUDPProtocol); static int netdev_bare_udp_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { assert(m); diff --git a/src/network/netdev/batadv.c b/src/network/netdev/batadv.c index 26da0231d4..e600727c20 100644 --- a/src/network/netdev/batadv.c +++ b/src/network/netdev/batadv.c @@ -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_CONFIG_PARSE_ENUM(config_parse_batadv_gateway_mode, batadv_gateway_mode, BatadvGatewayModes, - "Failed to parse GatewayMode="); +DEFINE_CONFIG_PARSE_ENUM(config_parse_batadv_gateway_mode, batadv_gateway_mode, BatadvGatewayModes); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_FROM_STRING(batadv_routing_algorithm, BatadvRoutingAlgorithm); -DEFINE_CONFIG_PARSE_ENUM(config_parse_batadv_routing_algorithm, batadv_routing_algorithm, BatadvRoutingAlgorithm, - "Failed to parse RoutingAlgorithm="); +DEFINE_CONFIG_PARSE_ENUM(config_parse_batadv_routing_algorithm, batadv_routing_algorithm, BatadvRoutingAlgorithm); DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(batadv_routing_algorithm_kernel, BatadvRoutingAlgorithm); diff --git a/src/network/netdev/bond.c b/src/network/netdev/bond.c index 52a7f126b6..de122f8eb3 100644 --- a/src/network/netdev/bond.c +++ b/src/network/netdev/bond.c @@ -44,17 +44,16 @@ #define GRATUITOUS_ARP_MAX 255 #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, bond_xmit_hash_policy, - BondXmitHashPolicy, - "Failed to parse bond transmit hash policy"); -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, "Failed to parse bond AD select"); -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, "Failed to parse bond arp validate"); -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, "Failed to parse bond primary reselect"); + BondXmitHashPolicy); +DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_lacp_rate, bond_lacp_rate, BondLacpRate); +DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_ad_select, bond_ad_select, BondAdSelect); +DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_fail_over_mac, bond_fail_over_mac, BondFailOverMac); +DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_validate, bond_arp_validate, BondArpValidate); +DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_arp_all_targets, bond_arp_all_targets, BondArpAllTargets); +DEFINE_CONFIG_PARSE_ENUM(config_parse_bond_primary_reselect, bond_primary_reselect, BondPrimaryReselect); static int netdev_bond_fill_message_create(NetDev *netdev, Link *link, sd_netlink_message *m) { assert(!link); diff --git a/src/network/netdev/bridge.c b/src/network/netdev/bridge.c index 27f3916476..25b0f81aa0 100644 --- a/src/network/netdev/bridge.c +++ b/src/network/netdev/bridge.c @@ -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_CONFIG_PARSE_ENUM(config_parse_multicast_router, multicast_router, MulticastRouter, - "Failed to parse bridge multicast router setting"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_multicast_router, multicast_router, MulticastRouter); /* callback for bridge netdev's parameter set */ static int netdev_bridge_set_handler(sd_netlink *rtnl, sd_netlink_message *m, NetDev *netdev) { diff --git a/src/network/netdev/fou-tunnel.c b/src/network/netdev/fou-tunnel.c index 969a4e6de6..e962c6c64b 100644 --- a/src/network/netdev/fou-tunnel.c +++ b/src/network/netdev/fou-tunnel.c @@ -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_CONFIG_PARSE_ENUM(config_parse_fou_encap_type, fou_encap_type, FooOverUDPEncapType, - "Failed to parse Encapsulation="); +DEFINE_CONFIG_PARSE_ENUM(config_parse_fou_encap_type, fou_encap_type, FooOverUDPEncapType); static int netdev_fill_fou_tunnel_message(NetDev *netdev, sd_netlink_message *m) { FouTunnel *t = FOU(netdev); diff --git a/src/network/netdev/geneve.c b/src/network/netdev/geneve.c index 22c2b00e1b..493edcc42a 100644 --- a/src/network/netdev/geneve.c +++ b/src/network/netdev/geneve.c @@ -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_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) { assert(m); diff --git a/src/network/netdev/ipoib.c b/src/network/netdev/ipoib.c index d5fe299b7b..e2f879e722 100644 --- a/src/network/netdev/ipoib.c +++ b/src/network/netdev/ipoib.c @@ -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_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( const char *unit, diff --git a/src/network/netdev/ipvlan.c b/src/network/netdev/ipvlan.c index 51ae64341d..892678b4ad 100644 --- a/src/network/netdev/ipvlan.c +++ b/src/network/netdev/ipvlan.c @@ -11,8 +11,8 @@ #include "networkd-link.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_flags, ipvlan_flags, IPVlanFlags, "Failed to parse ipvlan flags"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_ipvlan_mode, ipvlan_mode, IPVlanMode); +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) { assert(netdev); diff --git a/src/network/netdev/l2tp-tunnel.c b/src/network/netdev/l2tp-tunnel.c index 4f9e7189d1..3194f3f785 100644 --- a/src/network/netdev/l2tp-tunnel.c +++ b/src/network/netdev/l2tp-tunnel.c @@ -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_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] = { [NETDEV_L2TP_LOCAL_ADDRESS_AUTO] = "auto", diff --git a/src/network/netdev/macvlan.c b/src/network/netdev/macvlan.c index 21933d3970..1537d868b5 100644 --- a/src/network/netdev/macvlan.c +++ b/src/network/netdev/macvlan.c @@ -16,7 +16,7 @@ typedef enum BCQueueThreshold { BC_QUEUE_THRESHOLD_DISABLE = -1, } 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) { assert(netdev); diff --git a/src/network/netdev/tunnel.c b/src/network/netdev/tunnel.c index db84e7cf6e..2bf58086b2 100644 --- a/src/network/netdev/tunnel.c +++ b/src/network/netdev/tunnel.c @@ -30,7 +30,7 @@ static const char* const ip6tnl_mode_table[_NETDEV_IP6_TNL_MODE_MAX] = { }; 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) diff --git a/src/network/netdev/vxlan.c b/src/network/netdev/vxlan.c index 37f65967a6..e928b20d83 100644 --- a/src/network/netdev/vxlan.c +++ b/src/network/netdev/vxlan.c @@ -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_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) { assert(v); diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 4a9459f006..0a784553d0 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -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_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DHCPClientIdentifier, - "Failed to parse client identifier type"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp_client_identifier, dhcp_client_identifier, DHCPClientIdentifier); diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index 852987bd86..3f773cbb99 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -878,8 +878,7 @@ int config_parse_dhcp6_pd_prefix_hint( return 0; } -DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode, - "Failed to parse WithoutRA= setting"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_dhcp6_client_start_mode, dhcp6_client_start_mode, DHCP6ClientStartMode); static const char* const dhcp6_client_start_mode_table[_DHCP6_CLIENT_START_MODE_MAX] = { [DHCP6_CLIENT_START_MODE_NO] = "no", diff --git a/src/network/networkd-dns.c b/src/network/networkd-dns.c index 7078419d37..74a371b6d7 100644 --- a/src/network/networkd-dns.c +++ b/src/network/networkd-dns.c @@ -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_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); diff --git a/src/network/networkd-ipv6ll.c b/src/network/networkd-ipv6ll.c index 32229a3fc7..cd23cc94aa 100644 --- a/src/network/networkd-ipv6ll.c +++ b/src/network/networkd-ipv6ll.c @@ -243,5 +243,4 @@ DEFINE_STRING_TABLE_LOOKUP(ipv6_link_local_address_gen_mode, IPv6LinkLocalAddres DEFINE_CONFIG_PARSE_ENUM( config_parse_ipv6_link_local_address_gen_mode, ipv6_link_local_address_gen_mode, - IPv6LinkLocalAddressGenMode, - "Failed to parse IPv6 link-local address generation mode"); + IPv6LinkLocalAddressGenMode); diff --git a/src/network/networkd-lldp-rx.c b/src/network/networkd-lldp-rx.c index f74485488e..6ba198282e 100644 --- a/src/network/networkd-lldp-rx.c +++ b/src/network/networkd-lldp-rx.c @@ -17,7 +17,7 @@ #include "strv.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] = { [LLDP_MODE_NO] = "no", diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 21b76fafc4..f44f03365c 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -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_CONFIG_PARSE_ENUM(config_parse_ndisc_start_dhcp6_client, ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client, - "Failed to parse DHCPv6Client= setting"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_ndisc_start_dhcp6_client, ndisc_start_dhcp6_client, IPv6AcceptRAStartDHCP6Client); diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c index 94666c2bdd..56cf52bbe6 100644 --- a/src/network/networkd-network.c +++ b/src/network/networkd-network.c @@ -1056,11 +1056,8 @@ int config_parse_ignore_carrier_loss( return 0; } -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, - "Failed to parse KeepConfiguration= setting"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_required_family_for_online, link_required_address_family, AddressFamily); +DEFINE_CONFIG_PARSE_ENUM(config_parse_keep_configuration, keep_configuration, KeepConfiguration); static const char* const keep_configuration_table[_KEEP_CONFIGURATION_MAX] = { [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_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); diff --git a/src/network/networkd-routing-policy-rule.c b/src/network/networkd-routing-policy-rule.c index 75b4224c8a..1efb2bff94 100644 --- a/src/network/networkd-routing-policy-rule.c +++ b/src/network/networkd-routing-policy-rule.c @@ -1637,8 +1637,7 @@ static DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT( config_parse_routing_policy_rule_family, routing_policy_rule_address_family, AddressFamily, - ADDRESS_FAMILY_NO, - "Invalid family"); + ADDRESS_FAMILY_NO); typedef struct RoutingPolicyRuleConfParser { ConfigParserCallback parser; diff --git a/src/network/networkd-sysctl.c b/src/network/networkd-sysctl.c index a454322fd0..2027a29f27 100644 --- a/src/network/networkd-sysctl.c +++ b/src/network/networkd-sysctl.c @@ -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, IPV6_PRIVACY_EXTENSIONS_YES); -DEFINE_CONFIG_PARSE_ENUM(config_parse_ipv6_privacy_extensions, ipv6_privacy_extensions, IPv6PrivacyExtensions, - "Failed to parse IPv6 privacy extensions option"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_ipv6_privacy_extensions, ipv6_privacy_extensions, IPv6PrivacyExtensions); static const char* const ip_reverse_path_filter_table[_IP_REVERSE_PATH_FILTER_MAX] = { [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_CONFIG_PARSE_ENUM(config_parse_ip_reverse_path_filter, ip_reverse_path_filter, IPReversePathFilter, - "Failed to parse IP reverse path filter option"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_ip_reverse_path_filter, ip_reverse_path_filter, IPReversePathFilter); int config_parse_ip_forward_deprecated( const char* unit, diff --git a/src/network/networkd-util.c b/src/network/networkd-util.c index 46f9008879..8d6df6d2c1 100644 --- a/src/network/networkd-util.c +++ b/src/network/networkd-util.c @@ -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(nexthop_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, - AddressFamily, "Failed to parse option"); +DEFINE_CONFIG_PARSE_ENUM(config_parse_link_local_address_family, link_local_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_STRING_TABLE_LOOKUP(dhcp_lease_server_type, sd_dhcp_lease_server_type_t); diff --git a/src/network/test-networkd-conf.c b/src/network/test-networkd-conf.c index 3581524c63..186d9d3e65 100644 --- a/src/network/test-networkd-conf.c +++ b/src/network/test-networkd-conf.c @@ -11,76 +11,65 @@ #include "strv.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 = {}; - int r; - r = 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_se(r == ret); - assert_se(expected == actual.type); + ASSERT_OK(config_parse_duid_type("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL)); + ASSERT_EQ(actual.type, expected); 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_one("", 0, 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:2000-01-01 00:00:00 UTC", 0, 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:2000-01-01 00:00:00 UTC", 0, 0, 0); - test_config_parse_duid_type_one("link-layer", 0, 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("uuid", 0, 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("foo", 0, 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("", 0, 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", DUID_TYPE_LLT, (usec_t) 946684800000000); + 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); + 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); + 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); + 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); } -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 = {}; - int r; - _cleanup_free_ char *d = NULL; - r = 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); + ASSERT_OK(config_parse_duid_rawdata("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL)); if (expected) { - assert_se(actual.raw_data_len == expected->raw_data_len); - assert_se(memcmp(actual.raw_data, expected->raw_data, expected->raw_data_len) == 0); + _cleanup_free_ char *d = NULL, *e = NULL; + 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) { - struct ether_addr *actual = NULL; - int r; +static void test_config_parse_ether_addr_one(const char *rvalue, const struct ether_addr* expected) { + _cleanup_free_ struct ether_addr *actual = NULL; - r = config_parse_ether_addr("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL); - assert_se(ret == r); + ASSERT_OK(config_parse_ether_addr("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &actual, NULL)); if (expected) { - assert_se(actual); - assert_se(ether_addr_equal(expected, actual)); + ASSERT_NOT_NULL(actual); + ASSERT_STREQ(ETHER_ADDR_TO_STR(actual), ETHER_ADDR_TO_STR(expected)); } else - assert_se(actual == NULL); - - free(actual); + ASSERT_NULL(actual); } 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; - assert_se(config_parse_ether_addrs("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &s, NULL) == 0); - assert_se(set_size(s) == n); + ASSERT_OK(config_parse_ether_addrs("network", "filename", 1, "section", 1, "lvalue", 0, rvalue, &s, NULL)); + ASSERT_EQ(set_size(s), n); for (size_t m = 0; m < n; m++) { _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 \ @@ -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_one("", 0, &(DUID){}); - test_config_parse_duid_rawdata_one("00:11:22:33:44:55:66:77", 0, + test_config_parse_duid_rawdata_one("", &(DUID){}); + 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}}); - 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}}); - test_config_parse_duid_rawdata_one("000:11:22", 0, &(DUID){}); /* error, output is all zeros */ - test_config_parse_duid_rawdata_one("00:111:22", 0, &(DUID){}); - test_config_parse_duid_rawdata_one("0:1:2:3:4:5:6:7", 0, + test_config_parse_duid_rawdata_one("000:11:22", &(DUID){}); /* error, output is all zeros */ + test_config_parse_duid_rawdata_one("00:111:22", &(DUID){}); + 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}}); - test_config_parse_duid_rawdata_one("11::", 0, &(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(STR_TOO_LONG, 0, &(DUID){}); - test_config_parse_duid_rawdata_one(STR_OK, 0, &(DUID){0, 128, BYTES_OK}); + test_config_parse_duid_rawdata_one("11::", &(DUID){0, 1, {0x11}}); /* FIXME: should this be an error? */ + test_config_parse_duid_rawdata_one("abcdef", &(DUID){}); + test_config_parse_duid_rawdata_one(STR_TOO_LONG, &(DUID){}); + test_config_parse_duid_rawdata_one(STR_OK, &(DUID){0, 128, BYTES_OK}); } TEST(config_parse_ether_addr) { @@ -136,32 +125,32 @@ TEST(config_parse_ether_addr) { { .ether_addr_octet = { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab } }, }; - test_config_parse_ether_addr_one("", 0, NULL); - test_config_parse_ether_addr_one("no:ta:ma:ca:dd:re", 0, 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:ff", 0, &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 \t\n", 0, 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", 0, 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:dd:ee", 0, NULL); - test_config_parse_ether_addr_one("9:aa:bb:cc:dd:ee:ff", 0, 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", 0, &t[0]); - test_config_parse_ether_addr_one("01:23:45:67:89:aB", 0, &t[1]); - test_config_parse_ether_addr_one("1:23:45:67:89:aB", 0, &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", 0, &t[0]); - test_config_parse_ether_addr_one("01-23-45-67-89-ab", 0, &t[1]); - test_config_parse_ether_addr_one("aabb.ccdd.eeff", 0, &t[0]); - test_config_parse_ether_addr_one("0123.4567.89ab", 0, &t[1]); - test_config_parse_ether_addr_one("123.4567.89ab.", 0, NULL); - test_config_parse_ether_addr_one("aabbcc.ddeeff", 0, NULL); - test_config_parse_ether_addr_one("aabbccddeeff", 0, NULL); - test_config_parse_ether_addr_one("aabbccddee:ff", 0, NULL); - test_config_parse_ether_addr_one("012345.6789ab", 0, NULL); - test_config_parse_ether_addr_one("123.4567.89ab", 0, &t[1]); + test_config_parse_ether_addr_one("", 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", NULL); + 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", 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", 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", 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", 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", &t[0]); + 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", &t[1]); + 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", &t[0]); + test_config_parse_ether_addr_one("01-23-45-67-89-ab", &t[1]); + test_config_parse_ether_addr_one("aabb.ccdd.eeff", &t[0]); + test_config_parse_ether_addr_one("0123.4567.89ab", &t[1]); + test_config_parse_ether_addr_one("123.4567.89ab.", NULL); + test_config_parse_ether_addr_one("aabbcc.ddeeff", NULL); + test_config_parse_ether_addr_one("aabbccddeeff", NULL); + test_config_parse_ether_addr_one("aabbccddee:ff", NULL); + test_config_parse_ether_addr_one("012345.6789ab", NULL); + 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("no:ta:ma:ca:dd:re", t, 0); diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c index 132a54338f..587da92cb2 100644 --- a/src/nspawn/nspawn-settings.c +++ b/src/nspawn/nspawn-settings.c @@ -232,7 +232,7 @@ int settings_allocate_properties(Settings *s) { 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( 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); } -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] = { [RESOLV_CONF_OFF] = "off", @@ -914,7 +914,7 @@ int config_parse_link_journal( 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] = { [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_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] = { [USER_NAMESPACE_OWNERSHIP_OFF] = "off", diff --git a/src/partition/repart.c b/src/partition/repart.c index 48b3b43013..427762a8f6 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -1712,7 +1712,7 @@ static int config_parse_default_subvolume( 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( const char *unit, @@ -1899,8 +1899,8 @@ static int config_parse_encrypted_volume( 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_minimize, minimize_mode, MinimizeMode, MINIMIZE_OFF, "Invalid minimize 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); static int partition_finalize_fstype(Partition *p, const char *path) { _cleanup_free_ char *e = NULL, *upper = NULL; diff --git a/src/pstore/pstore.c b/src/pstore/pstore.c index e2dfc4d1a1..0addaa6df6 100644 --- a/src/pstore/pstore.c +++ b/src/pstore/pstore.c @@ -62,7 +62,7 @@ static const char* const pstore_storage_table[_PSTORE_STORAGE_MAX] = { }; 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; diff --git a/src/resolve/resolved-conf.c b/src/resolve/resolved-conf.c index 4441ee27c8..65a5611d09 100644 --- a/src/resolve/resolved-conf.c +++ b/src/resolve/resolved-conf.c @@ -21,7 +21,7 @@ #include "strv.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) { _cleanup_free_ char *server_name = NULL; diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index c4633fc52f..e50ccad35a 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -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); @@ -892,13 +892,11 @@ int config_parse_iec_size( r = parse_size(rvalue, 1024, &v); if (r >= 0 && (uint64_t) (size_t) v != v) r = -ERANGE; - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse size value '%s', ignoring: %m", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); *sz = (size_t) v; - return 0; + return 1; } int config_parse_si_uint64( @@ -922,9 +920,9 @@ int config_parse_si_uint64( r = parse_size(rvalue, 1000, sz); 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( @@ -948,9 +946,9 @@ int config_parse_iec_uint64( r = parse_size(rvalue, 1024, bytes); 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( @@ -971,7 +969,7 @@ int config_parse_iec_uint64_infinity( if (streq(rvalue, "infinity")) { *bytes = UINT64_MAX; - return 0; + return 1; } 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 *userdata) { - int k; bool *b = ASSERT_PTR(data); bool fatal = ltype; + int r; assert(filename); assert(lvalue); assert(rvalue); - k = parse_boolean(rvalue); - if (k < 0) { - log_syntax(unit, fatal ? LOG_ERR : LOG_WARNING, filename, line, k, - "Failed to parse boolean value%s: %s", - fatal ? "" : ", ignoring", rvalue); + r = parse_boolean(rvalue); + if (r < 0) { + log_syntax_parse_error_full(unit, filename, line, r, fatal, lvalue, rvalue); return fatal ? -ENOEXEC : 0; } - *b = k; + *b = r; return 1; /* set */ } @@ -1027,12 +1023,8 @@ int config_parse_uint32_flag( assert(ltype != 0); r = isempty(rvalue) ? 0 : parse_boolean(rvalue); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse %s=%s. Ignoring assignment: %m", - lvalue, rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); SET_FLAG(*flags, ltype, r); return 1; @@ -1058,12 +1050,14 @@ int config_parse_id128( assert(rvalue); 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); - else if (r < 0) - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 128-bit ID/UUID, ignoring: %s", rvalue); + return 0; + } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); - return 0; + return 1; } int config_parse_tristate( @@ -1093,11 +1087,8 @@ int config_parse_tristate( } r = parse_tristate(rvalue, t); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse boolean value for %s=, ignoring: %s", lvalue, rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); return 1; } @@ -1144,7 +1135,7 @@ int config_parse_string( return 0; } - r = free_and_strdup_warn(s, empty_to_null(rvalue)); + r = free_and_strdup_warn(s, rvalue); if (r < 0) return r; @@ -1172,7 +1163,7 @@ int config_parse_dns_name( if (isempty(rvalue)) { *hostname = mfree(*hostname); - return 0; + return 1; } r = dns_name_is_valid(rvalue); @@ -1187,7 +1178,11 @@ int config_parse_dns_name( 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( @@ -1210,7 +1205,7 @@ int config_parse_hostname( if (isempty(rvalue)) { *hostname = mfree(*hostname); - return 0; + return 1; } if (!hostname_is_valid(rvalue, 0)) { @@ -1244,8 +1239,10 @@ int config_parse_path( assert(lvalue); assert(rvalue); - if (isempty(rvalue)) - goto finalize; + if (isempty(rvalue)) { + *s = mfree(*s); + return 1; + } n = strdup(rvalue); if (!n) @@ -1255,8 +1252,8 @@ int config_parse_path( if (r < 0) return fatal ? -ENOEXEC : 0; -finalize: - return free_and_replace(*s, n); + free_and_replace(*s, n); + return 1; } int config_parse_strv( @@ -1266,7 +1263,7 @@ int config_parse_strv( const char *section, unsigned section_line, const char *lvalue, - int ltype, + int ltype, /* When true, duplicated entries will be filtered. */ const char *rvalue, void *data, void *userdata) { @@ -1280,26 +1277,29 @@ int config_parse_strv( if (isempty(rvalue)) { *sv = strv_free(*sv); - return 0; + return 1; } + _cleanup_strv_free_ char **strv = NULL; for (const char *p = rvalue;;) { - char *word = NULL; + char *word; 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) - return 0; - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); - return 0; - } + break; - r = strv_consume(sv, word); + r = strv_consume(&strv, word); if (r < 0) 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( @@ -1357,14 +1357,12 @@ int config_parse_log_facility( assert(data); x = log_facility_unshifted_from_string(rvalue); - if (x < 0) { - log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse log facility, ignoring: %s", rvalue); - return 0; - } + if (x < 0) + return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue); *o = (x << 3) | LOG_PRI(*o); - return 0; + return 1; } int config_parse_log_level( @@ -1387,17 +1385,15 @@ int config_parse_log_level( assert(data); x = log_level_from_string(rvalue); - if (x < 0) { - log_syntax(unit, LOG_WARNING, filename, line, x, "Failed to parse log level, ignoring: %s", rvalue); - return 0; - } + if (x < 0) + return log_syntax_parse_error(unit, filename, line, x, lvalue, rvalue); if (*o < 0) /* if it wasn't initialized so far, assume zero facility */ *o = x; else *o = (*o & LOG_FACMASK) | x; - return 0; + return 1; } int config_parse_signal( @@ -1420,13 +1416,11 @@ int config_parse_signal( assert(sig); r = signal_from_string(rvalue); - if (r <= 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse signal name, ignoring: %s", rvalue); - return 0; - } + if (r <= 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); *sig = r; - return 0; + return 1; } int config_parse_personality( @@ -1448,18 +1442,17 @@ int config_parse_personality( assert(rvalue); assert(personality); - if (isempty(rvalue)) - p = PERSONALITY_INVALID; - else { - 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; - } + if (isempty(rvalue)) { + *personality = PERSONALITY_INVALID; + return 1; } + p = personality_from_string(rvalue); + if (p == PERSONALITY_INVALID) + return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue); + *personality = p; - return 0; + return 1; } int config_parse_ifname( @@ -1491,9 +1484,9 @@ int config_parse_ifname( return 0; } - r = free_and_strdup(s, rvalue); + r = free_and_strdup_warn(s, rvalue); if (r < 0) - return log_oom(); + return r; return 1; } @@ -1520,21 +1513,15 @@ int config_parse_ifnames( if (isempty(rvalue)) { *s = strv_free(*s); - return 0; + return 1; } for (const char *p = rvalue;;) { _cleanup_free_ char *word = NULL; r = extract_first_word(&p, &word, NULL, 0); - if (r == -ENOMEM) - return log_oom(); - 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) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); if (r == 0) break; @@ -1554,7 +1541,7 @@ int config_parse_ifnames( if (r < 0) return log_oom(); - return 0; + return 1; } int config_parse_ip_port( @@ -1579,18 +1566,15 @@ int config_parse_ip_port( if (isempty(rvalue)) { *s = 0; - return 0; + return 1; } r = parse_ip_port(rvalue, &port); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse port '%s'.", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); *s = port; - - return 0; + return 1; } int config_parse_mtu( @@ -1618,11 +1602,8 @@ int config_parse_mtu( rvalue); return 0; } - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse MTU value '%s', ignoring: %m", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); 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); return 0; } - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse resource value, ignoring: %s", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); if (rl[ltype]) *rl[ltype] = d; @@ -1663,7 +1642,7 @@ int config_parse_rlimit( return log_oom(); } - return 0; + return 1; } int config_parse_permille( @@ -1686,15 +1665,11 @@ int config_parse_permille( assert(rvalue); r = parse_permille(rvalue); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse permille value, ignoring: %s", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); *permille = (unsigned) r; - - return 0; + return 1; } int config_parse_vlanprotocol( @@ -1716,20 +1691,17 @@ int config_parse_vlanprotocol( if (isempty(rvalue)) { *vlan_protocol = -1; - return 0; + return 1; } if (STR_IN_SET(rvalue, "802.1ad", "802.1AD")) *vlan_protocol = ETH_P_8021AD; else if (STR_IN_SET(rvalue, "802.1q", "802.1Q")) *vlan_protocol = ETH_P_8021Q; - else { - log_syntax(unit, LOG_WARNING, filename, line, 0, - "Failed to parse VLAN protocol value, ignoring: %s", rvalue); - return 0; - } + else + return log_syntax_parse_error(unit, filename, line, 0, lvalue, rvalue); - return 0; + return 1; } int config_parse_hw_addr( @@ -1753,18 +1725,15 @@ int config_parse_hw_addr( if (isempty(rvalue)) { *hwaddr = HW_ADDR_NULL; - return 0; + return 1; } r = parse_hw_addr_full(rvalue, ltype, &a); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Not a valid hardware address, ignoring assignment: %s", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); *hwaddr = a; - return 0; + return 1; } int config_parse_hw_addrs( @@ -1789,7 +1758,7 @@ int config_parse_hw_addrs( if (isempty(rvalue)) { /* Empty assignment resets the list */ *hwaddrs = set_free(*hwaddrs); - return 0; + return 1; } for (const char *p = rvalue;;) { @@ -1797,15 +1766,10 @@ int config_parse_hw_addrs( _cleanup_free_ struct hw_addr_data *n = NULL; 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) - return 0; - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Invalid syntax, ignoring: %s", rvalue); - return 0; - } + return 1; n = new(struct hw_addr_data, 1); if (!n) @@ -1846,7 +1810,7 @@ int config_parse_ether_addr( if (isempty(rvalue)) { *hwaddr = mfree(*hwaddr); - return 0; + return 1; } n = new0(struct ether_addr, 1); @@ -1854,15 +1818,11 @@ int config_parse_ether_addr( return log_oom(); r = parse_ether_addr(rvalue, n); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Not a valid MAC address, ignoring assignment: %s", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); free_and_replace(*hwaddr, n); - - return 0; + return 1; } int config_parse_ether_addrs( @@ -1887,7 +1847,7 @@ int config_parse_ether_addrs( if (isempty(rvalue)) { /* Empty assignment resets the list */ *hwaddrs = set_free(*hwaddrs); - return 0; + return 1; } for (const char *p = rvalue;;) { @@ -1895,15 +1855,10 @@ int config_parse_ether_addrs( _cleanup_free_ struct ether_addr *n = NULL; 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) - return 0; - if (r == -ENOMEM) - return log_oom(); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Invalid syntax, ignoring: %s", rvalue); - return 0; - } + return 1; n = new(struct ether_addr, 1); if (!n) @@ -1950,15 +1905,12 @@ int config_parse_in_addr_non_null( *ipv4 = (struct in_addr) {}; else *ipv6 = (struct in6_addr) {}; - return 0; + return 1; } r = in_addr_from_string(ltype, rvalue, &a); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse %s=, ignoring assignment: %s", lvalue, rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); if (!in_addr_is_set(ltype, &a)) { log_syntax(unit, LOG_WARNING, filename, line, 0, @@ -1970,7 +1922,7 @@ int config_parse_in_addr_non_null( *ipv4 = a.in; else *ipv6 = a.in6; - return 0; + return 1; } int config_parse_unsigned_bounded( @@ -1979,8 +1931,8 @@ int config_parse_unsigned_bounded( unsigned line, const char *section, unsigned section_line, - const char *name, - const char *value, + const char *lvalue, + const char *rvalue, unsigned min, unsigned max, bool ignoring, @@ -1989,26 +1941,21 @@ int config_parse_unsigned_bounded( int r; assert(filename); - assert(name); - assert(value); + assert(lvalue); + assert(rvalue); assert(ret); - r = safe_atou_bounded(value, min, max, ret); - if (r == -ERANGE) + r = safe_atou_bounded(rvalue, min, max, ret); + if (r == -ERANGE) { log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid '%s=%s', allowed range is %u..%u%s.", - name, value, min, max, ignoring ? ", ignoring" : ""); - else if (r < 0) - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse '%s=%s'%s: %m", - name, value, ignoring ? ", ignoring" : ""); + lvalue, rvalue, min, max, ignoring ? ", ignoring" : ""); + return ignoring ? 0 : r; + } + if (r < 0) + 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 */ - else if (ignoring) - return 0; - else - return r; + return 1; /* Return 1 if something was set */ } int config_parse_calendar( @@ -2034,21 +1981,20 @@ int config_parse_calendar( if (isempty(rvalue)) { *cr = calendar_spec_free(*cr); - return 0; + return 1; } r = calendar_spec_from_string(rvalue, &c); if (r < 0) - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse calendar specification, ignoring: %s", rvalue); - else - *cr = TAKE_PTR(c); + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); - 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_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, @@ -2071,17 +2017,18 @@ int config_parse_timezone( if (isempty(rvalue)) { *tz = mfree(*tz); - return 0; + return 1; } r = verify_timezone(rvalue, LOG_WARNING); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Timezone is not valid, ignoring assignment: %s", rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); - 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( @@ -2100,12 +2047,8 @@ int config_parse_ip_protocol( int r; r = isempty(rvalue) ? 0 : parse_ip_protocol_full(rvalue, /* relaxed= */ ltype); - if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, - "Failed to parse '%s=%s', ignoring: %m", - lvalue, rvalue); - return 0; - } + if (r < 0) + return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue); if (r > UINT8_MAX) { /* linux/fib_rules.h and linux/fou.h define the netlink field as one byte, so we need to diff --git a/src/shared/conf-parser.h b/src/shared/conf-parser.h index 937bdc73ed..bf64ab2ba6 100644 --- a/src/shared/conf-parser.h +++ b/src/shared/conf-parser.h @@ -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,76 +373,67 @@ 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; \ - size_t i = 0; \ + size_t n = 0; \ int r; \ \ - assert(filename); \ assert(lvalue); \ - assert(rvalue); \ - \ - xs = new0(type, 1); \ - if (!xs) \ - return -ENOMEM; \ - \ - *xs = invalid; \ \ for (const char *p = rvalue;;) { \ _cleanup_free_ char *en = NULL; \ - type x, *new_xs; \ + type x; \ \ 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) { \ + FOREACH_ARRAY(i, xs, n) \ + if (*i == x) { \ log_syntax(unit, LOG_NOTICE, filename, line, 0, \ - "Duplicate entry, ignoring: %s", \ - en); \ + "Duplicate entry %s in %s=, ignoring.", \ + en, lvalue); \ x = invalid; \ + break; \ } \ \ if (x == invalid) \ continue; \ \ - *(xs + i) = x; \ - new_xs = realloc(xs, (++i + 1) * sizeof(type)); \ - if (new_xs) \ - xs = new_xs; \ - else \ + /* Allocate one more for the trailing 'invalid'. */ \ + if (!GREEDY_REALLOC(xs, n + 2)) \ 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); \ return 1; \ } @@ -460,8 +444,8 @@ int config_parse_unsigned_bounded( unsigned line, const char *section, unsigned section_line, - const char *name, - const char *value, + const char *lvalue, + const char *rvalue, unsigned min, unsigned max, bool ignoring, @@ -473,8 +457,8 @@ static inline int config_parse_uint32_bounded( unsigned line, const char *section, unsigned section_line, - const char *name, - const char *value, + const char *lvalue, + const char *rvalue, uint32_t min, uint32_t max, bool ignoring, @@ -484,7 +468,7 @@ static inline int config_parse_uint32_bounded( int r; r = config_parse_unsigned_bounded( - unit, filename, line, section, section_line, name, value, + unit, filename, line, section, section_line, lvalue, rvalue, min, max, ignoring, &t); if (r <= 0) @@ -500,8 +484,8 @@ static inline int config_parse_uint16_bounded( unsigned line, const char *section, unsigned section_line, - const char *name, - const char *value, + const char *lvalue, + const char *rvalue, uint16_t min, uint16_t max, bool ignoring, @@ -511,7 +495,7 @@ static inline int config_parse_uint16_bounded( int r; r = config_parse_unsigned_bounded( - unit, filename, line, section, section_line, name, value, + unit, filename, line, section, section_line, lvalue, rvalue, min, max, ignoring, &t); if (r <= 0) @@ -527,8 +511,8 @@ static inline int config_parse_uint8_bounded( unsigned line, const char *section, unsigned section_line, - const char *name, - const char *value, + const char *lvalue, + const char *rvalue, uint8_t min, uint8_t max, bool ignoring, @@ -538,7 +522,7 @@ static inline int config_parse_uint8_bounded( int r; r = config_parse_unsigned_bounded( - unit, filename, line, section, section_line, name, value, + unit, filename, line, section, section_line, lvalue, rvalue, min, max, ignoring, &t); if (r <= 0) diff --git a/src/shared/ethtool-util.c b/src/shared/ethtool-util.c index 1e100c35ef..174614a432 100644 --- a/src/shared/ethtool-util.c +++ b/src/shared/ethtool-util.c @@ -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", diff --git a/src/shared/resolve-util.c b/src/shared/resolve-util.c index 820f9bb530..e01578fbcb 100644 --- a/src/shared/resolve-util.c +++ b/src/shared/resolve-util.c @@ -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", diff --git a/src/sysupdate/sysupdate-transfer.c b/src/sysupdate/sysupdate-transfer.c index cf93d33f5e..7ea168961e 100644 --- a/src/sysupdate/sysupdate-transfer.c +++ b/src/sysupdate/sysupdate-transfer.c @@ -377,10 +377,10 @@ static int config_parse_resource_path( 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, - PATH_RELATIVE_TO_ROOT, "Invalid PathRelativeTo= value"); + PATH_RELATIVE_TO_ROOT); static int config_parse_resource_ptype( const char *unit, diff --git a/src/test/test-conf-parser.c b/src/test/test-conf-parser.c index 5643053460..a4309c0134 100644 --- a/src/test/test-conf-parser.c +++ b/src/test/test-conf-parser.c @@ -16,78 +16,85 @@ static void test_config_parse_path_one(const char *rvalue, const char *expected) { _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); } static void test_config_parse_log_level_one(const char *rvalue, int expected) { int log_level = 0; - assert_se(config_parse_log_level("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_level, NULL) >= 0); - assert_se(expected == log_level); + ASSERT_OK(config_parse_log_level("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_level, NULL)); + ASSERT_EQ(expected, log_level); } static void test_config_parse_log_facility_one(const char *rvalue, int expected) { int log_facility = 0; - assert_se(config_parse_log_facility("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_facility, NULL) >= 0); - assert_se(expected == log_facility); + ASSERT_OK(config_parse_log_facility("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &log_facility, NULL)); + ASSERT_EQ(expected, log_facility); } static void test_config_parse_iec_size_one(const char *rvalue, size_t expected) { size_t iec_size = 0; - assert_se(config_parse_iec_size("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &iec_size, NULL) >= 0); - assert_se(expected == iec_size); + ASSERT_OK(config_parse_iec_size("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &iec_size, NULL)); + ASSERT_EQ(expected, iec_size); } static void test_config_parse_si_uint64_one(const char *rvalue, uint64_t expected) { uint64_t si_uint64 = 0; - assert_se(config_parse_si_uint64("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_uint64, NULL) >= 0); - assert_se(expected == si_uint64); + ASSERT_OK(config_parse_si_uint64("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &si_uint64, NULL)); + ASSERT_EQ(expected, si_uint64); } static void test_config_parse_int_one(const char *rvalue, int expected) { int v = -1; - assert_se(config_parse_int("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); - assert_se(expected == v); + ASSERT_OK(config_parse_int("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL)); + ASSERT_EQ(expected, v); } static void test_config_parse_unsigned_one(const char *rvalue, unsigned expected) { unsigned v = 0; - assert_se(config_parse_unsigned("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); - assert_se(expected == v); + ASSERT_OK(config_parse_unsigned("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL)); + 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; - assert_se(config_parse_strv("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &strv, NULL) >= 0); - assert_se(strv_equal(expected, strv)); + ASSERT_OK(config_parse_strv("unit", "filename", 1, "section", 1, "lvalue", filter_duplicates, rvalue, &strv, NULL)); + ASSERT_TRUE(strv_equal(expected, strv)); } static void test_config_parse_mode_one(const char *rvalue, mode_t expected) { mode_t v = 0; - assert_se(config_parse_mode("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); - assert_se(expected == v); + ASSERT_OK(config_parse_mode("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL)); + ASSERT_EQ(expected, v); } static void test_config_parse_sec_one(const char *rvalue, usec_t expected) { usec_t v = 0; - assert_se(config_parse_sec("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); - assert_se(expected == v); + ASSERT_OK(config_parse_sec("unit", "filename", 1, "section", 1, "lvalue", 0, rvalue, &v, NULL)); + ASSERT_EQ(expected, v); } static void test_config_parse_nsec_one(const char *rvalue, nsec_t expected) { nsec_t v = 0; - assert_se(config_parse_nsec("unit", "filename", 1, "nsection", 1, "lvalue", 0, rvalue, &v, NULL) >= 0); - assert_se(expected == v); + ASSERT_OK(config_parse_nsec("unit", "filename", 1, "nsection", 1, "lvalue", 0, rvalue, &v, NULL)); + 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) { @@ -164,12 +171,19 @@ TEST(config_parse_unsigned) { } TEST(config_parse_strv) { - test_config_parse_strv_one("", STRV_MAKE_EMPTY); - test_config_parse_strv_one("foo", STRV_MAKE("foo")); - test_config_parse_strv_one("foo bar foo", STRV_MAKE("foo", "bar", "foo")); - test_config_parse_strv_one("\"foo bar\" foo", STRV_MAKE("foo bar", "foo")); - test_config_parse_strv_one("\xc3\x80", STRV_MAKE("\xc3\x80")); - test_config_parse_strv_one("\xc3\x7f", STRV_MAKE("\xc3\x7f")); + test_config_parse_strv_one("", false, STRV_MAKE_EMPTY); + test_config_parse_strv_one("foo", false, STRV_MAKE("foo")); + test_config_parse_strv_one("foo bar foo", false, 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", false, STRV_MAKE("\xc3\x80")); + 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) { @@ -206,11 +220,8 @@ TEST(config_parse_nsec) { } TEST(config_parse_iec_uint64) { - uint64_t offset = 0; - assert_se(config_parse_iec_uint64(NULL, "/this/file", 11, "Section", 22, "Size", 0, "4M", &offset, NULL) == 0); - 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); + test_config_parse_iec_uint64_one("4M", UINT64_C(4 * 1024 * 1024)); + test_config_parse_iec_uint64_one("4.5M", UINT64_C((4 * 1024 + 512) * 1024)); } #define x10(x) x x x x x x x x x x diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 647cdeeb9d..645c7f840a 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -1446,13 +1446,10 @@ DEFINE_CONFIG_PARSE_ENUM_WITH_DEFAULT( config_parse_mac_address_policy, mac_address_policy, MACAddressPolicy, - MAC_ADDRESS_POLICY_NONE, - "Failed to parse MAC address policy"); + MAC_ADDRESS_POLICY_NONE); DEFINE_CONFIG_PARSE_ENUMV(config_parse_name_policy, name_policy, NamePolicy, - _NAMEPOLICY_INVALID, - "Failed to parse interface name policy"); + _NAMEPOLICY_INVALID); DEFINE_CONFIG_PARSE_ENUMV(config_parse_alternative_names_policy, alternative_names_policy, NamePolicy, - _NAMEPOLICY_INVALID, - "Failed to parse alternative names policy"); + _NAMEPOLICY_INVALID); diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 5018541661..c46fcaa038 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -65,7 +65,7 @@ static int listen_fds(int *ret_ctrl, int *ret_netlink) { 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) { int r, log_val = -1;