ifcfg-rh: use cleanup attribute for error handling in reader
Drop some uses of "goto error". Instead, have the memory owned by an auto variable and automatically release it via the cleanup attribute.
This commit is contained in:
@@ -653,9 +653,10 @@ read_one_ip4_route (shvarFile *ifcfg,
|
|||||||
static gboolean
|
static gboolean
|
||||||
read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error)
|
read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError **error)
|
||||||
{
|
{
|
||||||
char *contents = NULL;
|
gs_free char *contents = NULL;
|
||||||
|
gs_strfreev char **lines = NULL;
|
||||||
gsize len = 0;
|
gsize len = 0;
|
||||||
char **lines = NULL, **iter;
|
char **iter;
|
||||||
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
|
GRegex *regex_to1, *regex_to2, *regex_via, *regex_metric;
|
||||||
GMatchInfo *match_info;
|
GMatchInfo *match_info;
|
||||||
int prefix_int;
|
int prefix_int;
|
||||||
@@ -675,8 +676,8 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
|
|||||||
g_return_val_if_fail (!error || !*error, FALSE);
|
g_return_val_if_fail (!error || !*error, FALSE);
|
||||||
|
|
||||||
/* Read the route file */
|
/* Read the route file */
|
||||||
if (!g_file_get_contents (filename, &contents, &len, NULL) || !len) {
|
if ( !g_file_get_contents (filename, &contents, &len, NULL)
|
||||||
g_free (contents);
|
|| !len) {
|
||||||
return TRUE; /* missing/empty = success */
|
return TRUE; /* missing/empty = success */
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -787,8 +788,6 @@ read_route_file_legacy (const char *filename, NMSettingIPConfig *s_ip4, GError *
|
|||||||
success = TRUE;
|
success = TRUE;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
g_free (contents);
|
|
||||||
g_strfreev (lines);
|
|
||||||
g_regex_unref (regex_to1);
|
g_regex_unref (regex_to1);
|
||||||
g_regex_unref (regex_to2);
|
g_regex_unref (regex_to2);
|
||||||
g_regex_unref (regex_via);
|
g_regex_unref (regex_via);
|
||||||
@@ -3384,23 +3383,22 @@ make_leap_setting (shvarFile *ifcfg,
|
|||||||
const char *file,
|
const char *file,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
NMSettingWirelessSecurity *wsec;
|
gs_unref_object NMSettingWirelessSecurity *wsec = NULL;
|
||||||
shvarFile *keys_ifcfg;
|
shvarFile *keys_ifcfg;
|
||||||
char *value;
|
gs_free char *value = NULL;
|
||||||
NMSettingSecretFlags flags;
|
NMSettingSecretFlags flags;
|
||||||
|
|
||||||
wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
|
wsec = NM_SETTING_WIRELESS_SECURITY (nm_setting_wireless_security_new ());
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "KEY_MGMT");
|
value = svGetValueStr_cp (ifcfg, "KEY_MGMT");
|
||||||
if (!value || strcmp (value, "IEEE8021X"))
|
if (!value || strcmp (value, "IEEE8021X"))
|
||||||
goto error; /* Not LEAP */
|
return NULL;
|
||||||
|
nm_clear_g_free (&value);
|
||||||
|
|
||||||
g_free (value);
|
|
||||||
value = svGetValueStr_cp (ifcfg, "SECURITYMODE");
|
value = svGetValueStr_cp (ifcfg, "SECURITYMODE");
|
||||||
if (!value || strcasecmp (value, "leap"))
|
if (!value || strcasecmp (value, "leap"))
|
||||||
goto error; /* Not LEAP */
|
return NULL; /* Not LEAP */
|
||||||
|
nm_clear_g_free (&value);
|
||||||
g_free (value);
|
|
||||||
|
|
||||||
flags = read_secret_flags (ifcfg, "IEEE_8021X_PASSWORD_FLAGS");
|
flags = read_secret_flags (ifcfg, "IEEE_8021X_PASSWORD_FLAGS");
|
||||||
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, flags, NULL);
|
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS, flags, NULL);
|
||||||
@@ -3418,30 +3416,24 @@ make_leap_setting (shvarFile *ifcfg,
|
|||||||
}
|
}
|
||||||
if (value && strlen (value))
|
if (value && strlen (value))
|
||||||
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, value, NULL);
|
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD, value, NULL);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "IEEE_8021X_IDENTITY");
|
value = svGetValueStr_cp (ifcfg, "IEEE_8021X_IDENTITY");
|
||||||
if (!value) {
|
if (!value) {
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Missing LEAP identity");
|
"Missing LEAP identity");
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, value, NULL);
|
g_object_set (wsec, NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME, value, NULL);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
|
|
||||||
g_object_set (wsec,
|
g_object_set (wsec,
|
||||||
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x",
|
NM_SETTING_WIRELESS_SECURITY_KEY_MGMT, "ieee8021x",
|
||||||
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap",
|
NM_SETTING_WIRELESS_SECURITY_AUTH_ALG, "leap",
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
return (NMSetting *) wsec;
|
return (NMSetting *) g_steal_pointer (&wsec);
|
||||||
|
|
||||||
error:
|
|
||||||
g_free (value);
|
|
||||||
if (wsec)
|
|
||||||
g_object_unref (wsec);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NMSetting *
|
static NMSetting *
|
||||||
@@ -4007,8 +3999,8 @@ make_wired_setting (shvarFile *ifcfg,
|
|||||||
NMSetting8021x **s_8021x,
|
NMSetting8021x **s_8021x,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
NMSettingWired *s_wired;
|
gs_unref_object NMSettingWired *s_wired = NULL;
|
||||||
char *value = NULL;
|
gs_free char *value = NULL;
|
||||||
char *nettype;
|
char *nettype;
|
||||||
|
|
||||||
s_wired = NM_SETTING_WIRED (nm_setting_wired_new ());
|
s_wired = NM_SETTING_WIRED (nm_setting_wired_new ());
|
||||||
@@ -4022,14 +4014,14 @@ make_wired_setting (shvarFile *ifcfg,
|
|||||||
g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL);
|
g_object_set (s_wired, NM_SETTING_WIRED_MTU, (guint) mtu, NULL);
|
||||||
else
|
else
|
||||||
PARSE_WARNING ("invalid MTU '%s'", value);
|
PARSE_WARNING ("invalid MTU '%s'", value);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "HWADDR");
|
value = svGetValueStr_cp (ifcfg, "HWADDR");
|
||||||
if (value) {
|
if (value) {
|
||||||
value = g_strstrip (value);
|
value = g_strstrip (value);
|
||||||
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, value, NULL);
|
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS, value, NULL);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "SUBCHANNELS");
|
value = svGetValueStr_cp (ifcfg, "SUBCHANNELS");
|
||||||
@@ -4060,19 +4052,19 @@ make_wired_setting (shvarFile *ifcfg,
|
|||||||
g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, chans, NULL);
|
g_object_set (s_wired, NM_SETTING_WIRED_S390_SUBCHANNELS, chans, NULL);
|
||||||
g_strfreev (chans);
|
g_strfreev (chans);
|
||||||
}
|
}
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "PORTNAME");
|
value = svGetValueStr_cp (ifcfg, "PORTNAME");
|
||||||
if (value) {
|
if (value) {
|
||||||
nm_setting_wired_add_s390_option (s_wired, "portname", value);
|
nm_setting_wired_add_s390_option (s_wired, "portname", value);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "CTCPROT");
|
value = svGetValueStr_cp (ifcfg, "CTCPROT");
|
||||||
if (value) {
|
if (value) {
|
||||||
nm_setting_wired_add_s390_option (s_wired, "ctcprot", value);
|
nm_setting_wired_add_s390_option (s_wired, "ctcprot", value);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
nettype = svGetValueStr_cp (ifcfg, "NETTYPE");
|
nettype = svGetValueStr_cp (ifcfg, "NETTYPE");
|
||||||
@@ -4102,28 +4094,28 @@ make_wired_setting (shvarFile *ifcfg,
|
|||||||
iter++;
|
iter++;
|
||||||
}
|
}
|
||||||
g_strfreev (options);
|
g_strfreev (options);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "MACADDR");
|
g_object_set (s_wired,
|
||||||
if (value) {
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS,
|
||||||
value = g_strstrip (value);
|
svGetValueStr (ifcfg, "MACADDR", &value),
|
||||||
g_object_set (s_wired, NM_SETTING_WIRED_CLONED_MAC_ADDRESS, value, NULL);
|
NULL);
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "GENERATE_MAC_ADDRESS_MASK");
|
g_object_set (s_wired,
|
||||||
g_object_set (s_wired, NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK, value, NULL);
|
NM_SETTING_WIRED_GENERATE_MAC_ADDRESS_MASK,
|
||||||
g_free (value);
|
svGetValueStr (ifcfg, "GENERATE_MAC_ADDRESS_MASK", &value),
|
||||||
|
NULL);
|
||||||
|
nm_clear_g_free (&value);
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "HWADDR_BLACKLIST");
|
value = svGetValueStr_cp (ifcfg, "HWADDR_BLACKLIST");
|
||||||
if (value) {
|
if (value) {
|
||||||
char **strv;
|
gs_strfreev char **strv = NULL;
|
||||||
|
|
||||||
strv = transform_hwaddr_blacklist (value);
|
strv = transform_hwaddr_blacklist (value);
|
||||||
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, strv, NULL);
|
g_object_set (s_wired, NM_SETTING_WIRED_MAC_ADDRESS_BLACKLIST, strv, NULL);
|
||||||
g_strfreev (strv);
|
nm_clear_g_free (&value);
|
||||||
g_free (value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
value = svGetValueStr_cp (ifcfg, "KEY_MGMT");
|
value = svGetValueStr_cp (ifcfg, "KEY_MGMT");
|
||||||
@@ -4131,25 +4123,20 @@ make_wired_setting (shvarFile *ifcfg,
|
|||||||
if (!strcmp (value, "IEEE8021X")) {
|
if (!strcmp (value, "IEEE8021X")) {
|
||||||
*s_8021x = fill_8021x (ifcfg, file, value, FALSE, error);
|
*s_8021x = fill_8021x (ifcfg, file, value, FALSE, error);
|
||||||
if (!*s_8021x)
|
if (!*s_8021x)
|
||||||
goto error;
|
return NULL;
|
||||||
} else {
|
} else {
|
||||||
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
g_set_error (error, NM_SETTINGS_ERROR, NM_SETTINGS_ERROR_INVALID_CONNECTION,
|
||||||
"Unknown wired KEY_MGMT type '%s'", value);
|
"Unknown wired KEY_MGMT type '%s'", value);
|
||||||
goto error;
|
return NULL;
|
||||||
}
|
}
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
parse_ethtool_options (ifcfg, s_wired,
|
parse_ethtool_options (ifcfg, s_wired,
|
||||||
svGetValue (ifcfg, "ETHTOOL_OPTS", &value));
|
svGetValue (ifcfg, "ETHTOOL_OPTS", &value));
|
||||||
g_free (value);
|
nm_clear_g_free (&value);
|
||||||
|
|
||||||
return (NMSetting *) s_wired;
|
return (NMSetting *) g_steal_pointer (&s_wired);
|
||||||
|
|
||||||
error:
|
|
||||||
g_free (value);
|
|
||||||
g_object_unref (s_wired);
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static NMConnection *
|
static NMConnection *
|
||||||
|
Reference in New Issue
Block a user