Code

Renamed error recording / logging functions.
authorSebastian Harl <sh@tokkee.org>
Sun, 10 Mar 2013 21:02:35 +0000 (22:02 +0100)
committerSebastian Harl <sh@tokkee.org>
Sun, 10 Mar 2013 21:02:35 +0000 (22:02 +0100)
sdb_error_set() now is sdb_log(); the sdb_error_start(), _append(), _finish()
triple is now called sdb_error_set(), _append(), _log(). These names better
describe what's actually going on.

src/backend/collectd.c
src/backend/mk-livestatus.c
src/backend/puppet-storeconfigs.c
src/core/plugin.c
src/core/store.c
src/daemon/config.c
src/daemon/sysdbd.c
src/include/utils/error.h
src/utils/dbi.c
src/utils/error.c
src/utils/unixsock.c

index 2a834f51982ca1248763674cecb34c41370215ac..312d7acf553d79f93d982704d64df177df193b7a 100644 (file)
@@ -76,14 +76,14 @@ sdb_collectd_add_host(const char *hostname, sdb_time_t last_update)
        status = sdb_store_host(&host);
 
        if (status < 0) {
        status = sdb_store_host(&host);
 
        if (status < 0) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to store/update "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to store/update "
                                "host '%s'.\n", name);
                return -1;
        }
        else if (status > 0) /* value too old */
                return 0;
 
                                "host '%s'.\n", name);
                return -1;
        }
        else if (status > 0) /* value too old */
                return 0;
 
-       sdb_error_set(SDB_LOG_DEBUG, "collectd backend: Added/updated host '%s' "
+       sdb_log(SDB_LOG_DEBUG, "collectd backend: Added/updated host '%s' "
                        "(last update timestamp = %"PRIscTIME").\n",
                        name, last_update);
        return 0;
                        "(last update timestamp = %"PRIscTIME").\n",
                        name, last_update);
        return 0;
@@ -108,7 +108,7 @@ sdb_collectd_add_svc(const char *hostname, const char *plugin,
 
        status = sdb_store_service(&svc);
        if (status < 0) {
 
        status = sdb_store_service(&svc);
        if (status < 0) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to store/update "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to store/update "
                                "service '%s/%s'.\n", host, name);
                return -1;
        }
                                "service '%s/%s'.\n", host, name);
                return -1;
        }
@@ -148,7 +148,7 @@ sdb_collectd_get_data(sdb_unixsock_client_t __attribute__((unused)) *client,
 
        if (! state->current_host) {
                char errbuf[1024];
 
        if (! state->current_host) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to allocate "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to allocate "
                                "string buffer: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
                                "string buffer: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
@@ -171,7 +171,7 @@ sdb_collectd_get_data(sdb_unixsock_client_t __attribute__((unused)) *client,
        /* new host */
        sdb_collectd_add_host(hostname, last_update);
 
        /* new host */
        sdb_collectd_add_host(hostname, last_update);
 
-       sdb_error_set(SDB_LOG_DEBUG, "collectd backend: Added/updated "
+       sdb_log(SDB_LOG_DEBUG, "collectd backend: Added/updated "
                        "%i service%s (%i failed) for host '%s'.\n",
                        state->svc_updated, state->svc_updated == 1 ? "" : "s",
                        state->svc_failed, state->current_host);
                        "%i service%s (%i failed) for host '%s'.\n",
                        state->svc_updated, state->svc_updated == 1 ? "" : "s",
                        state->svc_failed, state->current_host);
@@ -197,12 +197,12 @@ sdb_collectd_init(sdb_object_t *user_data)
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_unixsock_client_connect(client)) {
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_unixsock_client_connect(client)) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: "
+               sdb_log(SDB_LOG_ERR, "collectd backend: "
                                "Failed to connect to collectd.\n");
                return -1;
        }
 
                                "Failed to connect to collectd.\n");
                return -1;
        }
 
-       sdb_error_set(SDB_LOG_INFO, "collectd backend: Successfully "
+       sdb_log(SDB_LOG_INFO, "collectd backend: Successfully "
                        "connected to collectd @ %s.\n",
                        sdb_unixsock_client_path(client));
        return 0;
                        "connected to collectd @ %s.\n",
                        sdb_unixsock_client_path(client));
        return 0;
@@ -236,7 +236,7 @@ sdb_collectd_collect(sdb_object_t *user_data)
        client = SDB_OBJ_WRAPPER(user_data)->data;
 
        if (sdb_unixsock_client_send(client, "LISTVAL") <= 0) {
        client = SDB_OBJ_WRAPPER(user_data)->data;
 
        if (sdb_unixsock_client_send(client, "LISTVAL") <= 0) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to send LISTVAL "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to send LISTVAL "
                                "command to collectd @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
                                "command to collectd @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
@@ -244,7 +244,7 @@ sdb_collectd_collect(sdb_object_t *user_data)
 
        line = sdb_unixsock_client_recv(client, buffer, sizeof(buffer));
        if (! line) {
 
        line = sdb_unixsock_client_recv(client, buffer, sizeof(buffer));
        if (! line) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to read status "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to read status "
                                "of LISTVAL command from collectd @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
                                "of LISTVAL command from collectd @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
@@ -259,14 +259,14 @@ sdb_collectd_collect(sdb_object_t *user_data)
        errno = 0;
        count = strtol(line, &endptr, /* base */ 0);
        if (errno || (line == endptr)) {
        errno = 0;
        count = strtol(line, &endptr, /* base */ 0);
        if (errno || (line == endptr)) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to parse status "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to parse status "
                                "of LISTVAL command from collectd @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
        }
 
        if (count < 0) {
                                "of LISTVAL command from collectd @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
        }
 
        if (count < 0) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to get value "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to get value "
                                "list from collectd @ %s: %s\n",
                                sdb_unixsock_client_path(client),
                                msg ? msg : line);
                                "list from collectd @ %s: %s\n",
                                sdb_unixsock_client_path(client),
                                msg ? msg : line);
@@ -278,14 +278,14 @@ sdb_collectd_collect(sdb_object_t *user_data)
                                /* column count = */ 4,
                                SDB_TYPE_DATETIME, SDB_TYPE_STRING,
                                SDB_TYPE_STRING, SDB_TYPE_STRING)) {
                                /* column count = */ 4,
                                SDB_TYPE_DATETIME, SDB_TYPE_STRING,
                                SDB_TYPE_STRING, SDB_TYPE_STRING)) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to read response "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to read response "
                                "from collectd @ %s.\n", sdb_unixsock_client_path(client));
                return -1;
        }
 
        if (state.current_host) {
                sdb_collectd_add_host(state.current_host, state.current_timestamp);
                                "from collectd @ %s.\n", sdb_unixsock_client_path(client));
                return -1;
        }
 
        if (state.current_host) {
                sdb_collectd_add_host(state.current_host, state.current_timestamp);
-               sdb_error_set(SDB_LOG_DEBUG, "collectd backend: Added/updated "
+               sdb_log(SDB_LOG_DEBUG, "collectd backend: Added/updated "
                                "%i service%s (%i failed) for host '%s'.\n",
                                state.svc_updated, state.svc_updated == 1 ? "" : "s",
                                state.svc_failed, state.current_host);
                                "%i service%s (%i failed) for host '%s'.\n",
                                state.svc_updated, state.svc_updated == 1 ? "" : "s",
                                state.svc_failed, state.current_host);
@@ -307,7 +307,7 @@ sdb_collectd_config_instance(oconfig_item_t *ci)
        int i;
 
        if (oconfig_get_string(ci, &name)) {
        int i;
 
        if (oconfig_get_string(ci, &name)) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Instance requires a "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Instance requires a "
                                "single string argument\n\tUsage: <Instance NAME>\n");
                return -1;
        }
                                "single string argument\n\tUsage: <Instance NAME>\n");
                return -1;
        }
@@ -318,13 +318,13 @@ sdb_collectd_config_instance(oconfig_item_t *ci)
                if (! strcasecmp(child->key, "Socket"))
                        oconfig_get_string(child, &socket_path);
                else
                if (! strcasecmp(child->key, "Socket"))
                        oconfig_get_string(child, &socket_path);
                else
-                       sdb_error_set(SDB_LOG_WARNING, "collectd backend: Ignoring "
+                       sdb_log(SDB_LOG_WARNING, "collectd backend: Ignoring "
                                        "unknown config option '%s' inside <Instance %s>.\n",
                                        child->key, name);
        }
 
        if (! socket_path) {
                                        "unknown config option '%s' inside <Instance %s>.\n",
                                        child->key, name);
        }
 
        if (! socket_path) {
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Instance '%s' missing "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Instance '%s' missing "
                                "the 'Socket' option.\n", name);
                return -1;
        }
                                "the 'Socket' option.\n", name);
                return -1;
        }
@@ -335,7 +335,7 @@ sdb_collectd_config_instance(oconfig_item_t *ci)
        client = sdb_unixsock_client_create(socket_path);
        if (! client) {
                char errbuf[1024];
        client = sdb_unixsock_client_create(socket_path);
        if (! client) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to create "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to create "
                                "unixsock client: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
                                "unixsock client: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
@@ -345,7 +345,7 @@ sdb_collectd_config_instance(oconfig_item_t *ci)
                        (void (*)(void *))sdb_unixsock_client_destroy);
        if (! user_data) {
                sdb_unixsock_client_destroy(client);
                        (void (*)(void *))sdb_unixsock_client_destroy);
        if (! user_data) {
                sdb_unixsock_client_destroy(client);
-               sdb_error_set(SDB_LOG_ERR, "collectd backend: Failed to allocate "
+               sdb_log(SDB_LOG_ERR, "collectd backend: Failed to allocate "
                                "sdb_object_t\n");
                return -1;
        }
                                "sdb_object_t\n");
                return -1;
        }
@@ -372,7 +372,7 @@ sdb_collectd_config(oconfig_item_t *ci)
                if (! strcasecmp(child->key, "Instance"))
                        sdb_collectd_config_instance(child);
                else
                if (! strcasecmp(child->key, "Instance"))
                        sdb_collectd_config_instance(child);
                else
