Code

Use the sdb_error* function throughout the project.
[sysdb.git] / src / core / store.c
index e5cd886aae31be9bb1d35be92e9f42b7d729e4b5..a0bbf55ce39173c536c4758fce4efefcfeca81cf 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "sysdb.h"
 #include "core/store.h"
+#include "utils/error.h"
 #include "utils/llist.h"
 #include "utils/string.h"
 
@@ -197,33 +198,33 @@ sdb_host_create(const char *name)
 sdb_host_t *
 sdb_host_clone(const sdb_host_t *host)
 {
-       sdb_host_t *clone;
+       sdb_host_t *new;
 
-       clone = sdb_host_create(host->host_name);
-       if (! clone)
+       new = sdb_host_create(host->host_name);
+       if (! new)
                return NULL;
 
        /* make sure these are initialized; else sdb_object_deref() might access
         * arbitrary memory in case of an error */
-       clone->services = clone->attributes = NULL;
+       new->services = new->attributes = NULL;
 
        if (host->attributes) {
-               clone->attributes = sdb_llist_clone(host->attributes);
-               if (! clone->attributes) {
-                       sdb_object_deref(SDB_OBJ(clone));
+               new->attributes = sdb_llist_clone(host->attributes);
+               if (! new->attributes) {
+                       sdb_object_deref(SDB_OBJ(new));
                        return NULL;
                }
        }
 
-       clone->host_last_update = host->host_last_update;
+       new->host_last_update = host->host_last_update;
        if (host->services) {
-               clone->services = sdb_llist_clone(host->services);
-               if (! clone->services) {
-                       sdb_object_deref(SDB_OBJ(clone));
+               new->services = sdb_llist_clone(host->services);
+               if (! new->services) {
+                       sdb_object_deref(SDB_OBJ(new));
                        return NULL;
                }
        }
-       return clone;
+       return new;
 } /* sdb_host_clone */
 
 int
@@ -257,7 +258,7 @@ sdb_store_host(const sdb_host_t *host)
 
        if (old) {
                if (old->host_last_update > last_update) {
-                       fprintf(stderr, "store: Cannot update host '%s' - "
+                       sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update host '%s' - "
                                        "value too old (%"PRIscTIME" < %"PRIscTIME")\n",
                                        host->host_name, last_update, old->host_last_update);
                        /* don't report an error; the host may be updated by multiple
@@ -272,8 +273,8 @@ sdb_store_host(const sdb_host_t *host)
                sdb_host_t *new = sdb_host_clone(host);
                if (! new) {
                        char errbuf[1024];
-                       fprintf(stderr, "store: Failed to clone host object: %s\n",
-                                       sdb_strerror(errno, errbuf, sizeof(errbuf)));
+                       sdb_error_set(SDB_LOG_ERR, "store: Failed to clone host object: "
+                                       "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
                }
@@ -281,7 +282,7 @@ sdb_store_host(const sdb_host_t *host)
                if (! new->attributes) {
                        if (! (new->attributes = sdb_llist_create())) {
                                char errbuf[1024];
-                               fprintf(stderr, "store: Failed to initialize "
+                               sdb_error_set(SDB_LOG_ERR, "store: Failed to initialize "
                                                "host object '%s': %s\n", host->host_name,
                                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                sdb_object_deref(SDB_OBJ(new));
@@ -293,7 +294,7 @@ sdb_store_host(const sdb_host_t *host)
                if (! new->services) {
                        if (! (new->services = sdb_llist_create())) {
                                char errbuf[1024];
-                               fprintf(stderr, "store: Failed to initialize "
+                               sdb_error_set(SDB_LOG_ERR, "store: Failed to initialize "
                                                "host object '%s': %s\n", host->host_name,
                                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                sdb_object_deref(SDB_OBJ(new));
@@ -350,15 +351,15 @@ sdb_attribute_create(const char *hostname,
 sdb_attribute_t *
 sdb_attribute_clone(const sdb_attribute_t *attr)
 {
-       sdb_attribute_t *clone;
+       sdb_attribute_t *new;
 
-       clone = sdb_attribute_create(attr->hostname,
+       new = sdb_attribute_create(attr->hostname,
                        attr->attr_name, attr->attr_value);
-       if (! clone)
+       if (! new)
                return NULL;
 
-       clone->attr_last_update = attr->attr_last_update;
-       return clone;
+       new->attr_last_update = attr->attr_last_update;
+       return new;
 } /* sdb_attribute_clone */
 
 int
@@ -401,8 +402,8 @@ sdb_store_attribute(const sdb_attribute_t *attr)
 
        if (old) {
                if (old->host_last_update > last_update) {
-                       fprintf(stderr, "store: Cannot update attribute '%s/%s' - "
-                                       "value too old (%"PRIscTIME" < %"PRIscTIME")\n",
+                       sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update attribute "
+                                       "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")\n",
                                        attr->hostname, attr->attr_name, last_update,
                                        old->host_last_update);
                        status = 1;
@@ -415,8 +416,8 @@ sdb_store_attribute(const sdb_attribute_t *attr)
                sdb_attribute_t *new = sdb_attribute_clone(attr);
                if (! new) {
                        char errbuf[1024];
-                       fprintf(stderr, "store: Failed to clone attribute object: %s\n",
-                                       sdb_strerror(errno, errbuf, sizeof(errbuf)));
+                       sdb_error_set(SDB_LOG_ERR, "store: Failed to clone attribute "
+                                       "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
                }
@@ -450,14 +451,14 @@ sdb_service_create(const char *hostname, const char *name)
 sdb_service_t *
 sdb_service_clone(const sdb_service_t *svc)
 {
-       sdb_service_t *clone;
+       sdb_service_t *new;
 
-       clone = sdb_service_create(svc->hostname, svc->svc_name);
-       if (! clone)
+       new = sdb_service_create(svc->hostname, svc->svc_name);
+       if (! new)
                return NULL;
 
-       clone->svc_last_update = svc->svc_last_update;
-       return clone;
+       new->svc_last_update = svc->svc_last_update;
+       return new;
 } /* sdb_service_clone */
 
 int
@@ -499,8 +500,8 @@ sdb_store_service(const sdb_service_t *svc)
 
        if (old) {
                if (old->host_last_update > last_update) {
-                       fprintf(stderr, "store: Cannot update service '%s/%s' - "
-                                       "value too old (%"PRIscTIME" < %"PRIscTIME")\n",
+                       sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update service "
+                                       "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")\n",
                                        svc->hostname, svc->svc_name, last_update,
                                        old->host_last_update);
                        status = 1;
@@ -513,8 +514,8 @@ sdb_store_service(const sdb_service_t *svc)
                sdb_service_t *new = sdb_service_clone(svc);
                if (! new) {
                        char errbuf[1024];
-                       fprintf(stderr, "store: Failed to clone service object: %s\n",
-                                       sdb_strerror(errno, errbuf, sizeof(errbuf)));
+                       sdb_error_set(SDB_LOG_ERR, "store: Failed to clone service "
+                                       "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
                }