X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fcore%2Fstore.c;h=e9e0979e72e4db10ec99d34f2596f178c5d19317;hp=be307c5829adb49f212a478f13cb4d34c82983e4;hb=ddb7ffc175e49abfa69c82777b88d73e1f1103fb;hpb=e2d94a3eba924a4fd3c79d1ed99a57ae8bfb9282 diff --git a/src/core/store.c b/src/core/store.c index be307c5..e9e0979 100644 --- a/src/core/store.c +++ b/src/core/store.c @@ -27,8 +27,8 @@ #include "sysdb.h" #include "core/store.h" -#include "core/error.h" #include "core/plugin.h" +#include "utils/error.h" #include "utils/llist.h" #include @@ -418,11 +418,15 @@ sdb_store_attribute(const char *hostname, const char *key, const char *value, /* stored object = */ SDB_ATTRIBUTE, key, last_update, &updated_attr); - SDB_ATTR(updated_attr)->value = strdup(value); - if (! SDB_ATTR(updated_attr)->value) { - sdb_object_deref(SDB_OBJ(updated_attr)); - status = -1; + if (status >= 0) { + assert(updated_attr); + SDB_ATTR(updated_attr)->value = strdup(value); + if (! SDB_ATTR(updated_attr)->value) { + sdb_object_deref(SDB_OBJ(updated_attr)); + status = -1; + } } + pthread_rwlock_unlock(&obj_lock); return status; } /* sdb_store_attribute */ @@ -487,9 +491,11 @@ sdb_store_tojson(sdb_strbuf_t *buf) char errbuf[1024]; sdb_log(SDB_LOG_ERR, "store: Failed to retrieve attributes: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); - break; + sdb_strbuf_append(buf, "{\"error\": \"failed to retrieve " + "attributes: %s\"}", errbuf); } + /* has_next returns false if the iterator is NULL */ while (sdb_llist_iter_has_next(attr_iter)) { sdb_attribute_t *attr = SDB_ATTR(sdb_llist_iter_get_next(attr_iter)); assert(attr); @@ -512,7 +518,8 @@ sdb_store_tojson(sdb_strbuf_t *buf) char errbuf[1024]; sdb_log(SDB_LOG_ERR, "store: Failed to retrieve services: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); - break; + sdb_strbuf_append(buf, "{\"error\": \"failed to retrieve " + "services: %s\"}", errbuf); } while (sdb_llist_iter_has_next(svc_iter)) { @@ -530,7 +537,7 @@ sdb_store_tojson(sdb_strbuf_t *buf) } sdb_llist_iter_destroy(svc_iter); - sdb_strbuf_append(buf, "]}"); + sdb_strbuf_append(buf, "]},"); } sdb_strbuf_append(buf, "]}");