-                       sdb_error_set(SDB_LOG_WARNING, "collectd backend: Ignoring "
+                       sdb_log(SDB_LOG_WARNING, "collectd backend: Ignoring "
                                        "unknown config option '%s'.\n", child->key);
        }
        return 0;
                                        "unknown config option '%s'.\n", child->key);
        }
        return 0;
index f65e7589437b5073770020424de0c01f86ad5146..5d8c37735e25cf30cf2e4772ca6757e84e1fe8d5 100644 (file)
@@ -73,7 +73,7 @@ sdb_livestatus_get_host(sdb_unixsock_client_t __attribute__((unused)) *client,
        status = sdb_store_host(&host);
 
        if (status < 0) {
        status = sdb_store_host(&host);
 
        if (status < 0) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
                                "store/update host '%s'.\n", hostname);
                free(hostname);
                return -1;
                                "store/update host '%s'.\n", hostname);
                free(hostname);
                return -1;
@@ -81,7 +81,7 @@ sdb_livestatus_get_host(sdb_unixsock_client_t __attribute__((unused)) *client,
        else if (status > 0) /* value too old */
                return 0;
 
        else if (status > 0) /* value too old */
                return 0;
 
-       sdb_error_set(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated "
+       sdb_log(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated "
                        "host '%s' (last update timestamp = %"PRIscTIME").\n",
                        hostname, timestamp);
        free(hostname);
                        "host '%s' (last update timestamp = %"PRIscTIME").\n",
                        hostname, timestamp);
        free(hostname);
@@ -117,7 +117,7 @@ sdb_livestatus_get_svc(sdb_unixsock_client_t __attribute__((unused)) *client,
        status = sdb_store_service(&svc);
 
        if (status < 0) {
        status = sdb_store_service(&svc);
 
        if (status < 0) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
                                "store/update service '%s / %s'.\n", hostname, svcname);
                free(hostname);
                free(svcname);
                                "store/update service '%s / %s'.\n", hostname, svcname);
                free(hostname);
                free(svcname);
@@ -126,7 +126,7 @@ sdb_livestatus_get_svc(sdb_unixsock_client_t __attribute__((unused)) *client,
        else if (status > 0) /* value too old */
                return 0;
 
        else if (status > 0) /* value too old */
                return 0;
 
-       sdb_error_set(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated "
+       sdb_log(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated "
                        "service '%s / %s' (last update timestamp = %"PRIscTIME").\n",
                        hostname, svcname, timestamp);
        free(hostname);
                        "service '%s / %s' (last update timestamp = %"PRIscTIME").\n",
                        hostname, svcname, timestamp);
        free(hostname);
@@ -148,13 +148,13 @@ sdb_livestatus_init(sdb_object_t *user_data)
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_unixsock_client_connect(client)) {
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_unixsock_client_connect(client)) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: "
                                "Failed to connect to livestatus @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
        }
 
                                "Failed to connect to livestatus @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
        }
 
-       sdb_error_set(SDB_LOG_INFO, "MK Livestatus backend: Successfully "
+       sdb_log(SDB_LOG_INFO, "MK Livestatus backend: Successfully "
                        "connected to livestatus @ %s.\n",
                        sdb_unixsock_client_path(client));
        return 0;
                        "connected to livestatus @ %s.\n",
                        sdb_unixsock_client_path(client));
        return 0;
@@ -175,7 +175,7 @@ sdb_livestatus_collect(sdb_object_t *user_data)
        status = sdb_unixsock_client_send(client, "GET hosts\r\n"
                        "Columns: name last_check");
        if (status <= 0) {
        status = sdb_unixsock_client_send(client, "GET hosts\r\n"
                        "Columns: name last_check");
        if (status <= 0) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to send "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to send "
                                "'GET hosts' command to livestatus @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
                                "'GET hosts' command to livestatus @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
@@ -186,7 +186,7 @@ sdb_livestatus_collect(sdb_object_t *user_data)
        if (sdb_unixsock_client_process_lines(client, sdb_livestatus_get_host,
                                /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";",
                                /* column count */ 2, SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
        if (sdb_unixsock_client_process_lines(client, sdb_livestatus_get_host,
                                /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";",
                                /* column count */ 2, SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
                                "response from livestatus @ %s while reading hosts.\n",
                                sdb_unixsock_client_path(client));
                return -1;
                                "response from livestatus @ %s while reading hosts.\n",
                                sdb_unixsock_client_path(client));
                return -1;
@@ -195,7 +195,7 @@ sdb_livestatus_collect(sdb_object_t *user_data)
        if ((! sdb_unixsock_client_eof(client))
                        || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
        if ((! sdb_unixsock_client_eof(client))
                        || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
                                "host from livestatus @ %s: %s\n",
                                sdb_unixsock_client_path(client),
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                "host from livestatus @ %s: %s\n",
                                sdb_unixsock_client_path(client),
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
@@ -205,7 +205,7 @@ sdb_livestatus_collect(sdb_object_t *user_data)
        status = sdb_unixsock_client_send(client, "GET services\r\n"
                        "Columns: host_name description last_check");
        if (status <= 0) {
        status = sdb_unixsock_client_send(client, "GET services\r\n"
                        "Columns: host_name description last_check");
        if (status <= 0) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to send "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to send "
                                "'GET services' command to livestatus @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
                                "'GET services' command to livestatus @ %s.\n",
                                sdb_unixsock_client_path(client));
                return -1;
@@ -217,7 +217,7 @@ sdb_livestatus_collect(sdb_object_t *user_data)
                                /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";",
                                /* column count */ 3, SDB_TYPE_STRING, SDB_TYPE_STRING,
                                SDB_TYPE_DATETIME)) {
                                /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";",
                                /* column count */ 3, SDB_TYPE_STRING, SDB_TYPE_STRING,
                                SDB_TYPE_DATETIME)) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
                                "response from livestatus @ %s while reading services.\n",
                                sdb_unixsock_client_path(client));
                return -1;
                                "response from livestatus @ %s while reading services.\n",
                                sdb_unixsock_client_path(client));
                return -1;
@@ -226,7 +226,7 @@ sdb_livestatus_collect(sdb_object_t *user_data)
        if ((! sdb_unixsock_client_eof(client))
                        || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
        if ((! sdb_unixsock_client_eof(client))
                        || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read "
                                "services from livestatus @ %s: %s\n",
                                sdb_unixsock_client_path(client),
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                "services from livestatus @ %s: %s\n",
                                sdb_unixsock_client_path(client),
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
@@ -249,7 +249,7 @@ sdb_livestatus_config_instance(oconfig_item_t *ci)
        int i;
 
        if (oconfig_get_string(ci, &name)) {
        int i;
 
        if (oconfig_get_string(ci, &name)) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Instance requires "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Instance requires "
                                "a single string argument\n\tUsage: <Instance NAME>\n");
                return -1;
        }
                                "a single string argument\n\tUsage: <Instance NAME>\n");
                return -1;
        }
@@ -260,13 +260,13 @@ sdb_livestatus_config_instance(oconfig_item_t *ci)
                if (! strcasecmp(child->key, "Socket"))
                        oconfig_get_string(child, &socket_path);
                else
                if (! strcasecmp(child->key, "Socket"))
                        oconfig_get_string(child, &socket_path);
                else
-                       sdb_error_set(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring "
+                       sdb_log(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring "
                                        "unknown config option '%s' inside <Instance %s>.\n",
                                        child->key, name);
        }
 
        if (! socket_path) {
                                        "unknown config option '%s' inside <Instance %s>.\n",
                                        child->key, name);
        }
 
        if (! socket_path) {
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Instance '%s' "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Instance '%s' "
                                "missing the 'Socket' option.\n", name);
                return -1;
        }
                                "missing the 'Socket' option.\n", name);
                return -1;
        }
@@ -277,7 +277,7 @@ sdb_livestatus_config_instance(oconfig_item_t *ci)
        client = sdb_unixsock_client_create(socket_path);
        if (! client) {
                char errbuf[1024];
        client = sdb_unixsock_client_create(socket_path);
        if (! client) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to create "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to create "
                                "unixsock client: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
                                "unixsock client: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
@@ -287,7 +287,7 @@ sdb_livestatus_config_instance(oconfig_item_t *ci)
                        (void (*)(void *))sdb_unixsock_client_destroy);
        if (! user_data) {
                sdb_unixsock_client_destroy(client);
                        (void (*)(void *))sdb_unixsock_client_destroy);
        if (! user_data) {
                sdb_unixsock_client_destroy(client);
-               sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
+               sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
                                "allocate sdb_object_t\n");
                return -1;
        }
                                "allocate sdb_object_t\n");
                return -1;
        }
@@ -312,7 +312,7 @@ sdb_livestatus_config(oconfig_item_t *ci)
                if (! strcasecmp(child->key, "Instance"))
                        sdb_livestatus_config_instance(child);
                else
                if (! strcasecmp(child->key, "Instance"))
                        sdb_livestatus_config_instance(child);
                else
-                       sdb_error_set(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring "
+                       sdb_log(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring "
                                        "unknown config option '%s'.\n", child->key);
        }
        return 0;
                                        "unknown config option '%s'.\n", child->key);
        }
        return 0;
index 4c92c151770c53a34b44b147df793658c3343752..d55b76477d33bfbc2aadf7f3ad2ff938eebeb44f 100644 (file)
@@ -67,13 +67,13 @@ sdb_puppet_stcfg_get_hosts(sdb_dbi_client_t __attribute__((unused)) *client,
        status = sdb_store_host(&host);
 
        if (status < 0) {
        status = sdb_store_host(&host);
 
        if (status < 0) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
                                "store/update host '%s'.\n", host.host_name);
                free(host.host_name);
                return -1;
        }
        else if (! status)
                                "store/update host '%s'.\n", host.host_name);
                free(host.host_name);
                return -1;
        }
        else if (! status)
-               sdb_error_set(SDB_LOG_DEBUG, "puppet storeconfigs backend: "
+               sdb_log(SDB_LOG_DEBUG, "puppet storeconfigs backend: "
                                "Added/updated host '%s' (last update timestamp = "
                                "%"PRIscTIME").\n", host.host_name, host.host_last_update);
        free(host.host_name);
                                "Added/updated host '%s' (last update timestamp = "
                                "%"PRIscTIME").\n", host.host_name, host.host_last_update);
        free(host.host_name);
