aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-03-05 19:15:40 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2016-03-05 19:15:40 +0100
commit17804fa49b1f7b56ea05567202e708332f8da70c (patch)
treeb83295cff9986250629b7144f71f6f98a4295a4c
parent4b10ea7ab0dc1e59fe6957e01b4a54687572ed44 (diff)
downloadxK-17804fa49b1f7b56ea05567202e708332f8da70c.tar.gz
xK-17804fa49b1f7b56ea05567202e708332f8da70c.tar.xz
xK-17804fa49b1f7b56ea05567202e708332f8da70c.zip
degesch: fix +=/-= to null config items
-rw-r--r--degesch.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/degesch.c b/degesch.c
index 7b8494f..57b1bf7 100644
--- a/degesch.c
+++ b/degesch.c
@@ -9347,13 +9347,15 @@ static bool
handle_command_set_add
(struct config_item *item, const char *value, struct error **e)
{
- bool result = false;
struct str_vector items;
str_vector_init (&items);
- cstr_split (item->value.string.str, ",", &items);
+ if (item->type != CONFIG_ITEM_NULL)
+ cstr_split (item->value.string.str, ",", &items);
if (items.len == 1 && !*items.vector[0])
str_vector_reset (&items);
+ // FIXME: handle multiple items properly
+ bool result = false;
if (str_vector_find (&items, value) != -1)
error_set (e, "already present in the array: %s", value);
else
@@ -9370,13 +9372,15 @@ static bool
handle_command_set_remove
(struct config_item *item, const char *value, struct error **e)
{
- bool result = false;
struct str_vector items;
str_vector_init (&items);
- cstr_split (item->value.string.str, ",", &items);
+ if (item->type != CONFIG_ITEM_NULL)
+ cstr_split (item->value.string.str, ",", &items);
if (items.len == 1 && !*items.vector[0])
str_vector_reset (&items);
+ // FIXME: handle multiple items properly
+ bool result = false;
ssize_t i = str_vector_find (&items, value);
if (i == -1)
error_set (e, "not present in the array: %s", value);
@@ -9401,15 +9405,14 @@ handle_command_set_assign_item (struct app_context *ctx,
struct error *e = NULL;
if (!item->schema)
error_set (&e, "option not recognized");
- else if ((add | remove) && item->type != CONFIG_ITEM_STRING_ARRAY)
- // FIXME: it can also be null, which makes this message confusing
+ else if (!add && !remove)
+ config_item_set_from (item, config_item_clone (new_), &e);
+ else if (item->schema->type != CONFIG_ITEM_STRING_ARRAY)
error_set (&e, "not a string array");
else if (add)
handle_command_set_add (item, new_->value.string.str, &e);
else if (remove)
handle_command_set_remove (item, new_->value.string.str, &e);
- else
- config_item_set_from (item, config_item_clone (new_), &e);
if (e)
{