diff options
author | Thomas Haller <thaller@redhat.com> | 2023-03-15 17:06:30 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-03-15 17:06:30 +0100 |
commit | c7675c73eee3c460ad23ac8b16ec83e9c332f189 (patch) | |
tree | 2ea66f54ad7e36b54332d84e841408704c6d7bc7 | |
parent | d453188ed223102e9459d1c0c48ec43952fc5975 (diff) | |
parent | 8a12713568c51e34a218113d25e81ca671e5f1d9 (diff) |
ifcfg-rh: merge branch 'th/ifcfg-hostname'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1568
-rw-r--r-- | src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c | 21 | ||||
-rw-r--r-- | src/core/settings/plugins/ifcfg-rh/shvar.c | 23 |
2 files changed, 32 insertions, 12 deletions
diff --git a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c index 832e969fb5..a784662fd3 100644 --- a/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c +++ b/src/core/settings/plugins/ifcfg-rh/nms-ifcfg-rh-reader.c @@ -2591,7 +2591,7 @@ make_ip6_setting(shvarFile *ifcfg, shvarFile *network_ifcfg, gboolean routes_rea &local)) { PARSE_WARNING("%s", local->message); g_clear_error(&local); - } else if (errno == ENOENT) { + } else if (errno == ENOKEY) { /* The key is not specified. If "v" (IPV6_TOKEN) is set, * we default to EUI64. Otherwise, the connection would not verify. */ if (v) @@ -2683,16 +2683,25 @@ make_hostname_setting(shvarFile *ifcfg) NMTernary from_dns_lookup; NMTernary only_from_default; int priority; + gboolean has_setting = FALSE; priority = svGetValueInt64(ifcfg, "HOSTNAME_PRIORITY", 10, G_MININT32, G_MAXINT32, 0); + if (!has_setting && errno != ENOKEY) + has_setting = TRUE; + + from_dhcp = svGetValueTernary(ifcfg, "HOSTNAME_FROM_DHCP"); + if (!has_setting && errno != ENOKEY) + has_setting = TRUE; + + from_dns_lookup = svGetValueTernary(ifcfg, "HOSTNAME_FROM_DNS_LOOKUP"); + if (!has_setting && errno != ENOKEY) + has_setting = TRUE; - from_dhcp = svGetValueTernary(ifcfg, "HOSTNAME_FROM_DHCP"); - from_dns_lookup = svGetValueTernary(ifcfg, "HOSTNAME_FROM_DNS_LOOKUP"); only_from_default = svGetValueTernary(ifcfg, "HOSTNAME_ONLY_FROM_DEFAULT"); + if (!has_setting && errno != ENOKEY) + has_setting = TRUE; - /* Create the setting when at least one key is not default*/ - if (priority == 0 && from_dhcp == NM_TERNARY_DEFAULT && from_dns_lookup == NM_TERNARY_DEFAULT - && only_from_default == NM_TERNARY_DEFAULT) + if (!has_setting) return NULL; setting = nm_setting_hostname_new(); diff --git a/src/core/settings/plugins/ifcfg-rh/shvar.c b/src/core/settings/plugins/ifcfg-rh/shvar.c index fe8187c395..1ca2ea606f 100644 --- a/src/core/settings/plugins/ifcfg-rh/shvar.c +++ b/src/core/settings/plugins/ifcfg-rh/shvar.c @@ -97,23 +97,32 @@ static void _line_link_parse(shvarFile *s, const char *value, gsize len); * in case no valid value is found, the fallback value. Valid values * are: "yes", "true", "t", "y", "1" and "no", "false", "f", "n", "0". * + * Always sets errno. Either to zero on success, to ENOKEY for NULL + * or to EINVAL otherwise. + * * Returns: the parsed boolean value or @fallback. */ int svParseBoolean(const char *value, int fallback) { - if (!value) + if (!value) { + errno = ENOKEY; return fallback; + } if (!g_ascii_strcasecmp("yes", value) || !g_ascii_strcasecmp("true", value) || !g_ascii_strcasecmp("t", value) || !g_ascii_strcasecmp("y", value) - || !g_ascii_strcasecmp("1", value)) + || !g_ascii_strcasecmp("1", value)) { + errno = 0; return TRUE; - else if (!g_ascii_strcasecmp("no", value) || !g_ascii_strcasecmp("false", value) - || !g_ascii_strcasecmp("f", value) || !g_ascii_strcasecmp("n", value) - || !g_ascii_strcasecmp("0", value)) + } else if (!g_ascii_strcasecmp("no", value) || !g_ascii_strcasecmp("false", value) + || !g_ascii_strcasecmp("f", value) || !g_ascii_strcasecmp("n", value) + || !g_ascii_strcasecmp("0", value)) { + errno = 0; return FALSE; + } + errno = EINVAL; return fallback; } @@ -1253,6 +1262,7 @@ svGetValueStr_cp(shvarFile *s, const char *key) * @fallback: the fallback value in any error case * * Reads a value @key and converts it to a boolean using svParseBoolean(). + * This always sets errno, see svParseBoolean(). * * Returns: the parsed boolean value or @fallback. */ @@ -1271,6 +1281,7 @@ svGetValueBoolean(shvarFile *s, const char *key, int fallback) * @key: the name of the key to read * * Reads a value @key and converts it to a NMTernary value. + * This always sets errno, see svParseBoolean(). * * Returns: the parsed NMTernary */ @@ -1328,7 +1339,7 @@ svGetValueEnum(shvarFile *s, const char *key, GType gtype, int *out_value, GErro if (!svalue) { /* don't touch out_value. The caller is supposed * to initialize it with the default value. */ - errno = ENOENT; + errno = ENOKEY; return TRUE; } |