@@ -103,7 +103,7 @@ sdb_puppet_stcfg_get_attrs(sdb_dbi_client_t __attribute__((unused)) *client,
        status = sdb_store_attribute(&attr);
 
        if (status < 0) {
        status = sdb_store_attribute(&attr);
 
        if (status < 0) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
                                "store/update host attribute '%s' for host '%s'.\n",
                                attr.attr_name, attr.hostname);
                free(attr.hostname);
                                "store/update host attribute '%s' for host '%s'.\n",
                                attr.attr_name, attr.hostname);
                free(attr.hostname);
@@ -132,12 +132,12 @@ sdb_puppet_stcfg_init(sdb_object_t *user_data)
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_dbi_client_connect(client)) {
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_dbi_client_connect(client)) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                "Failed to connect to the storeconfigs DB.\n");
                return -1;
        }
 
                                "Failed to connect to the storeconfigs DB.\n");
                return -1;
        }
 
-       sdb_error_set(SDB_LOG_INFO, "puppet storeconfigs backend: Successfully "
+       sdb_log(SDB_LOG_INFO, "puppet storeconfigs backend: Successfully "
                        "connected to the storeconfigs DB.\n");
        return 0;
 } /* sdb_puppet_stcfg_init */
                        "connected to the storeconfigs DB.\n");
        return 0;
 } /* sdb_puppet_stcfg_init */
@@ -152,7 +152,7 @@ sdb_puppet_stcfg_collect(sdb_object_t *user_data)
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_dbi_client_check_conn(client)) {
 
        client = SDB_OBJ_WRAPPER(user_data)->data;
        if (sdb_dbi_client_check_conn(client)) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                "Connection to storeconfigs DB failed.\n");
                return -1;
        }
                                "Connection to storeconfigs DB failed.\n");
                return -1;
        }
@@ -160,7 +160,7 @@ sdb_puppet_stcfg_collect(sdb_object_t *user_data)
        if (sdb_dbi_exec_query(client, "SELECT name, updated_at FROM hosts;",
                                sdb_puppet_stcfg_get_hosts, NULL, /* #columns = */ 2,
                                /* col types = */ SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
        if (sdb_dbi_exec_query(client, "SELECT name, updated_at FROM hosts;",
                                sdb_puppet_stcfg_get_hosts, NULL, /* #columns = */ 2,
                                /* col types = */ SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
                                "retrieve hosts from the storeconfigs DB.\n");
                return -1;
        }
                                "retrieve hosts from the storeconfigs DB.\n");
                return -1;
        }
@@ -178,7 +178,7 @@ sdb_puppet_stcfg_collect(sdb_object_t *user_data)
                                sdb_puppet_stcfg_get_attrs, NULL, /* #columns = */ 4,
                                /* col types = */ SDB_TYPE_STRING, SDB_TYPE_STRING,
                                SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
                                sdb_puppet_stcfg_get_attrs, NULL, /* #columns = */ 4,
                                /* col types = */ SDB_TYPE_STRING, SDB_TYPE_STRING,
                                SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: Failed to "
                                "retrieve host attributes from the storeconfigs DB.\n");
                return -1;
        }
                                "retrieve host attributes from the storeconfigs DB.\n");
                return -1;
        }
@@ -201,7 +201,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
        int i;
 
        if (oconfig_get_string(ci, &name)) {
        int i;
 
        if (oconfig_get_string(ci, &name)) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Connection "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: Connection "
                                "requires a single string argument\n"
                                "\tUsage: <Connection NAME>\n");
                return -1;
                                "requires a single string argument\n"
                                "\tUsage: <Connection NAME>\n");
                return -1;
@@ -215,7 +215,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
 
                if (! strcasecmp(child->key, "DBAdapter")) {
                        if (oconfig_get_string(child, &driver)) {
 
                if (! strcasecmp(child->key, "DBAdapter")) {
                        if (oconfig_get_string(child, &driver)) {
-                               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+                               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                                "DBAdapter requires a single string argument inside "
                                                "<Connection %s>\n\tUsage: DBAdapter NAME\n",
                                                name);
                                                "DBAdapter requires a single string argument inside "
                                                "<Connection %s>\n\tUsage: DBAdapter NAME\n",
                                                name);
@@ -224,7 +224,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
                }
                else if (! strcasecmp(child->key, "DBName")) {
                        if (oconfig_get_string(child, &database)) {
                }
                else if (! strcasecmp(child->key, "DBName")) {
                        if (oconfig_get_string(child, &database)) {
-                               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+                               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                                "DBName requires a single string argument inside "
                                                "<Connection %s>\n\tUsage: DBName NAME\n",
                                                name);
                                                "DBName requires a single string argument inside "
                                                "<Connection %s>\n\tUsage: DBName NAME\n",
                                                name);
@@ -251,7 +251,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
                        if ((child->values_num != 2)
                                        || (child->values[0].type != OCONFIG_TYPE_STRING)
                                        || (child->values[1].type != OCONFIG_TYPE_STRING)) {
                        if ((child->values_num != 2)
                                        || (child->values[0].type != OCONFIG_TYPE_STRING)
                                        || (child->values[1].type != OCONFIG_TYPE_STRING)) {
-                               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+                               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                                "DBIOption requires exactly two string arguments "
                                                "inside <Connection %s>\n"
                                                "\tUsage: DBIOption KEY VALUE\n", name);
                                                "DBIOption requires exactly two string arguments "
                                                "inside <Connection %s>\n"
                                                "\tUsage: DBIOption KEY VALUE\n", name);
@@ -263,14 +263,14 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
                        value = child->values[1].value.string;
                }
                else {
                        value = child->values[1].value.string;
                }
                else {
-                       sdb_error_set(SDB_LOG_WARNING, "puppet storeconfigs backend: "
+                       sdb_log(SDB_LOG_WARNING, "puppet storeconfigs backend: "
                                        "Ignoring unknown config option '%s' inside "
                                        "<Connection %s>.\n", child->key, name);
                        continue;
                }
 
                if (status) {
                                        "Ignoring unknown config option '%s' inside "
                                        "<Connection %s>.\n", child->key, name);
                        continue;
                }
 
                if (status) {
-                       sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: Option "
+                       sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: Option "
                                        "'%s' requires a single string argument inside "
                                        "<Connection %s>\n\tUsage: DBAdapter NAME\n",
                                        child->key, name);
                                        "'%s' requires a single string argument inside "
                                        "<Connection %s>\n\tUsage: DBAdapter NAME\n",
                                        child->key, name);
@@ -282,7 +282,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
                if (! options) {
                        if (! (options = sdb_dbi_options_create())) {
                                char errmsg[1024];
                if (! options) {
                        if (! (options = sdb_dbi_options_create())) {
                                char errmsg[1024];
-                               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+                               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                                "Failed to create DBI options object: %s\n",
                                                sdb_strerror(errno, errmsg, sizeof(errmsg)));
                                continue;
                                                "Failed to create DBI options object: %s\n",
                                                sdb_strerror(errno, errmsg, sizeof(errmsg)));
                                continue;
@@ -291,7 +291,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
 
                if (sdb_dbi_options_add(options, key, value)) {
                        char errmsg[1024];
 
                if (sdb_dbi_options_add(options, key, value)) {
                        char errmsg[1024];
-                       sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+                       sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                        "Failed to add option '%s': %s\n", key,
                                        sdb_strerror(errno, errmsg, sizeof(errmsg)));
                        continue;
                                        "Failed to add option '%s': %s\n", key,
                                        sdb_strerror(errno, errmsg, sizeof(errmsg)));
                        continue;
@@ -299,13 +299,13 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
        }
 
        if (! driver) {
        }
 
        if (! driver) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                "Connection '%s' " "missing the 'DBAdapter' option.\n",
                                name);
                return -1;
        }
        if (! database) {
                                "Connection '%s' " "missing the 'DBAdapter' option.\n",
                                name);
                return -1;
        }
        if (! database) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                "Connection '%s' missing the 'DBName' option.\n", name);
                return -1;
        }
                                "Connection '%s' missing the 'DBName' option.\n", name);
                return -1;
        }
@@ -316,7 +316,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
        client = sdb_dbi_client_create(driver, database);
        if (! client) {
                char errbuf[1024];
        client = sdb_dbi_client_create(driver, database);
        if (! client) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                "Failed to create DBI client: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
                                "Failed to create DBI client: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
@@ -328,7 +328,7 @@ sdb_puppet_stcfg_config_conn(oconfig_item_t *ci)
                        (void (*)(void *))sdb_dbi_client_destroy);
        if (! user_data) {
                sdb_dbi_client_destroy(client);
                        (void (*)(void *))sdb_dbi_client_destroy);
        if (! user_data) {
                sdb_dbi_client_destroy(client);
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: "
                                "Failed to allocate sdb_object_t\n");
                return -1;
        }
                                "Failed to allocate sdb_object_t\n");
                return -1;
        }
@@ -353,7 +353,7 @@ sdb_puppet_stcfg_config(oconfig_item_t *ci)
                if (! strcasecmp(child->key, "Connection"))
                        sdb_puppet_stcfg_config_conn(child);
                else
                if (! strcasecmp(child->key, "Connection"))
                        sdb_puppet_stcfg_config_conn(child);
                else
-                       sdb_error_set(SDB_LOG_WARNING, "puppet storeconfigs backend: "
+                       sdb_log(SDB_LOG_WARNING, "puppet storeconfigs backend: "
                                        "Ignoring unknown config option '%s'.\n", child->key);
        }
        return 0;
                                        "Ignoring unknown config option '%s'.\n", child->key);
        }
        return 0;
