summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2016-10-08 14:08:53 +0200
committerThomas Haller <thaller@redhat.com>2016-10-11 11:37:46 +0200
commit96846352de0c5110128e82171c6648b7083936bb (patch)
tree8c7703debae4df2141511c0dfde4ab5b81afa97e
parent0ed009f23690cd80076f61cd209453d3037a48e2 (diff)
downloadNetworkManager-96846352de0c5110128e82171c6648b7083936bb.tar.gz
ifcfg-rh: minor cleanups in writer
-rw-r--r--src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c29
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c7
2 files changed, 16 insertions, 20 deletions
diff --git a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
index a0b0bd03a0..37a2a27fdd 100644
--- a/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
+++ b/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-writer.c
@@ -125,12 +125,11 @@ set_secret (shvarFile *ifcfg,
goto error;
}
- /* Clear the secret from the associated "keys" file */
- svUnsetValue (keyfile, key);
-
/* Only write the secret if it's system owned and supposed to be saved */
if (flags == NM_SETTING_SECRET_FLAG_NONE)
svSetValue (keyfile, key, value, verbatim);
+ else
+ svUnsetValue (keyfile, key);
if (!svWriteFile (keyfile, 0600, &error)) {
_LOGW ("could not update ifcfg file '%s': %s",
@@ -485,7 +484,7 @@ write_8021x_setting (NMConnection *connection,
if (value)
tmp = g_ascii_strup (value, -1);
}
- svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp ? tmp : NULL, FALSE);
+ svSetValue (ifcfg, "IEEE_8021X_EAP_METHODS", tmp, FALSE);
g_free (tmp);
svSetValue (ifcfg, "IEEE_8021X_IDENTITY",
@@ -1616,19 +1615,16 @@ write_team_port_setting (NMConnection *connection, shvarFile *ifcfg, GError **er
static void
write_dcb_flags (shvarFile *ifcfg, const char *tag, NMSettingDcbFlags flags)
{
- char *prop;
+ char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")];
- prop = g_strdup_printf ("DCB_%s_ENABLE", tag);
+ nm_sprintf_buf (prop, "DCB_%s_ENABLE", tag);
svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ENABLE) ? "yes" : NULL, FALSE);
- g_free (prop);
- prop = g_strdup_printf ("DCB_%s_ADVERTISE", tag);
+ nm_sprintf_buf (prop, "DCB_%s_ADVERTISE", tag);
svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_ADVERTISE) ? "yes" : NULL, FALSE);
- g_free (prop);
- prop = g_strdup_printf ("DCB_%s_WILLING", tag);
+ nm_sprintf_buf (prop, "DCB_%s_WILLING", tag);
svSetValue (ifcfg, prop, (flags & NM_SETTING_DCB_FLAG_WILLING) ? "yes" : NULL, FALSE);
- g_free (prop);
}
static void
@@ -1637,16 +1633,15 @@ write_dcb_app (shvarFile *ifcfg,
NMSettingDcbFlags flags,
gint priority)
{
- char *prop, *tmp = NULL;
+ char prop[NM_STRLEN ("DCB_xxxxxxxxxxxxxxxxxxxxxxx_yyyyyyyyyyyyyyyyyyyy")];
write_dcb_flags (ifcfg, tag, flags);
+ nm_sprintf_buf (prop, "DCB_%s_PRIORITY", tag);
if ((flags & NM_SETTING_DCB_FLAG_ENABLE) && (priority >= 0))
- tmp = g_strdup_printf ("%d", priority);
- prop = g_strdup_printf ("DCB_%s_PRIORITY", tag);
- svSetValue (ifcfg, prop, tmp, FALSE);
- g_free (prop);
- g_free (tmp);
+ svSetValueInt64 (ifcfg, prop, priority);
+ else
+ svUnsetValue (ifcfg, prop);
}
typedef gboolean (*DcbGetBoolFunc) (NMSettingDcb *, guint);
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index df7849bfb5..32601384b4 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -441,10 +441,11 @@ svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verba
void
svSetValueInt64 (shvarFile *s, const char *key, gint64 value)
{
- gs_free char *v = NULL;
+ char buf[NM_DECIMAL_STR_MAX (value)];
- v = g_strdup_printf ("%"G_GINT64_FORMAT, value);
- svSetValueFull (s, key, v, TRUE);
+ svSetValueFull (s, key,
+ nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value),
+ TRUE);
}
void