From c800b2c5fbea60370bffa8c9a45008481861e851 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Mon, 27 Sep 2010 22:47:44 +0300 Subject: [PATCH] fix conf_set() --- proxies/conf_proxy.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/proxies/conf_proxy.c b/proxies/conf_proxy.c index fd909136..278520d1 100644 --- a/proxies/conf_proxy.c +++ b/proxies/conf_proxy.c @@ -66,7 +66,7 @@ static struct pair * find_pair(const char * key) return NULL; } -static void on_value_changed(struct pair * pair_ptr, const char * value, uint64_t version) +static void on_value_changed(struct pair * pair_ptr, const char * value, uint64_t version, bool announce) { size_t len; @@ -89,7 +89,7 @@ static void on_value_changed(struct pair * pair_ptr, const char * value, uint64_ } } - if (pair_ptr->callback != NULL) + if (announce && pair_ptr->callback != NULL) { pair_ptr->callback(pair_ptr->callback_context, pair_ptr->key, value); } @@ -156,7 +156,7 @@ static void on_conf_changed(void * context, DBusMessage * message_ptr) return; } - on_value_changed(pair_ptr, value, version); + on_value_changed(pair_ptr, value, version, true); } /* this must be static because it is referenced by the @@ -278,18 +278,22 @@ bool conf_set(const char * key, const char * value) uint64_t version; struct pair * pair_ptr; + pair_ptr = find_pair(key); + if (pair_ptr != NULL && pair_ptr->value != NULL && strcmp(value, pair_ptr->value) == 0) + { + return true; /* not changed */ + } + if (!dbus_call(CONF_SERVICE_NAME, CONF_OBJECT_PATH, CONF_IFACE, "set", "ss", &key, &value, "t", &version)) { log_error("conf::set() failed."); return false; } - /* this is not strictly required because if there is a registered pair, - we should catch the "changed" signal for it */ - pair_ptr = find_pair(key); - if (pair_ptr != NULL && strcmp(value, pair_ptr->value) == 0) + if (pair_ptr != NULL && pair_ptr->value != NULL && strcmp(value, pair_ptr->value) != 0) { - on_value_changed(pair_ptr, value, version); + /* record the new version and dont call the callback */ + on_value_changed(pair_ptr, value, version, false); } return true;