ifcfg-rh: rename svFindFirstKeyWithPrefix() to svFindFirstNumberedKey() for finding NETMASK

svFindFirstKeyWithPrefix() only had one caller: to find whether there are
any NETMASK variables set. NETMASK is a numbered variable, so we should only
find variables that indeed follow the pattern. Since there was only
one caller, rename and repurpose the function.
This commit is contained in:
Thomas Haller 2019-12-20 09:24:30 +01:00
parent 820696f352
commit 9085c5c3a9
3 changed files with 5 additions and 7 deletions

View file

@ -2402,7 +2402,7 @@ write_ip4_setting (NMConnection *connection,
else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) else if (!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED))
svSetValueStr (ifcfg, "BOOTPROTO", "shared"); svSetValueStr (ifcfg, "BOOTPROTO", "shared");
has_netmask = !!svFindFirstKeyWithPrefix (ifcfg, "NETMASK"); has_netmask = !!svFindFirstNumberedKey (ifcfg, "NETMASK");
/* Write out IPADDR<n>, PREFIX<n>, GATEWAY<n> for current IP addresses /* Write out IPADDR<n>, PREFIX<n>, GATEWAY<n> for current IP addresses
* without labels. Unset obsolete NETMASK<n>. * without labels. Unset obsolete NETMASK<n>.

View file

@ -998,19 +998,17 @@ svGetKeysSorted (shvarFile *s,
/*****************************************************************************/ /*****************************************************************************/
const char * const char *
svFindFirstKeyWithPrefix (shvarFile *s, const char *key_prefix) svFindFirstNumberedKey (shvarFile *s, const char *key_prefix)
{ {
CList *current;
const shvarLine *l; const shvarLine *l;
g_return_val_if_fail (s, NULL); g_return_val_if_fail (s, NULL);
g_return_val_if_fail (key_prefix, NULL); g_return_val_if_fail (key_prefix, NULL);
c_list_for_each (current, &s->lst_head) { c_list_for_each_entry (l, &s->lst_head, lst) {
l = c_list_entry (current, shvarLine, lst);
if ( l->key if ( l->key
&& l->line && l->line
&& g_str_has_prefix (l->key, key_prefix)) && nms_ifcfg_rh_utils_is_numbered_tag (l->key, key_prefix, NULL))
return l->key; return l->key;
} }

View file

@ -30,7 +30,7 @@ shvarFile *svCreateFile (const char *name);
/* Open the file <name>, return shvarFile on success, NULL on failure */ /* Open the file <name>, return shvarFile on success, NULL on failure */
shvarFile *svOpenFile (const char *name, GError **error); shvarFile *svOpenFile (const char *name, GError **error);
const char *svFindFirstKeyWithPrefix (shvarFile *s, const char *key_prefix); const char *svFindFirstNumberedKey (shvarFile *s, const char *key_prefix);
/* Get the value associated with the key, and leave the current pointer /* Get the value associated with the key, and leave the current pointer
* pointing at the line containing the value. The char* returned MUST * pointing at the line containing the value. The char* returned MUST