From 0348bc9195b423f06cee6c4d8ff0a85befcc4882 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 20 May 2015 14:07:57 +0200 Subject: [PATCH] ifcfg-rh: add svSetValueFull() to support writing empty values svSetValue() treated the empty word like %NULL. Handle empty differently from unset. --- src/settings/plugins/ifcfg-rh/shvar.c | 10 +++++++++- src/settings/plugins/ifcfg-rh/shvar.h | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index 8e174bd56b..4a5ca1d186 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -368,6 +368,14 @@ svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, gint64 m */ void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim) +{ + svSetValueFull (s, key, value && value[0] ? value : NULL, verbatim); +} + +/* Same as svSetValue() but it preserves empty @value -- contrary to + * svSetValue() for which "" effectively means to remove the value. */ +void +svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim) { gs_free char *newval_free = NULL; gs_free char *oldval = NULL; @@ -384,7 +392,7 @@ svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim) newval = svEscape (value, &newval_free); oldval = svGetValueFull (s, key, FALSE); - if (!newval || !newval[0]) { + if (!newval) { /* delete value */ if (oldval) { /* delete line */ diff --git a/src/settings/plugins/ifcfg-rh/shvar.h b/src/settings/plugins/ifcfg-rh/shvar.h index 738bce6d11..4902541b00 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.h +++ b/src/settings/plugins/ifcfg-rh/shvar.h @@ -72,6 +72,7 @@ gint64 svGetValueInt64 (shvarFile *s, const char *key, guint base, gint64 min, g * to the top of the file. */ void svSetValue (shvarFile *s, const char *key, const char *value, gboolean verbatim); +void svSetValueFull (shvarFile *s, const char *key, const char *value, gboolean verbatim); /* Write the current contents iff modified. Returns FALSE on error