@@ -372,7 +372,7 @@ sdb_module_init(sdb_plugin_info_t *info)
        sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
 
        if (dbi_initialize(/* driver dir = */ NULL) < 0) {
        sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION);
 
        if (dbi_initialize(/* driver dir = */ NULL) < 0) {
-               sdb_error_set(SDB_LOG_ERR, "puppet storeconfigs backend: failed to "
+               sdb_log(SDB_LOG_ERR, "puppet storeconfigs backend: failed to "
                                "initialize DBI; possibly you don't have any drivers "
                                "installed.\n");
                return -1;
                                "initialize DBI; possibly you don't have any drivers "
                                "installed.\n");
                return -1;
index 7f5883aa20cefa0a4e1e07afb8b89a3afe54a598..99f07cb03e2a10914f56fab553a4e56aad54eed6 100644 (file)
@@ -199,7 +199,7 @@ sdb_plugin_cb_init(sdb_object_t *obj, va_list ap)
        assert(obj);
 
        if (sdb_plugin_find_by_name(*list, name)) {
        assert(obj);
 
        if (sdb_plugin_find_by_name(*list, name)) {
-               sdb_error_set(SDB_LOG_WARNING, "plugin: %s callback '%s' "
+               sdb_log(SDB_LOG_WARNING, "plugin: %s callback '%s' "
                                "has already been registered. Ignoring newly "
                                "registered version.\n", type, name);
                return -1;
                                "has already been registered. Ignoring newly "
                                "registered version.\n", type, name);
                return -1;
@@ -253,7 +253,7 @@ sdb_plugin_add_callback(sdb_llist_t **list, const char *type,
        /* pass control to the list */
        sdb_object_deref(obj);
 
        /* pass control to the list */
        sdb_object_deref(obj);
 
-       sdb_error_set(SDB_LOG_INFO, "plugin: Registered %s callback '%s'.\n",
+       sdb_log(SDB_LOG_INFO, "plugin: Registered %s callback '%s'.\n",
                        type, name);
        return 0;
 } /* sdb_plugin_add_callback */
                        type, name);
        return 0;
 } /* sdb_plugin_add_callback */
@@ -280,7 +280,7 @@ sdb_plugin_load(const char *name)
 
        if (access(filename, R_OK)) {
                char errbuf[1024];
 
        if (access(filename, R_OK)) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "plugin: Failed to load plugin '%s': %s\n",
+               sdb_log(SDB_LOG_ERR, "plugin: Failed to load plugin '%s': %s\n",
                                name, sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
        }
                                name, sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
        }
@@ -290,7 +290,7 @@ sdb_plugin_load(const char *name)
 
        lh = lt_dlopen(filename);
        if (! lh) {
 
        lh = lt_dlopen(filename);
        if (! lh) {
-               sdb_error_set(SDB_LOG_ERR, "plugin: Failed to load plugin '%s': %s\n"
+               sdb_log(SDB_LOG_ERR, "plugin: Failed to load plugin '%s': %s\n"
                                "The most common cause for this problem are missing "
                                "dependencies.\n", name, lt_dlerror());
                return -1;
                                "The most common cause for this problem are missing "
                                "dependencies.\n", name, lt_dlerror());
                return -1;
@@ -298,14 +298,14 @@ sdb_plugin_load(const char *name)
 
        mod_init = (int (*)(sdb_plugin_info_t *))lt_dlsym(lh, "sdb_module_init");
        if (! mod_init) {
 
        mod_init = (int (*)(sdb_plugin_info_t *))lt_dlsym(lh, "sdb_module_init");
        if (! mod_init) {
-               sdb_error_set(SDB_LOG_ERR, "plugin: Failed to load plugin '%s': "
+               sdb_log(SDB_LOG_ERR, "plugin: Failed to load plugin '%s': "
                                "could not find symbol 'sdb_module_init'\n", name);
                return -1;
        }
 
        status = mod_init(&plugin_info);
        if (status) {
                                "could not find symbol 'sdb_module_init'\n", name);
                return -1;
        }
 
        status = mod_init(&plugin_info);
        if (status) {
-               sdb_error_set(SDB_LOG_ERR, "plugin: Failed to initialize "
+               sdb_log(SDB_LOG_ERR, "plugin: Failed to initialize "
                                "plugin '%s'\n", name);
                return -1;
        }
                                "plugin '%s'\n", name);
                return -1;
        }
@@ -313,13 +313,13 @@ sdb_plugin_load(const char *name)
        /* compare minor version */
        if ((plugin_info.version < 0)
                        || ((int)(plugin_info.version / 100) != (int)(SDB_VERSION / 100)))
        /* compare minor version */
        if ((plugin_info.version < 0)
                        || ((int)(plugin_info.version / 100) != (int)(SDB_VERSION / 100)))
-               sdb_error_set(SDB_LOG_WARNING, "plugin: WARNING: version of "
+               sdb_log(SDB_LOG_WARNING, "plugin: WARNING: version of "
                                "plugin '%s' (%i.%i.%i) does not match our version "
                                "(%i.%i.%i); this might cause problems\n",
                                name, SDB_VERSION_DECODE(plugin_info.version),
                                SDB_VERSION_DECODE(SDB_VERSION));
 
                                "plugin '%s' (%i.%i.%i) does not match our version "
                                "(%i.%i.%i); this might cause problems\n",
                                name, SDB_VERSION_DECODE(plugin_info.version),
                                SDB_VERSION_DECODE(SDB_VERSION));
 
-       sdb_error_set(SDB_LOG_INFO, "plugin: Successfully loaded "
+       sdb_log(SDB_LOG_INFO, "plugin: Successfully loaded "
                        "plugin '%s' v%i (%s)\n\t%s\n",
                        plugin_info.name, plugin_info.plugin_version,
                        plugin_info.description, plugin_info.copyright);
                        "plugin '%s' v%i (%s)\n\t%s\n",
                        plugin_info.name, plugin_info.plugin_version,
                        plugin_info.description, plugin_info.copyright);
@@ -438,7 +438,7 @@ sdb_plugin_register_collector(const char *name, sdb_plugin_collector_cb callback
 
        if (! (SDB_PLUGIN_CCB(obj)->ccb_next_update = sdb_gettime())) {
                char errbuf[1024];
 
        if (! (SDB_PLUGIN_CCB(obj)->ccb_next_update = sdb_gettime())) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "plugin: Failed to determine current "
+               sdb_log(SDB_LOG_ERR, "plugin: Failed to determine current "
                                "time: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                sdb_object_deref(obj);
                return -1;
                                "time: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                sdb_object_deref(obj);
                return -1;
@@ -453,7 +453,7 @@ sdb_plugin_register_collector(const char *name, sdb_plugin_collector_cb callback
        /* pass control to the list */
        sdb_object_deref(obj);
 
        /* pass control to the list */
        sdb_object_deref(obj);
 
-       sdb_error_set(SDB_LOG_INFO, "plugin: Registered collector callback '%s' "
+       sdb_log(SDB_LOG_INFO, "plugin: Registered collector callback '%s' "
                        "(interval = %.3fs).\n", name,
                        SDB_TIME_TO_DOUBLE(SDB_PLUGIN_CCB(obj)->ccb_interval));
        return 0;
                        "(interval = %.3fs).\n", name,
                        SDB_TIME_TO_DOUBLE(SDB_PLUGIN_CCB(obj)->ccb_interval));
        return 0;
@@ -511,7 +511,7 @@ sdb_plugin_configure(const char *name, oconfig_item_t *ci)
        plugin = sdb_plugin_find_by_name(config_list, name);
        if (! plugin) {
                /* XXX: check if any such plugin has been loaded */
        plugin = sdb_plugin_find_by_name(config_list, name);
        if (! plugin) {
                /* XXX: check if any such plugin has been loaded */
-               sdb_error_set(SDB_LOG_ERR, "plugin: Plugin '%s' did not register "
+               sdb_log(SDB_LOG_ERR, "plugin: Plugin '%s' did not register "
                                "a config callback.\n", name);
                errno = ENOENT;
                return -1;
                                "a config callback.\n", name);
                errno = ENOENT;
                return -1;
@@ -568,7 +568,7 @@ sdb_plugin_collector_loop(sdb_plugin_loop_t *loop)
 
                if (! (now = sdb_gettime())) {
                        char errbuf[1024];
 
                if (! (now = sdb_gettime())) {
                        char errbuf[1024];
-                       sdb_error_set(SDB_LOG_ERR, "plugin: Failed to determine current "
+                       sdb_log(SDB_LOG_ERR, "plugin: Failed to determine current "
                                        "time: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        now = SDB_PLUGIN_CCB(obj)->ccb_next_update;
                }
                                        "time: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        now = SDB_PLUGIN_CCB(obj)->ccb_next_update;
                }
@@ -580,7 +580,7 @@ sdb_plugin_collector_loop(sdb_plugin_loop_t *loop)
                        while (loop->do_loop && sdb_sleep(interval, &interval)) {
                                if (errno != EINTR) {
                                        char errbuf[1024];
                        while (loop->do_loop && sdb_sleep(interval, &interval)) {
                                if (errno != EINTR) {
                                        char errbuf[1024];
-                                       sdb_error_set(SDB_LOG_ERR, "plugin: Failed to sleep: %s\n",
+                                       sdb_log(SDB_LOG_ERR, "plugin: Failed to sleep: %s\n",
                                                        sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                        return -1;
                                }
                                                        sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                        return -1;
                                }
@@ -601,7 +601,7 @@ sdb_plugin_collector_loop(sdb_plugin_loop_t *loop)
                if (! interval)
                        interval = loop->default_interval;
                if (! interval) {
                if (! interval)
                        interval = loop->default_interval;
                if (! interval) {
-                       sdb_error_set(SDB_LOG_WARNING, "plugin: No interval configured "
+                       sdb_log(SDB_LOG_WARNING, "plugin: No interval configured "
                                        "for plugin '%s'; skipping any further "
                                        "iterations.\n", SDB_PLUGIN_CCB(obj)->ccb_name);
                        sdb_object_deref(obj);
                                        "for plugin '%s'; skipping any further "
                                        "iterations.\n", SDB_PLUGIN_CCB(obj)->ccb_name);
                        sdb_object_deref(obj);
@@ -612,13 +612,13 @@ sdb_plugin_collector_loop(sdb_plugin_loop_t *loop)
 
                if (! (now = sdb_gettime())) {
                        char errbuf[1024];
 
                if (! (now = sdb_gettime())) {
                        char errbuf[1024];
-                       sdb_error_set(SDB_LOG_ERR, "plugin: Failed to determine current "
+                       sdb_log(SDB_LOG_ERR, "plugin: Failed to determine current "
                                        "time: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        now = SDB_PLUGIN_CCB(obj)->ccb_next_update;
                }
 
                if (now > SDB_PLUGIN_CCB(obj)->ccb_next_update) {
                                        "time: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        now = SDB_PLUGIN_CCB(obj)->ccb_next_update;
                }
 
                if (now > SDB_PLUGIN_CCB(obj)->ccb_next_update) {
-                       sdb_error_set(SDB_LOG_WARNING, "plugin: Plugin '%s' took too "
+                       sdb_log(SDB_LOG_WARNING, "plugin: Plugin '%s' took too "
                                        "long; skipping iterations to keep up.\n",
                                        SDB_PLUGIN_CCB(obj)->ccb_name);
                        SDB_PLUGIN_CCB(obj)->ccb_next_update = now;
                                        "long; skipping iterations to keep up.\n",
                                        SDB_PLUGIN_CCB(obj)->ccb_name);
                        SDB_PLUGIN_CCB(obj)->ccb_next_update = now;
@@ -626,7 +626,7 @@ sdb_plugin_collector_loop(sdb_plugin_loop_t *loop)
 
                if (sdb_llist_insert_sorted(collector_list, obj,
                                        sdb_plugin_cmp_next_update)) {
 
                if (sdb_llist_insert_sorted(collector_list, obj,
                                        sdb_plugin_cmp_next_update)) {
-                       sdb_error_set(SDB_LOG_ERR, "plugin: Failed to re-insert "
+                       sdb_log(SDB_LOG_ERR, "plugin: Failed to re-insert "
                                        "plugin '%s' into collector list. Unable to further "
                                        "use the plugin.\n",
                                        SDB_PLUGIN_CCB(obj)->ccb_name);
                                        "plugin '%s' into collector list. Unable to further "
                                        "use the plugin.\n",
                                        SDB_PLUGIN_CCB(obj)->ccb_name);
index a0bbf55ce39173c536c4758fce4efefcfeca81cf..3901ba45a3016b5d8ca5f911cee64cc33b6db388 100644 (file)
@@ -258,7 +258,7 @@ sdb_store_host(const sdb_host_t *host)
 
        if (old) {
                if (old->host_last_update > last_update) {
 
        if (old) {
                if (old->host_last_update > last_update) {
-                       sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update host '%s' - "
+                       sdb_log(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
                                        "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
@@ -273,7 +273,7 @@ sdb_store_host(const sdb_host_t *host)
                sdb_host_t *new = sdb_host_clone(host);
                if (! new) {
                        char errbuf[1024];
                sdb_host_t *new = sdb_host_clone(host);
                if (! new) {
                        char errbuf[1024];
-                       sdb_error_set(SDB_LOG_ERR, "store: Failed to clone host object: "
+                       sdb_log(SDB_LOG_ERR, "store: Failed to clone host object: "
                                        "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
                                        "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
@@ -282,7 +282,7 @@ sdb_store_host(const sdb_host_t *host)
                if (! new->attributes) {
                        if (! (new->attributes = sdb_llist_create())) {
                                char errbuf[1024];
                if (! new->attributes) {
                        if (! (new->attributes = sdb_llist_create())) {
                                char errbuf[1024];
-                               sdb_error_set(SDB_LOG_ERR, "store: Failed to initialize "
+                               sdb_log(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));
                                                "host object '%s': %s\n", host->host_name,
                                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                sdb_object_deref(SDB_OBJ(new));
@@ -294,7 +294,7 @@ sdb_store_host(const sdb_host_t *host)
                if (! new->services) {
                        if (! (new->services = sdb_llist_create())) {
                                char errbuf[1024];
                if (! new->services) {
                        if (! (new->services = sdb_llist_create())) {
                                char errbuf[1024];
-                               sdb_error_set(SDB_LOG_ERR, "store: Failed to initialize "
+                               sdb_log(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));
                                                "host object '%s': %s\n", host->host_name,
                                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                                sdb_object_deref(SDB_OBJ(new));
@@ -402,7 +402,7 @@ sdb_store_attribute(const sdb_attribute_t *attr)
 
        if (old) {
                if (old->host_last_update > last_update) {
 
        if (old) {
                if (old->host_last_update > last_update) {
-                       sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update attribute "
+                       sdb_log(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);
                                        "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")\n",
                                        attr->hostname, attr->attr_name, last_update,
                                        old->host_last_update);
@@ -416,7 +416,7 @@ sdb_store_attribute(const sdb_attribute_t *attr)
                sdb_attribute_t *new = sdb_attribute_clone(attr);
                if (! new) {
                        char errbuf[1024];
                sdb_attribute_t *new = sdb_attribute_clone(attr);
                if (! new) {
                        char errbuf[1024];
-                       sdb_error_set(SDB_LOG_ERR, "store: Failed to clone attribute "
+                       sdb_log(SDB_LOG_ERR, "store: Failed to clone attribute "
                                        "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
                                        "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
@@ -500,7 +500,7 @@ sdb_store_service(const sdb_service_t *svc)
 
        if (old) {
                if (old->host_last_update > last_update) {
 
        if (old) {
                if (old->host_last_update > last_update) {
-                       sdb_error_set(SDB_LOG_DEBUG, "store: Cannot update service "
+                       sdb_log(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);
                                        "'%s/%s' - value too old (%"PRIscTIME" < %"PRIscTIME")\n",
                                        svc->hostname, svc->svc_name, last_update,
                                        old->host_last_update);
@@ -514,7 +514,7 @@ sdb_store_service(const sdb_service_t *svc)
                sdb_service_t *new = sdb_service_clone(svc);
                if (! new) {
                        char errbuf[1024];
                sdb_service_t *new = sdb_service_clone(svc);
                if (! new) {
                        char errbuf[1024];
-                       sdb_error_set(SDB_LOG_ERR, "store: Failed to clone service "
+                       sdb_log(SDB_LOG_ERR, "store: Failed to clone service "
                                        "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
                                        "object: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        pthread_rwlock_unlock(&host_lock);
                        return -1;
index ea870c2d21c636110a54d553fedf73fc82888165..2975e06fa7d218393907bbcd770809d6689353ff 100644 (file)
@@ -56,14 +56,14 @@ config_get_interval(oconfig_item_t *ci, sdb_time_t *interval)
        assert(ci && interval);
 
        if (oconfig_get_number(ci, &interval_dbl)) {
        assert(ci && interval);
 
        if (oconfig_get_number(ci, &interval_dbl)) {
-               sdb_error_set(SDB_LOG_ERR, "config: Interval requires "
+               sdb_log(SDB_LOG_ERR, "config: Interval requires "
                                "a single numeric argument\n"
                                "\tUsage: Interval SECONDS\n");
                return -1;
        }
 
        if (interval_dbl <= 0.0) {
                                "a single numeric argument\n"
                                "\tUsage: Interval SECONDS\n");
                return -1;
        }
 
        if (interval_dbl <= 0.0) {
-               sdb_error_set(SDB_LOG_ERR, "config: Invalid interval: %f\n"
+               sdb_log(SDB_LOG_ERR, "config: Invalid interval: %f\n"
                                "\tInterval may not be less than or equal to zero.\n",
                                interval_dbl);
                return -1;
                                "\tInterval may not be less than or equal to zero.\n",
                                interval_dbl);
                return -1;
@@ -102,7 +102,7 @@ daemon_load_backend(oconfig_item_t *ci)
        ctx.interval = default_interval;
 
        if (oconfig_get_string(ci, &name)) {
        ctx.interval = default_interval;
 
        if (oconfig_get_string(ci, &name)) {
-               sdb_error_set(SDB_LOG_ERR, "config: LoadBackend requires a single "
+               sdb_log(SDB_LOG_ERR, "config: LoadBackend requires a single "
                                "string argument\n"
                                "\tUsage: LoadBackend BACKEND\n");
                return -1;
                                "string argument\n"
                                "\tUsage: LoadBackend BACKEND\n");
                return -1;
@@ -118,7 +118,7 @@ daemon_load_backend(oconfig_item_t *ci)
                                return -1;
                }
                else {
                                return -1;
                }
                else {
-                       sdb_error_set(SDB_LOG_WARNING, "config: Unknown option '%s' "
+                       sdb_log(SDB_LOG_WARNING, "config: Unknown option '%s' "
                                        "inside 'LoadBackend' -- see the documentation for "
                                        "details.\n", child->key);
                        continue;
                                        "inside 'LoadBackend' -- see the documentation for "
                                        "details.\n", child->key);
                        continue;
@@ -139,7 +139,7 @@ daemon_configure_plugin(oconfig_item_t *ci)
        assert(ci);
 
        if (oconfig_get_string(ci, &name)) {
        assert(ci);
 
        if (oconfig_get_string(ci, &name)) {
-               sdb_error_set(SDB_LOG_ERR, "config: %s requires a single "
+               sdb_log(SDB_LOG_ERR, "config: %s requires a single "
                                "string argument\n"
                                "\tUsage: LoadBackend BACKEND\n",
                                ci->key);
                                "string argument\n"
                                "\tUsage: LoadBackend BACKEND\n",
                                ci->key);
@@ -181,13 +181,13 @@ daemon_parse_config(const char *filename)
                }
 
                if (status) {
                }
 
                if (status) {
-                       sdb_error_start(SDB_LOG_ERR, "config: Failed to parse option "
-                                       "'%s'\n", child->key);
+                       sdb_error_set("config: Failed to parse option '%s'\n",
+                                       child->key);
                        if (status > 0)
                                sdb_error_append("\tUnknown option '%s' -- "
                                                "see the documentation for details\n",
                                                child->key);
                        if (status > 0)
                                sdb_error_append("\tUnknown option '%s' -- "
                                                "see the documentation for details\n",
                                                child->key);
-                       sdb_error_finish();
+                       sdb_error_log(SDB_LOG_ERR);
                        retval = -1;
                }
        }
                        retval = -1;
                }
        }
index d4851f8e42f123fa71dbbceae972fb0a24897390..5a901a223bf432ad02b542bba11c1b2e32ea03a3 100644 (file)
@@ -109,7 +109,7 @@ daemonize(void)
 
        if ((pid = fork()) < 0) {
                char errbuf[1024];
 
        if ((pid = fork()) < 0) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "Failed to fork to background: %s\n",
+               sdb_log(SDB_LOG_ERR, "Failed to fork to background: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
@@ -120,7 +120,7 @@ daemonize(void)
 
        if (chdir("/")) {
                char errbuf[1024];
 
        if (chdir("/")) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "Failed to change working directory to "
+               sdb_log(SDB_LOG_ERR, "Failed to change working directory to "
                                "the root directory: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
                                "the root directory: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
@@ -132,7 +132,7 @@ daemonize(void)
        close(0);
        if (open("/dev/null", O_RDWR)) {
                char errbuf[1024];
        close(0);
        if (open("/dev/null", O_RDWR)) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "Failed to connect stdin to '/dev/null': "
+               sdb_log(SDB_LOG_ERR, "Failed to connect stdin to '/dev/null': "
                                "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
                                "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
@@ -140,7 +140,7 @@ daemonize(void)
        close(1);
        if (dup(0) != 1) {
                char errbuf[1024];
        close(1);
        if (dup(0) != 1) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "Could not connect stdout to '/dev/null': "
+               sdb_log(SDB_LOG_ERR, "Could not connect stdout to '/dev/null': "
                                "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
                                "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
@@ -148,7 +148,7 @@ daemonize(void)
        close(2);
        if (dup(0) != 2) {
                char errbuf[1024];
        close(2);
        if (dup(0) != 2) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "Could not connect stderr to '/dev/null': "
+               sdb_log(SDB_LOG_ERR, "Could not connect stderr to '/dev/null': "
                                "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
                                "%s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return errno;
        }
@@ -195,7 +195,7 @@ main(int argc, char **argv)
                config_filename = CONFIGFILE;
 
        if (daemon_parse_config(config_filename)) {
                config_filename = CONFIGFILE;
 
        if (daemon_parse_config(config_filename)) {
-               sdb_error_set(SDB_LOG_ERR, "Failed to parse configuration file.\n");
+               sdb_log(SDB_LOG_ERR, "Failed to parse configuration file.\n");
                exit(1);
        }
 
                exit(1);
        }
 
@@ -205,13 +205,13 @@ main(int argc, char **argv)
 
        if (sigaction(SIGINT, &sa_intterm, /* old action */ NULL)) {
                char errbuf[1024];
 
        if (sigaction(SIGINT, &sa_intterm, /* old action */ NULL)) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "Failed to install signal handler for "
+               sdb_log(SDB_LOG_ERR, "Failed to install signal handler for "
                                "SIGINT: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                exit(1);
        }
        if (sigaction(SIGTERM, &sa_intterm, /* old action */ NULL)) {
                char errbuf[1024];
                                "SIGINT: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                exit(1);
        }
        if (sigaction(SIGTERM, &sa_intterm, /* old action */ NULL)) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "Failed to install signal handler for "
+               sdb_log(SDB_LOG_ERR, "Failed to install signal handler for "
                                "SIGTERM: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                exit(1);
        }
                                "SIGTERM: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                exit(1);
        }
@@ -220,14 +220,14 @@ main(int argc, char **argv)
                if (daemonize())
                        exit(1);
 
                if (daemonize())
                        exit(1);
 
-       sdb_error_set(SDB_LOG_INFO, "SysDB daemon "SDB_VERSION_STRING
+       sdb_log(SDB_LOG_INFO, "SysDB daemon "SDB_VERSION_STRING
                        SDB_VERSION_EXTRA " (pid %i) initialized successfully\n",
                        (int)getpid());
 
        sdb_plugin_init_all();
        sdb_plugin_collector_loop(&plugin_main_loop);
 
                        SDB_VERSION_EXTRA " (pid %i) initialized successfully\n",
                        (int)getpid());
 
        sdb_plugin_init_all();
        sdb_plugin_collector_loop(&plugin_main_loop);
 
-       sdb_error_set(SDB_LOG_INFO, "Shutting down SysDB daemon "SDB_VERSION_STRING
+       sdb_log(SDB_LOG_INFO, "Shutting down SysDB daemon "SDB_VERSION_STRING
                        SDB_VERSION_EXTRA" (pid %i)\n", (int)getpid());
 
        fprintf(stderr, "Store dump:\n");
                        SDB_VERSION_EXTRA" (pid %i)\n", (int)getpid());
 
        fprintf(stderr, "Store dump:\n");
index 8b2a177160c08102632675331a931da881114f82..73b48baacf2c1cdf9f5df66118166fc90c6df408 100644 (file)
@@ -60,34 +60,42 @@ enum {
 };
 #define SDB_LOG_PRIO_TO_STRING(prio) \
        (((prio) == SDB_LOG_EMERG) ? "EMERG" \
 };
 #define SDB_LOG_PRIO_TO_STRING(prio) \
        (((prio) == SDB_LOG_EMERG) ? "EMERG" \
-               : ((prio) == SDB_LOG_ERR) ? "ERR" \
+               : ((prio) == SDB_LOG_ERR) ? "ERROR" \
                : ((prio) == SDB_LOG_WARNING) ? "WARNING" \
                : ((prio) == SDB_LOG_NOTICE) ? "NOTICE" \
                : ((prio) == SDB_LOG_INFO) ? "INFO" \
                : ((prio) == SDB_LOG_DEBUG) ? "DEBUG" : "UNKNOWN")
 
 /*
                : ((prio) == SDB_LOG_WARNING) ? "WARNING" \
                : ((prio) == SDB_LOG_NOTICE) ? "NOTICE" \
                : ((prio) == SDB_LOG_INFO) ? "INFO" \
                : ((prio) == SDB_LOG_DEBUG) ? "DEBUG" : "UNKNOWN")
 
 /*
- * sdb_error_set:
- * Set the current error message. The string will be formated in printf-style
+ * sdb_log:
+ * Log the specified message. The string will be formatted in printf-style
  * using the specified format and arguments and logged with the specified
  * using the specified format and arguments and logged with the specified
- * priority. XXX: SDB_LOG_EMERG might, at some point and/or depending on
- * configuration, try a clean shut-down of the process.
+ * priority. In addition, the error message will be stored as the current
+ * error message. This function is basically the same as calling sdb_error_set
+ * and sdb_error_log. XXX: SDB_LOG_EMERG might, at some point and/or depending
+ * on configuration, try a clean shut-down of the process.
  */
 int
  */
 int
-sdb_error_set(int prio, const char *fmt, ...);
+sdb_log(int prio, const char *fmt, ...);
 
 /*
 
 /*
- * sdb_error_start, sdb_error_append, sdb_error_end:
- * Compose the current error message from multiple parts. The error message
- * will only be logged after calling sdb_error_finish().
- * See sdb_error_set for details.
+ * sdb_error_set, sdb_error_append:
+ * Compose the current error message. The string will be formatted in printf-
+ * style using the specified format and arguments. No automatic logging will
+ * be done.
  */
 int
  */
 int
-sdb_error_start(int prio, const char *fmt, ...);
+sdb_error_set(const char *fmt, ...);
 int
 sdb_error_append(const char *fmt, ...);
 int
 sdb_error_append(const char *fmt, ...);
+
+/*
+ * sdb_error_log:
+ * Log the current error message with the specified priority. See sdb_log for
+ * more information.
+ */
 int
 int
-sdb_error_finish(void);
+sdb_error_log(int prio);
 
 /*
  * sdb_error_get:
 
 /*
  * sdb_error_get:
@@ -100,8 +108,8 @@ sdb_error_get(void);
 
 /*
  * sdb_error_get_prio:
 
 /*
  * sdb_error_get_prio:
- * Get the priority of the current error message -- see the SDB_LOG_ constants
- * for details.
+ * Get the priority of the last logged error message -- see the SDB_LOG_
+ * constants for details.
  */
 int
 sdb_error_get_prio(void);
  */
 int
 sdb_error_get_prio(void);
index dc1d6e4fc3af78460366c714e21146d9dfe31869..60b47c46faeaa840beaac97519b81a09dcbcfb41 100644 (file)
@@ -102,7 +102,7 @@ sdb_dbi_get_field(dbi_result res, unsigned int i,
                        }
                        break;
                default:
                        }
                        break;
                default:
-                       sdb_error_set(SDB_LOG_ERR, "dbi: Unexpected type %i while "
+                       sdb_log(SDB_LOG_ERR, "dbi: Unexpected type %i while "
                                        "parsing query result.\n", type);
                        return -1;
        }
                                        "parsing query result.\n", type);
                        return -1;
        }
@@ -129,7 +129,7 @@ sdb_dbi_get_data(sdb_dbi_client_t *client, dbi_result res,
        for (i = 0; i < num_fields; ++i) {
                types[i] = dbi_result_get_field_type_idx(res, i + 1);
                if (types[i] == DBI_TYPE_ERROR) {
        for (i = 0; i < num_fields; ++i) {
                types[i] = dbi_result_get_field_type_idx(res, i + 1);
                if (types[i] == DBI_TYPE_ERROR) {
-                       sdb_error_set(SDB_LOG_ERR, "dbi: failed to fetch data: %s\n",
+                       sdb_log(SDB_LOG_ERR, "dbi: failed to fetch data: %s\n",
                                        sdb_dbi_strerror(client->conn));
                        return -1;
                }
                                        sdb_dbi_strerror(client->conn));
                        return -1;
                }
@@ -142,7 +142,7 @@ sdb_dbi_get_data(sdb_dbi_client_t *client, dbi_result res,
 
        for (n = 0; n < num_rows; ++n) {
                if (! dbi_result_seek_row(res, n + 1)) {
 
        for (n = 0; n < num_rows; ++n) {
                if (! dbi_result_seek_row(res, n + 1)) {
-                       sdb_error_set(SDB_LOG_ERR, "dbi: Failed to retrieve row %llu: "
+                       sdb_log(SDB_LOG_ERR, "dbi: Failed to retrieve row %llu: "
                                        "%s\n", n, sdb_dbi_strerror(client->conn));
                        continue;
                }
                                        "%s\n", n, sdb_dbi_strerror(client->conn));
                        continue;
                }
@@ -289,7 +289,7 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client)
 
        driver = dbi_driver_open(client->driver);
        if (! driver) {
 
        driver = dbi_driver_open(client->driver);
        if (! driver) {
-               sdb_error_start(SDB_LOG_ERR, "dbi: failed to open DBI driver '%s'; "
+               sdb_error_set("dbi: failed to open DBI driver '%s'; "
                                "possibly it's not installed.\n",
                                client->driver);
 
                                "possibly it's not installed.\n",
                                client->driver);
 
@@ -298,13 +298,13 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client)
                                driver = dbi_driver_list(driver)) {
                        sdb_error_append("\t- %s\n", dbi_driver_get_name(driver));
                }
                                driver = dbi_driver_list(driver)) {
                        sdb_error_append("\t- %s\n", dbi_driver_get_name(driver));
                }
-               sdb_error_finish();
+               sdb_error_log(SDB_LOG_ERR);
                return -1;
        }
 
        client->conn = dbi_conn_open(driver);
        if (! client->conn) {
                return -1;
        }
 
        client->conn = dbi_conn_open(driver);
        if (! client->conn) {
-               sdb_error_set(SDB_LOG_ERR, "dbi: failed to open connection "
+               sdb_log(SDB_LOG_ERR, "dbi: failed to open connection "
                                "object.\n");
                return -1;
        }
                                "object.\n");
                return -1;
        }
@@ -319,7 +319,7 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client)
                                continue;
                        /* else: error */
 
                                continue;
                        /* else: error */
 
-                       sdb_error_start(SDB_LOG_ERR, "dbi: failed to set option '%s': "
+                       sdb_error_set("dbi: failed to set option '%s': "
                                        "%s\n", client->options->options[i].key,
                                        sdb_dbi_strerror(client->conn));
 
                                        "%s\n", client->options->options[i].key,
                                        sdb_dbi_strerror(client->conn));
 
@@ -327,7 +327,7 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client)
                        for (opt = dbi_conn_get_option_list(client->conn, NULL); opt;
                                        opt = dbi_conn_get_option_list(client->conn, opt))
                                sdb_error_append("\t- %s\n", opt);
                        for (opt = dbi_conn_get_option_list(client->conn, NULL); opt;
                                        opt = dbi_conn_get_option_list(client->conn, opt))
                                sdb_error_append("\t- %s\n", opt);
-                       sdb_error_finish();
+                       sdb_error_log(SDB_LOG_ERR);
 
                        dbi_conn_close(client->conn);
                        return -1;
 
                        dbi_conn_close(client->conn);
                        return -1;
@@ -335,14 +335,14 @@ sdb_dbi_client_connect(sdb_dbi_client_t *client)
        }
 
        if (dbi_conn_set_option(client->conn, "dbname", client->database)) {
        }
 
        if (dbi_conn_set_option(client->conn, "dbname", client->database)) {
-               sdb_error_set(SDB_LOG_ERR, "dbi: failed to set option 'dbname': %s\n",
+               sdb_log(SDB_LOG_ERR, "dbi: failed to set option 'dbname': %s\n",
                                sdb_dbi_strerror(client->conn));
                dbi_conn_close(client->conn);
                return -1;
        }
 
        if (dbi_conn_connect(client->conn) < 0) {
                                sdb_dbi_strerror(client->conn));
                dbi_conn_close(client->conn);
                return -1;
        }
 
        if (dbi_conn_connect(client->conn) < 0) {
-               sdb_error_set(SDB_LOG_ERR, "dbi: failed to connect to database '%s': "
+               sdb_log(SDB_LOG_ERR, "dbi: failed to connect to database '%s': "
                                "%s\n", client->database, sdb_dbi_strerror(client->conn));
                dbi_conn_close(client->conn);
                return -1;
                                "%s\n", client->database, sdb_dbi_strerror(client->conn));
                dbi_conn_close(client->conn);
                return -1;
@@ -378,13 +378,13 @@ sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query,
 
        res = dbi_conn_query(client->conn, query);
        if (! res) {
 
        res = dbi_conn_query(client->conn, query);
        if (! res) {
-               sdb_error_set(SDB_LOG_ERR, "dbi: failed to execute query '%s': %s\n",
+               sdb_log(SDB_LOG_ERR, "dbi: failed to execute query '%s': %s\n",
                                query, sdb_dbi_strerror(client->conn));
                return -1;
        }
 
        if (dbi_result_get_numrows(res) == DBI_ROW_ERROR) {
                                query, sdb_dbi_strerror(client->conn));
                return -1;
        }
 
        if (dbi_result_get_numrows(res) == DBI_ROW_ERROR) {
-               sdb_error_set(SDB_LOG_ERR, "dbi: failed to fetch rows for query "
+               sdb_log(SDB_LOG_ERR, "dbi: failed to fetch rows for query "
                                "'%s': %s\n", query, sdb_dbi_strerror(client->conn));
                dbi_result_free(res);
                return -1;
                                "'%s': %s\n", query, sdb_dbi_strerror(client->conn));
                dbi_result_free(res);
                return -1;
@@ -402,7 +402,7 @@ sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query,
                int i;
 
                if (n != (int)num_fields) {
                int i;
 
                if (n != (int)num_fields) {
-                       sdb_error_set(SDB_LOG_ERR, "dbi: number of returned fields (%i) "
+                       sdb_log(SDB_LOG_ERR, "dbi: number of returned fields (%i) "
                                        "does not match the number of requested fields (%i) "
                                        "for query '%s'.\n", num_fields, n, query);
                        dbi_result_free(res);
                                        "does not match the number of requested fields (%i) "
                                        "for query '%s'.\n", num_fields, n, query);
                        dbi_result_free(res);
@@ -422,7 +422,7 @@ sdb_dbi_exec_query(sdb_dbi_client_t *client, const char *query,
 
                        /* column count starts at 1 */
                        if ((unsigned int)field_type != type) {
 
                        /* column count starts at 1 */
                        if ((unsigned int)field_type != type) {
-                               sdb_error_set(SDB_LOG_ERR, "dbi: type of column '%s' (%u) "
+                               sdb_log(SDB_LOG_ERR, "dbi: type of column '%s' (%u) "
                                                "does not match requested type (%u).\n",
                                                dbi_result_get_field_name(res, (unsigned int)i + 1),
                                                field_type, type);
                                                "does not match requested type (%u).\n",
                                                dbi_result_get_field_name(res, (unsigned int)i + 1),
                                                field_type, type);
index 08a77f1c40b9007d9e05dd365dc9a6b07f5e15c3..7eef71263d70b695945da5671e55d0e632a05377 100644 (file)
@@ -42,7 +42,7 @@
 typedef struct {
        int   prio;
        char  msg[SDB_MAX_ERROR];
 typedef struct {
        int   prio;
        char  msg[SDB_MAX_ERROR];
-       _Bool finalized;
+       _Bool logged;
 } sdb_error_ctx_t;
 #define SDB_ERROR_INIT { -1, "", 1 }
 
 } sdb_error_ctx_t;
 #define SDB_ERROR_INIT { -1, "", 1 }
 
@@ -121,12 +121,12 @@ sdb_error_clear(void)
 
        ctx->prio = -1;
        ctx->msg[0] = '\0';
 
        ctx->prio = -1;
        ctx->msg[0] = '\0';
-       ctx->finalized = 1;
+       ctx->logged = 1;
        return 0;
 } /* sdb_error_clear */
 
 static int
        return 0;
 } /* sdb_error_clear */
 
 static int
-sdb_error_vappend(int prio, const char *fmt, va_list ap)
+sdb_error_vappend(const char *fmt, va_list ap)
 {
        sdb_error_ctx_t *ctx;
        size_t len;
 {
        sdb_error_ctx_t *ctx;
        size_t len;
@@ -139,15 +139,12 @@ sdb_error_vappend(int prio, const char *fmt, va_list ap)
        if (len >= sizeof(ctx->msg))
                return 0; /* nothing written */
 
        if (len >= sizeof(ctx->msg))
                return 0; /* nothing written */
 
-       if (prio >= 0)
-               ctx->prio = prio;
-
-       ctx->finalized = 0;
+       ctx->logged = 0;
        return vsnprintf(ctx->msg + len, sizeof(ctx->msg) - len, fmt, ap);
 } /* sdb_error_vappend */
 
 static int
        return vsnprintf(ctx->msg + len, sizeof(ctx->msg) - len, fmt, ap);
 } /* sdb_error_vappend */
 
 static int
-sdb_error_log(void)
+sdb_do_log(int prio)
 {
        sdb_error_ctx_t *ctx;
        int ret;
 {
        sdb_error_ctx_t *ctx;
        int ret;
@@ -156,21 +153,24 @@ sdb_error_log(void)
        if (! ctx)
                return -1;
 
        if (! ctx)
                return -1;
 
-       if (ctx->finalized)
+       if (prio >= 0)
+               ctx->prio = prio;
+
+       if (ctx->logged)
                return 0;
 
        ret = fprintf(stderr, "[%s] %s\n",
                return 0;
 
        ret = fprintf(stderr, "[%s] %s\n",
-                       SDB_LOG_PRIO_TO_STRING(ctx->prio), ctx->msg);
-       ctx->finalized = 1;
+                       SDB_LOG_PRIO_TO_STRING(prio), ctx->msg);
+       ctx->logged = 1;
        return ret;
        return ret;
-} /* sdb_error_log */
+} /* sdb_do_log */
 
 /*
  * public API
  */
 
 int
 
 /*
  * public API
  */
 
 int
-sdb_error_set(int prio, const char *fmt, ...)
+sdb_log(int prio, const char *fmt, ...)
 {
        va_list ap;
        int ret;
 {
        va_list ap;
        int ret;
@@ -179,15 +179,15 @@ sdb_error_set(int prio, const char *fmt, ...)
                return -1;
 
        va_start(ap, fmt);
                return -1;
 
        va_start(ap, fmt);
-       ret = sdb_error_vappend(prio, fmt, ap);
+       ret = sdb_error_vappend(fmt, ap);
        va_end(ap);
 
        va_end(ap);
 
-       sdb_error_log();
+       sdb_do_log(prio);
        return ret;
        return ret;
-} /* sdb_error_set */
+} /* sdb_log */
 
 int
 
 int
-sdb_error_start(int prio, const char *fmt, ...)
+sdb_error_set(const char *fmt, ...)
 {
        va_list ap;
        int ret;
 {
        va_list ap;
        int ret;
@@ -196,11 +196,11 @@ sdb_error_start(int prio, const char *fmt, ...)
                return -1;
 
        va_start(ap, fmt);
                return -1;
 
        va_start(ap, fmt);
-       ret = sdb_error_vappend(prio, fmt, ap);
+       ret = sdb_error_vappend(fmt, ap);
        va_end(ap);
 
        return ret;
        va_end(ap);
 
        return ret;
-} /* sdb_error_start */
+} /* sdb_error_set */
 
 int
 sdb_error_append(const char *fmt, ...)
 
 int
 sdb_error_append(const char *fmt, ...)
@@ -209,17 +209,17 @@ sdb_error_append(const char *fmt, ...)
        int ret;
 
        va_start(ap, fmt);
        int ret;
 
        va_start(ap, fmt);
-       ret = sdb_error_vappend(/* dont change prio */ -1, fmt, ap);
+       ret = sdb_error_vappend(fmt, ap);
        va_end(ap);
 
        return ret;
 } /* sdb_error_append */
 
 int
        va_end(ap);
 
        return ret;
 } /* sdb_error_append */
 
 int
-sdb_error_finish(void)
+sdb_error_log(int prio)
 {
 {
-       return sdb_error_log();
-} /* sdb_error_finish */
+       return sdb_do_log(prio);
+} /* sdb_error_log */
 
 const char *
 sdb_error_get(void)
 
 const char *
 sdb_error_get(void)
index b4b9772a0e9dbe1684abed2e7af3d8b9fad8fc06..08233f8fb23f757a987422e73cd99f5d3dd58817 100644 (file)
@@ -117,7 +117,7 @@ sdb_unixsock_parse_cell(char *string, int type, sdb_data_t *data)
                        data->data.binary.datum = (const unsigned char *)string;
                        break;
                default:
                        data->data.binary.datum = (const unsigned char *)string;
                        break;
                default:
-                       sdb_error_set(SDB_LOG_ERR, "unixsock: Unexpected type %i while "
+                       sdb_log(SDB_LOG_ERR, "unixsock: Unexpected type %i while "
                                        "parsing query result.\n", type);
                        return -1;
        }
                                        "parsing query result.\n", type);
                        return -1;
        }
@@ -126,13 +126,13 @@ sdb_unixsock_parse_cell(char *string, int type, sdb_data_t *data)
                        || (type == SDB_TYPE_DATETIME)) {
                if (errno || (string == endptr)) {
                        char errbuf[1024];
                        || (type == SDB_TYPE_DATETIME)) {
                if (errno || (string == endptr)) {
                        char errbuf[1024];
-                       sdb_error_set(SDB_LOG_ERR, "unixsock: Failed to parse string "
+                       sdb_log(SDB_LOG_ERR, "unixsock: Failed to parse string "
                                        "'%s' as numeric value (type %i): %s\n", string, type,
                                        sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        return -1;
                }
                else if (endptr && (*endptr != '\0'))
                                        "'%s' as numeric value (type %i): %s\n", string, type,
                                        sdb_strerror(errno, errbuf, sizeof(errbuf)));
                        return -1;
                }
                else if (endptr && (*endptr != '\0'))
-                       sdb_error_set(SDB_LOG_WARNING, "unixsock: Ignoring garbage after "
+                       sdb_log(SDB_LOG_WARNING, "unixsock: Ignoring garbage after "
                                        "number while parsing numeric value (type %i): %s.\n",
                                        type, endptr);
        }
                                        "number while parsing numeric value (type %i): %s.\n",
                                        type, endptr);
        }
@@ -158,7 +158,7 @@ sdb_unixsock_client_process_one_line(sdb_unixsock_client_t *client,
                char *next;
 
                if (! line) { /* this must no happen */
                char *next;
 
                if (! line) { /* this must no happen */
-                       sdb_error_set(SDB_LOG_ERR, "unixsock: Unexpected EOL while "
+                       sdb_log(SDB_LOG_ERR, "unixsock: Unexpected EOL while "
                                        "parsing line (expected %i columns delimited by '%s'; "
                                        "got %i): %s\n", column_count, delim,
                                        /* last line number */ i, orig_line);
                                        "parsing line (expected %i columns delimited by '%s'; "
                                        "got %i): %s\n", column_count, delim,
                                        /* last line number */ i, orig_line);
@@ -232,7 +232,7 @@ sdb_unixsock_client_connect(sdb_unixsock_client_t *client)
        fd = socket(AF_UNIX, SOCK_STREAM, /* protocol = */ 0);
        if (fd < 0) {
                char errbuf[1024];
        fd = socket(AF_UNIX, SOCK_STREAM, /* protocol = */ 0);
        if (fd < 0) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "unixsock: Failed to open socket: %s\n",
+               sdb_log(SDB_LOG_ERR, "unixsock: Failed to open socket: %s\n",
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
        }
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
        }
@@ -243,7 +243,7 @@ sdb_unixsock_client_connect(sdb_unixsock_client_t *client)
 
        if (connect(fd, (struct sockaddr *)&sa, sizeof(sa))) {
                char errbuf[1024];
 
        if (connect(fd, (struct sockaddr *)&sa, sizeof(sa))) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "unixsock: Failed to connect to %s: %s\n",
+               sdb_log(SDB_LOG_ERR, "unixsock: Failed to connect to %s: %s\n",
                                sa.sun_path, sdb_strerror(errno, errbuf, sizeof(errbuf)));
                close(fd);
                return -1;
                                sa.sun_path, sdb_strerror(errno, errbuf, sizeof(errbuf)));
                close(fd);
                return -1;
@@ -252,7 +252,7 @@ sdb_unixsock_client_connect(sdb_unixsock_client_t *client)
        client->fh = fdopen(fd, "r+");
        if (! client->fh) {
                char errbuf[1024];
        client->fh = fdopen(fd, "r+");
        if (! client->fh) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "unixsock: Failed to open I/O "
+               sdb_log(SDB_LOG_ERR, "unixsock: Failed to open I/O "
                                "stream for %s: %s\n", sa.sun_path,
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                close(fd);
                                "stream for %s: %s\n", sa.sun_path,
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                close(fd);
@@ -278,7 +278,7 @@ sdb_unixsock_client_send(sdb_unixsock_client_t *client,
        status = fprintf(client->fh, "%s\r\n", msg);
        if (status < 0) {
                char errbuf[1024];
        status = fprintf(client->fh, "%s\r\n", msg);
        if (status < 0) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "unixsock: Failed to write to "
+               sdb_log(SDB_LOG_ERR, "unixsock: Failed to write to "
                                "socket (%s): %s\n", client->path,
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return status;
                                "socket (%s): %s\n", client->path,
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return status;
@@ -300,7 +300,7 @@ sdb_unixsock_client_recv(sdb_unixsock_client_t *client,
        if (! buffer) {
                if (! feof(client->fh)) {
                        char errbuf[1024];
        if (! buffer) {
                if (! feof(client->fh)) {
                        char errbuf[1024];
-                       sdb_error_set(SDB_LOG_ERR, "unixsock: Failed to read "
+                       sdb_log(SDB_LOG_ERR, "unixsock: Failed to read "
                                        "from socket (%s): %s\n", client->path,
                                        sdb_strerror(errno, errbuf, sizeof(errbuf)));
                }
                                        "from socket (%s): %s\n", client->path,
                                        sdb_strerror(errno, errbuf, sizeof(errbuf)));
                }
@@ -341,7 +341,7 @@ sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client,
                        types[i] = va_arg(ap, int);
 
                        if ((types[i] < 1) || (types[i] > SDB_TYPE_BINARY)) {
                        types[i] = va_arg(ap, int);
 
                        if ((types[i] < 1) || (types[i] > SDB_TYPE_BINARY)) {
-                               sdb_error_set(SDB_LOG_ERR, "unixsock: Unknown column "
+                               sdb_log(SDB_LOG_ERR, "unixsock: Unknown column "
                                                "type %i while processing response from the "
                                                "UNIX socket @ %s.\n", types[i], client->path);
                                va_end(ap);
                                                "type %i while processing response from the "
                                                "UNIX socket @ %s.\n", types[i], client->path);
                                va_end(ap);
@@ -374,7 +374,7 @@ sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client,
                column_count = sdb_unixsock_get_column_count(line, delim);
 
                if ((n_cols >= 0) && (n_cols != column_count)) {
                column_count = sdb_unixsock_get_column_count(line, delim);
 
                if ((n_cols >= 0) && (n_cols != column_count)) {
-                       sdb_error_set(SDB_LOG_ERR, "unixsock: number of columns (%i) "
+                       sdb_log(SDB_LOG_ERR, "unixsock: number of columns (%i) "
                                        "does not match the number of requested columns (%i) "
                                        "while processing response from the UNIX socket @ %s: "
                                        "%s\n", column_count, n_cols, client->path, line);
                                        "does not match the number of requested columns (%i) "
                                        "while processing response from the UNIX socket @ %s: "
                                        "%s\n", column_count, n_cols, client->path, line);
@@ -395,7 +395,7 @@ sdb_unixsock_client_process_lines(sdb_unixsock_client_t *client,
                        || ((max_lines < 0) && (! sdb_unixsock_client_eof(client)))
                        || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
                        || ((max_lines < 0) && (! sdb_unixsock_client_eof(client)))
                        || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
-               sdb_error_set(SDB_LOG_ERR, "unixsock: Unexpected end of data while "
+               sdb_log(SDB_LOG_ERR, "unixsock: Unexpected end of data while "
                                "reading from socket (%s): %s\n", client->path,
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
                                "reading from socket (%s): %s\n", client->path,
                                sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;