summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-05-25 14:41:18 +0200
committerThomas Haller <thaller@redhat.com>2017-05-30 11:10:19 +0200
commitbdd7d858f3114b6f71875efa97f2d537613c33db (patch)
tree6d4b9c245e137f49f125d0bdac16b8a63e92430f
parentefd462d946ae3382975cd73f60f33185a2cf9542 (diff)
downloadNetworkManager-bdd7d858f3114b6f71875efa97f2d537613c33db.tar.gz
ifcfg-rh: return from svSetValue*() functions whether anything changed
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.c42
-rw-r--r--src/settings/plugins/ifcfg-rh/shvar.h12
2 files changed, 30 insertions, 24 deletions
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c
index f150b65251..365e240bf4 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.c
+++ b/src/settings/plugins/ifcfg-rh/shvar.c
@@ -1097,14 +1097,15 @@ svGetValueEnum (shvarFile *s, const char *key,
/* Same as svSetValueStr() but it preserves empty @value -- contrary to
* svSetValueStr() for which "" effectively means to remove the value. */
-void
+gboolean
svSetValue (shvarFile *s, const char *key, const char *value)
{
CList *current;
shvarLine *line, *l;
+ gboolean changed = FALSE;
- g_return_if_fail (s != NULL);
- g_return_if_fail (key != NULL);
+ g_return_val_if_fail (s, FALSE);
+ g_return_val_if_fail (key, FALSE);
nm_assert (_shell_is_name (key, -1));
@@ -1116,7 +1117,7 @@ svSetValue (shvarFile *s, const char *key, const char *value)
/* if we find multiple entries for the same key, we can
* delete all but the last. */
line_free (line);
- s->modified = TRUE;
+ changed = TRUE;
}
line = l;
}
@@ -1124,18 +1125,23 @@ svSetValue (shvarFile *s, const char *key, const char *value)
if (!value) {
if (line) {
- if (nm_clear_g_free (&line->line))
- s->modified = TRUE;
+ if (nm_clear_g_free (&line->line)) {
+ changed = TRUE;
+ }
}
} else {
if (!line) {
c_list_link_tail (&s->lst_head, &line_new_build (key, value)->lst);
- s->modified = TRUE;
+ changed = TRUE;
} else {
if (line_set (line, value))
- s->modified = TRUE;
+ changed = TRUE;
}
}
+
+ if (changed)
+ s->modified = TRUE;
+ return changed;
}
/* Set the variable <key> equal to the value <value>.
@@ -1143,39 +1149,39 @@ svSetValue (shvarFile *s, const char *key, const char *value)
* the key=value pair after that line. Otherwise, append the pair
* to the bottom of the file.
*/
-void
+gboolean
svSetValueStr (shvarFile *s, const char *key, const char *value)
{
- svSetValue (s, key, value && value[0] ? value : NULL);
+ return svSetValue (s, key, value && value[0] ? value : NULL);
}
-void
+gboolean
svSetValueInt64 (shvarFile *s, const char *key, gint64 value)
{
char buf[NM_DECIMAL_STR_MAX (value)];
- svSetValue (s, key, nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value));
+ return svSetValue (s, key, nm_sprintf_buf (buf, "%"G_GINT64_FORMAT, value));
}
-void
+gboolean
svSetValueBoolean (shvarFile *s, const char *key, gboolean value)
{
- svSetValue (s, key, value ? "yes" : "no");
+ return svSetValue (s, key, value ? "yes" : "no");
}
-void
+gboolean
svSetValueEnum (shvarFile *s, const char *key, GType gtype, int value)
{
gs_free char *v = NULL;
v = _nm_utils_enum_to_str_full (gtype, value, " ");
- svSetValueStr (s, key, v);
+ return svSetValueStr (s, key, v);
}
-void
+gboolean
svUnsetValue (shvarFile *s, const char *key)
{
- svSetValue (s, key, NULL);
+ return svSetValue (s, key, NULL);
}
void
diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h
index 62b07c2f57..e9519d287b 100644
--- a/src/settings/plugins/ifcfg-rh/shvar.h
+++ b/src/settings/plugins/ifcfg-rh/shvar.h
@@ -75,13 +75,13 @@ gboolean svGetValueEnum (shvarFile *s, const char *key,
* the key=value pair after that line. Otherwise, prepend the pair
* to the top of the file.
*/
-void svSetValue (shvarFile *s, const char *key, const char *value);
-void svSetValueStr (shvarFile *s, const char *key, const char *value);
-void svSetValueBoolean (shvarFile *s, const char *key, gboolean value);
-void svSetValueInt64 (shvarFile *s, const char *key, gint64 value);
-void svSetValueEnum (shvarFile *s, const char *key, GType gtype, int value);
+gboolean svSetValue (shvarFile *s, const char *key, const char *value);
+gboolean svSetValueStr (shvarFile *s, const char *key, const char *value);
+gboolean svSetValueBoolean (shvarFile *s, const char *key, gboolean value);
+gboolean svSetValueInt64 (shvarFile *s, const char *key, gint64 value);
+gboolean svSetValueEnum (shvarFile *s, const char *key, GType gtype, int value);
-void svUnsetValue (shvarFile *s, const char *key);
+gboolean svUnsetValue (shvarFile *s, const char *key);
void svUnsetValuesWithPrefix (shvarFile *s, const char *prefix);