mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-06 20:10:17 +01:00
ifcfg-rh: cleanup write_wired_setting()
Drop some local variables, or move them inside a nested scope, closer to where they are used.
This commit is contained in:
parent
f69fb04cd0
commit
1bcf104782
1 changed files with 42 additions and 44 deletions
|
|
@ -809,7 +809,7 @@ write_wireless_setting (NMConnection *connection,
|
|||
const char *device_mac, *cloned_mac;
|
||||
guint32 mtu, chan, i;
|
||||
gboolean adhoc = FALSE, hex_ssid = FALSE;
|
||||
const char * const *macaddr_blacklist;
|
||||
const char *const*macaddr_blacklist;
|
||||
|
||||
s_wireless = nm_connection_get_setting_wireless (connection);
|
||||
if (!s_wireless) {
|
||||
|
|
@ -1041,13 +1041,11 @@ static gboolean
|
|||
write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
||||
{
|
||||
NMSettingWired *s_wired;
|
||||
const char *device_mac, *cloned_mac;
|
||||
char *tmp;
|
||||
const char *nettype, *portname, *ctcprot, *s390_key, *s390_val, *duplex;
|
||||
const char *const*s390_subchannels;
|
||||
const char *duplex;
|
||||
guint32 mtu, num_opts, speed, i;
|
||||
const char *const *s390_subchannels;
|
||||
GString *str = NULL;
|
||||
const char * const *macaddr_blacklist;
|
||||
const char *const*macaddr_blacklist;
|
||||
gboolean auto_negotiate;
|
||||
NMSettingWiredWakeOnLan wol;
|
||||
const char *wol_password;
|
||||
|
|
@ -1059,77 +1057,78 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
return FALSE;
|
||||
}
|
||||
|
||||
device_mac = nm_setting_wired_get_mac_address (s_wired);
|
||||
svSetValueStr (ifcfg, "HWADDR", device_mac);
|
||||
svSetValueStr (ifcfg, "HWADDR",
|
||||
nm_setting_wired_get_mac_address (s_wired));
|
||||
|
||||
cloned_mac = nm_setting_wired_get_cloned_mac_address (s_wired);
|
||||
svSetValueStr (ifcfg, "MACADDR", cloned_mac);
|
||||
svSetValueStr (ifcfg, "MACADDR",
|
||||
nm_setting_wired_get_cloned_mac_address (s_wired));
|
||||
|
||||
svSetValueStr (ifcfg, "GENERATE_MAC_ADDRESS_MASK",
|
||||
nm_setting_wired_get_generate_mac_address_mask (s_wired));
|
||||
|
||||
svUnsetValue (ifcfg, "HWADDR_BLACKLIST");
|
||||
macaddr_blacklist = nm_setting_wired_get_mac_address_blacklist (s_wired);
|
||||
if (macaddr_blacklist[0]) {
|
||||
char *blacklist_str;
|
||||
gs_free char *blacklist_str = NULL;
|
||||
|
||||
blacklist_str = g_strjoinv (" ", (char **) macaddr_blacklist);
|
||||
svSetValueStr (ifcfg, "HWADDR_BLACKLIST", blacklist_str);
|
||||
g_free (blacklist_str);
|
||||
}
|
||||
} else
|
||||
svUnsetValue (ifcfg, "HWADDR_BLACKLIST");
|
||||
|
||||
mtu = nm_setting_wired_get_mtu (s_wired);
|
||||
svSetValueInt64_cond (ifcfg, "MTU", mtu != 0, mtu);
|
||||
|
||||
svUnsetValue (ifcfg, "SUBCHANNELS");
|
||||
s390_subchannels = nm_setting_wired_get_s390_subchannels (s_wired);
|
||||
if (s390_subchannels) {
|
||||
int len = g_strv_length ((char **)s390_subchannels);
|
||||
|
||||
tmp = NULL;
|
||||
{
|
||||
gs_free char *tmp = NULL;
|
||||
gsize len = NM_PTRARRAY_LEN (s390_subchannels);
|
||||
|
||||
if (len == 2) {
|
||||
tmp = g_strdup_printf ("%s,%s", s390_subchannels[0], s390_subchannels[1]);
|
||||
tmp = g_strdup_printf ("%s,%s",
|
||||
s390_subchannels[0],
|
||||
s390_subchannels[1]);
|
||||
} else if (len == 3) {
|
||||
tmp = g_strdup_printf ("%s,%s,%s", s390_subchannels[0], s390_subchannels[1],
|
||||
tmp = g_strdup_printf ("%s,%s,%s",
|
||||
s390_subchannels[0],
|
||||
s390_subchannels[1],
|
||||
s390_subchannels[2]);
|
||||
}
|
||||
|
||||
svSetValueStr (ifcfg, "SUBCHANNELS", tmp);
|
||||
g_free (tmp);
|
||||
}
|
||||
|
||||
svUnsetValue (ifcfg, "NETTYPE");
|
||||
nettype = nm_setting_wired_get_s390_nettype (s_wired);
|
||||
if (nettype)
|
||||
svSetValueStr (ifcfg, "NETTYPE", nettype);
|
||||
svSetValueStr (ifcfg, "NETTYPE",
|
||||
nm_setting_wired_get_s390_nettype (s_wired));
|
||||
|
||||
svUnsetValue (ifcfg, "PORTNAME");
|
||||
portname = nm_setting_wired_get_s390_option_by_key (s_wired, "portname");
|
||||
if (portname)
|
||||
svSetValueStr (ifcfg, "PORTNAME", portname);
|
||||
svSetValueStr (ifcfg, "PORTNAME",
|
||||
nm_setting_wired_get_s390_option_by_key (s_wired, "portname"));
|
||||
|
||||
svUnsetValue (ifcfg, "CTCPROT");
|
||||
ctcprot = nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot");
|
||||
if (ctcprot)
|
||||
svSetValueStr (ifcfg, "CTCPROT", ctcprot);
|
||||
svSetValueStr (ifcfg, "CTCPROT",
|
||||
nm_setting_wired_get_s390_option_by_key (s_wired, "ctcprot"));
|
||||
|
||||
svUnsetValue (ifcfg, "OPTIONS");
|
||||
num_opts = nm_setting_wired_get_num_s390_options (s_wired);
|
||||
if (s390_subchannels && num_opts) {
|
||||
str = g_string_sized_new (30);
|
||||
nm_auto_free_gstring GString *tmp = NULL;
|
||||
|
||||
for (i = 0; i < num_opts; i++) {
|
||||
const char *s390_key, *s390_val;
|
||||
|
||||
nm_setting_wired_get_s390_option (s_wired, i, &s390_key, &s390_val);
|
||||
|
||||
/* portname is handled separately */
|
||||
if (!strcmp (s390_key, "portname") || !strcmp (s390_key, "ctcprot"))
|
||||
continue;
|
||||
|
||||
if (str->len)
|
||||
g_string_append_c (str, ' ');
|
||||
g_string_append_printf (str, "%s=%s", s390_key, s390_val);
|
||||
if (!tmp)
|
||||
tmp = g_string_sized_new (30);
|
||||
else
|
||||
g_string_append_c (tmp, ' ');
|
||||
g_string_append_printf (tmp, "%s=%s", s390_key, s390_val);
|
||||
}
|
||||
if (str->len)
|
||||
svSetValueStr (ifcfg, "OPTIONS", str->str);
|
||||
g_string_free (str, TRUE);
|
||||
if (tmp)
|
||||
svSetValueStr (ifcfg, "OPTIONS", tmp->str);
|
||||
}
|
||||
|
||||
/* Stuff ETHTOOL_OPT with required options */
|
||||
|
|
@ -1161,8 +1160,7 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_IGNORE)
|
||||
svSetValue (ifcfg, "ETHTOOL_WAKE_ON_LAN", "ignore");
|
||||
else if (wol == NM_SETTING_WIRED_WAKE_ON_LAN_DEFAULT) {
|
||||
if (!str)
|
||||
svUnsetValue (ifcfg, "ETHTOOL_OPTS");
|
||||
/* pass */
|
||||
} else {
|
||||
if (!str)
|
||||
str = g_string_sized_new (30);
|
||||
|
|
@ -1193,8 +1191,8 @@ write_wired_setting (NMConnection *connection, shvarFile *ifcfg, GError **error)
|
|||
if (str) {
|
||||
svSetValueStr (ifcfg, "ETHTOOL_OPTS", str->str);
|
||||
g_string_free (str, TRUE);
|
||||
}
|
||||
/* End ETHTOOL_OPT stuffing */
|
||||
} else
|
||||
svUnsetValue (ifcfg, "ETHTOOL_OPTS");
|
||||
|
||||
svSetValueStr (ifcfg, "TYPE", TYPE_ETHERNET);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue