summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ec7449c)
raw | patch | inline | side by side (parent: ec7449c)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 1 Apr 2013 17:56:55 +0000 (19:56 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 1 Apr 2013 17:56:55 +0000 (19:56 +0200) |
This is more appropriate.
21 files changed:
diff --git a/src/Makefile.am b/src/Makefile.am
index 9876de64a7dc1ab52a84460f6c7ca3eac146b8f0..38154a828c78b7f2c57173d9d19b51a2c4a97cab 100644 (file)
--- a/src/Makefile.am
+++ b/src/Makefile.am
core/plugin.c include/core/plugin.h \
core/store.c include/core/store.h \
include/utils/data.h \
- utils/error.c include/utils/error.h \
+ core/error.c include/core/error.h \
utils/llist.c include/utils/llist.h \
utils/strbuf.c include/utils/strbuf.h \
- utils/time.c include/utils/time.h \
+ core/time.c include/core/time.h \
utils/unixsock.c include/utils/unixsock.h
libsysdb_la_CFLAGS = $(AM_CFLAGS)
libsysdb_la_CPPFLAGS = $(AM_CPPFLAGS) $(LTDLINCL)
index 78c238de39d44264f85ee9d4b7f01d739f19cde9..945773983ee173c726049d32e22db59a06000d24 100644 (file)
#include "sysdb.h"
#include "core/plugin.h"
#include "core/store.h"
-#include "utils/error.h"
+#include "core/error.h"
#include "utils/unixsock.h"
#include "liboconfig/utils.h"
index 200edc289fc4379d7fadb73cf2c6e662d81005d2..e151b52ed17af64e0a8f902b8f012c975ebbce84 100644 (file)
#include "sysdb.h"
#include "core/plugin.h"
#include "core/store.h"
-#include "utils/error.h"
+#include "core/error.h"
#include "utils/unixsock.h"
#include "liboconfig/utils.h"
index 84855c65a380e64a47451524bb9f5c10158de24b..8b3804ba22e36144876efadc1440e1b3314bef40 100644 (file)
#include "sysdb.h"
#include "core/plugin.h"
#include "core/store.h"
-#include "utils/error.h"
+#include "core/error.h"
#include "utils/dbi.h"
#include "liboconfig/utils.h"
diff --git a/src/core/error.c b/src/core/error.c
--- /dev/null
+++ b/src/core/error.c
@@ -0,0 +1,284 @@
+/*
+ * SysDB - src/core/error.c
+ * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "core/error.h"
+#include "utils/strbuf.h"
+
+#include <pthread.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <string.h>
+
+#include <stdlib.h>
+
+/*
+ * private data types
+ */
+
+typedef struct {
+ int prio;
+ sdb_strbuf_t *msg;
+ _Bool logged;
+} sdb_error_ctx_t;
+#define SDB_ERROR_INIT { -1, NULL, 1 }
+
+/*
+ * private variables
+ */
+
+static sdb_error_ctx_t default_error_ctx = SDB_ERROR_INIT;
+
+static pthread_key_t error_ctx_key;
+static _Bool error_ctx_key_initialized = 0;
+
+/*
+ * private helper functions
+ */
+
+static void
+sdb_error_ctx_destructor(void *p)
+{
+ sdb_error_ctx_t *ctx = p;
+
+ if (! ctx)
+ return;
+
+ sdb_strbuf_destroy(ctx->msg);
+ free(ctx);
+} /* sdb_error_ctx_destructor */
+
+static void
+sdb_error_ctx_init(void)
+{
+ if (error_ctx_key_initialized)
+ return;
+
+ pthread_key_create(&error_ctx_key, sdb_error_ctx_destructor);
+ error_ctx_key_initialized = 1;
+} /* sdb_error_init */
+
+static sdb_error_ctx_t *
+sdb_error_ctx_create(void)
+{
+ sdb_error_ctx_t *ctx;
+
+ ctx = malloc(sizeof(*ctx));
+ if (! ctx)
+ return NULL;
+
+ *ctx = default_error_ctx;
+ ctx->msg = sdb_strbuf_create(64);
+ if (! ctx->msg) {
+ free(ctx);
+ return NULL;
+ }
+
+ if (! error_ctx_key_initialized)
+ sdb_error_ctx_init();
+ pthread_setspecific(error_ctx_key, ctx);
+ return ctx;
+} /* sdb_error_ctx_create */
+
+static sdb_error_ctx_t *
+sdb_error_get_ctx(void)
+{
+ sdb_error_ctx_t *ctx;
+
+ if (! error_ctx_key_initialized)
+ sdb_error_ctx_init();
+ ctx = pthread_getspecific(error_ctx_key);
+
+ if (! ctx)
+ ctx = sdb_error_ctx_create();
+ if (! ctx)
+ return NULL;
+ return ctx;
+} /* sdb_error_get_ctx */
+
+static int
+sdb_error_vprintf(const char *fmt, va_list ap)
+{
+ sdb_error_ctx_t *ctx;
+
+ ctx = sdb_error_get_ctx();
+ if (! ctx)
+ return -1;
+
+ ctx->logged = 0;
+ return (int)sdb_strbuf_vsprintf(ctx->msg, fmt, ap);
+} /* sdb_error_vprintf */
+
+static int
+sdb_error_vappend(const char *fmt, va_list ap)
+{
+ sdb_error_ctx_t *ctx;
+
+ ctx = sdb_error_get_ctx();
+ if (! ctx)
+ return -1;
+
+ ctx->logged = 0;
+ return (int)sdb_strbuf_vappend(ctx->msg, fmt, ap);
+} /* sdb_error_vappend */
+
+static int
+sdb_do_log(int prio)
+{
+ sdb_error_ctx_t *ctx;
+ int ret;
+
+ ctx = sdb_error_get_ctx();
+ if (! ctx)
+ return -1;
+
+ if (prio >= 0)
+ ctx->prio = prio;
+
+ if (ctx->logged)
+ return 0;
+
+ ret = fprintf(stderr, "[%s] %s\n",
+ SDB_LOG_PRIO_TO_STRING(prio),
+ sdb_strbuf_string(ctx->msg));
+ ctx->logged = 1;
+ return ret;
+} /* sdb_do_log */
+
+/*
+ * public API
+ */
+
+int
+sdb_log(int prio, const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = sdb_error_vprintf(fmt, ap);
+ va_end(ap);
+
+ if (ret > 0)
+ sdb_do_log(prio);
+ return ret;
+} /* sdb_log */
+
+int
+sdb_error_set(const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = sdb_error_vprintf(fmt, ap);
+ va_end(ap);
+
+ return ret;
+} /* sdb_error_set */
+
+int
+sdb_error_append(const char *fmt, ...)
+{
+ va_list ap;
+ int ret;
+
+ va_start(ap, fmt);
+ ret = sdb_error_vappend(fmt, ap);
+ va_end(ap);
+
+ return ret;
+} /* sdb_error_append */
+
+int
+sdb_error_chomp(void)
+{
+ sdb_error_ctx_t *ctx;
+
+ ctx = sdb_error_get_ctx();
+ if (! ctx)
+ return -1;
+
+ sdb_strbuf_chomp(ctx->msg);
+ return 0;
+} /* sdb_error_chomp */
+
+int
+sdb_error_log(int prio)
+{
+ return sdb_do_log(prio);
+} /* sdb_error_log */
+
+const char *
+sdb_error_get(void)
+{
+ sdb_error_ctx_t *ctx;
+
+ ctx = sdb_error_get_ctx();
+ if (! ctx)
+ return "success";
+ return sdb_strbuf_string(ctx->msg);
+} /* sdb_error_get */
+
+int
+sdb_error_get_prio(void)
+{
+ sdb_error_ctx_t *ctx;
+
+ ctx = sdb_error_get_ctx();
+ if (! ctx)
+ return -1;
+ return ctx->prio;
+} /* sdb_error_get_prio */
+
+char *
+sdb_strerror(int errnum, char *strerrbuf, size_t buflen)
+{
+#if STRERROR_R_CHAR_P
+ {
+ char *tmp = strerror_r(errnum, strerrbuf, buflen);
+ if (*strerrbuf = '\0') {
+ if (tmp && (tmp != strerrbuf) && (*tmp != '\0'))
+ strncpy(strerrbuf, tmp, buflen);
+ else
+ snprintf(strerrbuf, buflen, "unknown error #%i "
+ "(strerror_r(3) did not return an error message)",
+ errnum);
+ }
+ }
+#else
+ if (strerror_r(errnum, strerrbuf, buflen))
+ snprintf(strerrbuf, buflen, "unknown error #%i "
+ "(strerror_r(3) failed)", errnum);
+#endif
+
+ strerrbuf[buflen - 1] = '\0';
+ return strerrbuf;
+} /* sdb_strerror */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+
diff --git a/src/core/plugin.c b/src/core/plugin.c
index 5df7059e9c6412b1c49bfc49813563a534f7d031..5fdaca0db885b9ba3c0870ac301cd13c17017602 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
#include "sysdb.h"
#include "core/plugin.h"
-#include "utils/error.h"
+#include "core/error.h"
+#include "core/time.h"
#include "utils/llist.h"
-#include "utils/time.h"
#include <assert.h>
diff --git a/src/core/store.c b/src/core/store.c
index 4e841bac0022040ca77cd5fedcfa55aab1f4e2a1..714a0b39ed18161b07b6bdd3bd856da335abd04d 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
#include "sysdb.h"
#include "core/store.h"
-#include "utils/error.h"
+#include "core/error.h"
#include "utils/llist.h"
#include <assert.h>
diff --git a/src/core/time.c b/src/core/time.c
--- /dev/null
+++ b/src/core/time.c
@@ -0,0 +1,79 @@
+/*
+ * SysDB - src/core/time.c
+ * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "core/time.h"
+
+#include <time.h>
+
+#include <string.h>
+
+/*
+ * public API
+ */
+
+sdb_time_t
+sdb_gettime(void)
+{
+ struct timespec ts_now = { 0, 0 };
+
+ if (clock_gettime(CLOCK_REALTIME, &ts_now))
+ return 0;
+ return TIMESPEC_TO_SDB_TIME(ts_now);
+} /* sdb_gettime */
+
+int
+sdb_sleep(sdb_time_t reg, sdb_time_t *rem)
+{
+ struct timespec ts_reg, ts_rem = { 0, 0 };
+ int status;
+
+ ts_reg.tv_sec = (time_t)SDB_TIME_TO_SECS(reg);
+ ts_reg.tv_nsec = (long int)(reg % (sdb_time_t)1000000000);
+
+ status = nanosleep(&ts_reg, &ts_rem);
+ if (rem)
+ *rem = TIMESPEC_TO_SDB_TIME(ts_rem);
+ return status;
+} /* sdb_sleep */
+
+size_t
+sdb_strftime(char *s, size_t len, const char *format, sdb_time_t t)
+{
+ time_t tstamp;
+ struct tm tm;
+
+ memset(&tm, 0, sizeof(tm));
+
+ tstamp = (time_t)SDB_TIME_TO_SECS(t);
+ if (! localtime_r (&tstamp, &tm))
+ return 0;
+
+ return strftime(s, len, format, &tm);
+} /* sdb_strftime */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+
diff --git a/src/daemon/config.c b/src/daemon/config.c
index ac95b6c6370a653940e2cd66daf52aa48af0fcc5..03bc2b857caad19d8151c46b3cb35e00db896ec0 100644 (file)
--- a/src/daemon/config.c
+++ b/src/daemon/config.c
#include "sysdb.h"
#include "core/plugin.h"
-#include "utils/error.h"
-#include "utils/time.h"
+#include "core/error.h"
+#include "core/time.h"
#include "daemon/config.h"
diff --git a/src/daemon/sysdbd.c b/src/daemon/sysdbd.c
index 99c129657ea9b2a445b557765d9577d9516f4bff..f1992610f2a2164af9d189c8f1324ea6a3265daf 100644 (file)
--- a/src/daemon/sysdbd.c
+++ b/src/daemon/sysdbd.c
#include "sysdb.h"
#include "core/plugin.h"
#include "core/store.h"
-#include "utils/error.h"
+#include "core/error.h"
#include "daemon/config.h"
diff --git a/src/include/core/error.h b/src/include/core/error.h
--- /dev/null
+++ b/src/include/core/error.h
@@ -0,0 +1,141 @@
+/*
+ * SysDB - src/include/core/error.h
+ * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * SysDB error handling:
+ * Error handling in SysDB is done on a by-thread basis, that is, each thread
+ * will use its own memory region to store information about the last reported
+ * error.
+ * Once the error message has been passed to SysDB, it will log the entire
+ * message at once. XXX: currently, SysDB only supports printing the error to
+ * the standard error channel; support for other logging backends will be
+ * added later in a modular fashion.
+ */
+
+#ifndef SDB_CORE_ERROR_H
+#define SDB_CORE_ERROR_H 1
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* max length of any error message */
+#ifndef SDB_MAX_ERROR
+# define SDB_MAX_ERROR 4096
+#endif /* ! SDB_MAX_ERROR */
+
+/* On Linux systems and possibly others, this should be the same as the LOG_
+ * constants defined by syslog. */
+enum {
+ SDB_LOG_EMERG = 0,
+ SDB_LOG_ERR = 3,
+ SDB_LOG_WARNING = 4,
+ SDB_LOG_NOTICE = 5,
+ SDB_LOG_INFO = 6,
+ SDB_LOG_DEBUG = 7,
+};
+#define SDB_LOG_PRIO_TO_STRING(prio) \
+ (((prio) == SDB_LOG_EMERG) ? "EMERG" \
+ : ((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")
+
+/*
+ * 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
+ * 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
+sdb_log(int prio, const char *fmt, ...);
+
+/*
+ * 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
+sdb_error_set(const char *fmt, ...);
+int
+sdb_error_append(const char *fmt, ...);
+
+/*
+ * sdb_error_chomp:
+ * Remove all consecutive newline characters at the end of the error message.
+ */
+int
+sdb_error_chomp(void);
+
+/*
+ * sdb_error_log:
+ * Log the current error message with the specified priority. See sdb_log for
+ * more information.
+ */
+int
+sdb_error_log(int prio);
+
+/*
+ * sdb_error_get:
+ * Get the current error message. The string returned by this function is
+ * owned by SysDB and might point to static memory -- do not modify or free
+ * it.
+ */
+const char *
+sdb_error_get(void);
+
+/*
+ * sdb_error_get_prio:
+ * Get the priority of the last logged error message -- see the SDB_LOG_
+ * constants for details.
+ */
+int
+sdb_error_get_prio(void);
+
+/*
+ * sdb_strerror:
+ * This is a wrapper around the system's strerror function which ensures that
+ * a pointer to the formatted error message is returned.
+ */
+char *
+sdb_strerror(int errnum, char *strerrbuf, size_t buflen);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ! SDB_CORE_ERROR_H */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+
index 1ac243abf9494c11f4ec508407e194cc10e2ce1c..ac8656ab3b36c8a76a10c1abac91feb96fe15d92 100644 (file)
#include "sysdb.h"
#include "core/object.h"
-#include "utils/time.h"
+#include "core/time.h"
#include "liboconfig/oconfig.h"
index 46cd53643a7ec8b1d63a5431d4fde5dc3b94c2fb..6bda96783763f2e0234a5eb089857ed40acc23ff 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
#include "sysdb.h"
#include "core/object.h"
-#include "utils/time.h"
+#include "core/time.h"
#include "utils/llist.h"
#include <stdio.h>
diff --git a/src/include/core/time.h b/src/include/core/time.h
--- /dev/null
+++ b/src/include/core/time.h
@@ -0,0 +1,73 @@
+/*
+ * SysDB - src/include/core/time.h
+ * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+ * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+ * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SDB_CORE_TIME_H
+#define SDB_CORE_TIME_H 1
+
+#include <inttypes.h>
+#include <stdint.h>
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * sdb_time_t:
+ * The time, in nano-seconds, since the epoch.
+ */
+typedef uint64_t sdb_time_t;
+#define PRIscTIME PRIu64
+
+#define SECS_TO_SDB_TIME(s) ((sdb_time_t)(s) * (sdb_time_t)1000000000)
+#define SDB_TIME_TO_SECS(t) ((t) / (sdb_time_t)1000000000)
+
+#define NSECS_TO_SDB_TIME(ns) ((sdb_time_t)ns)
+
+#define DOUBLE_TO_SDB_TIME(d) ((sdb_time_t)((d) * 1000000000.0))
+#define SDB_TIME_TO_DOUBLE(t) ((double)(t) / 1000000000.0)
+
+#define TIMESPEC_TO_SDB_TIME(ts) (SECS_TO_SDB_TIME((ts).tv_sec) \
+ + NSECS_TO_SDB_TIME((ts).tv_nsec))
+
+sdb_time_t
+sdb_gettime(void);
+
+int
+sdb_sleep(sdb_time_t reg, sdb_time_t *rem);
+
+size_t
+sdb_strftime(char *s, size_t len, const char *format, sdb_time_t);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif /* ! SDB_CORE_TIME_H */
+
+/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
+
index 0f38a11cd8234e5fad1aa25e2df49526951f9af7..fc6afca4c2125ed5ac7d5c94d04c095ce1111718 100644 (file)
--- a/src/include/utils/data.h
+++ b/src/include/utils/data.h
#ifndef SDB_UTILS_DATA_H
#define SDB_UTILS_DATA_H 1
-#include "utils/time.h"
+#include "core/time.h"
#include <inttypes.h>
#include <stddef.h>
diff --git a/src/include/utils/error.h b/src/include/utils/error.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * SysDB - src/include/utils/error.h
- * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * SysDB error handling:
- * Error handling in SysDB is done on a by-thread basis, that is, each thread
- * will use its own memory region to store information about the last reported
- * error.
- * Once the error message has been passed to SysDB, it will log the entire
- * message at once. XXX: currently, SysDB only supports printing the error to
- * the standard error channel; support for other logging backends will be
- * added later in a modular fashion.
- */
-
-#ifndef SDB_UTILS_ERROR_H
-#define SDB_UTILS_ERROR_H 1
-
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* max length of any error message */
-#ifndef SDB_MAX_ERROR
-# define SDB_MAX_ERROR 4096
-#endif /* ! SDB_MAX_ERROR */
-
-/* On Linux systems and possibly others, this should be the same as the LOG_
- * constants defined by syslog. */
-enum {
- SDB_LOG_EMERG = 0,
- SDB_LOG_ERR = 3,
- SDB_LOG_WARNING = 4,
- SDB_LOG_NOTICE = 5,
- SDB_LOG_INFO = 6,
- SDB_LOG_DEBUG = 7,
-};
-#define SDB_LOG_PRIO_TO_STRING(prio) \
- (((prio) == SDB_LOG_EMERG) ? "EMERG" \
- : ((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")
-
-/*
- * 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
- * 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
-sdb_log(int prio, const char *fmt, ...);
-
-/*
- * 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
-sdb_error_set(const char *fmt, ...);
-int
-sdb_error_append(const char *fmt, ...);
-
-/*
- * sdb_error_chomp:
- * Remove all consecutive newline characters at the end of the error message.
- */
-int
-sdb_error_chomp(void);
-
-/*
- * sdb_error_log:
- * Log the current error message with the specified priority. See sdb_log for
- * more information.
- */
-int
-sdb_error_log(int prio);
-
-/*
- * sdb_error_get:
- * Get the current error message. The string returned by this function is
- * owned by SysDB and might point to static memory -- do not modify or free
- * it.
- */
-const char *
-sdb_error_get(void);
-
-/*
- * sdb_error_get_prio:
- * Get the priority of the last logged error message -- see the SDB_LOG_
- * constants for details.
- */
-int
-sdb_error_get_prio(void);
-
-/*
- * sdb_strerror:
- * This is a wrapper around the system's strerror function which ensures that
- * a pointer to the formatted error message is returned.
- */
-char *
-sdb_strerror(int errnum, char *strerrbuf, size_t buflen);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* ! SDB_UTILS_ERROR_H */
-
-/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
-
diff --git a/src/include/utils/time.h b/src/include/utils/time.h
--- a/src/include/utils/time.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * SysDB - src/include/utils/time.h
- * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef SDB_UTILS_TIME_H
-#define SDB_UTILS_TIME_H 1
-
-#include <inttypes.h>
-#include <stdint.h>
-#include <stddef.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/*
- * sdb_time_t:
- * The time, in nano-seconds, since the epoch.
- */
-typedef uint64_t sdb_time_t;
-#define PRIscTIME PRIu64
-
-#define SECS_TO_SDB_TIME(s) ((sdb_time_t)(s) * (sdb_time_t)1000000000)
-#define SDB_TIME_TO_SECS(t) ((t) / (sdb_time_t)1000000000)
-
-#define NSECS_TO_SDB_TIME(ns) ((sdb_time_t)ns)
-
-#define DOUBLE_TO_SDB_TIME(d) ((sdb_time_t)((d) * 1000000000.0))
-#define SDB_TIME_TO_DOUBLE(t) ((double)(t) / 1000000000.0)
-
-#define TIMESPEC_TO_SDB_TIME(ts) (SECS_TO_SDB_TIME((ts).tv_sec) \
- + NSECS_TO_SDB_TIME((ts).tv_nsec))
-
-sdb_time_t
-sdb_gettime(void);
-
-int
-sdb_sleep(sdb_time_t reg, sdb_time_t *rem);
-
-size_t
-sdb_strftime(char *s, size_t len, const char *format, sdb_time_t);
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif /* ! SDB_UTILS_TIME_H */
-
-/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
-
diff --git a/src/utils/dbi.c b/src/utils/dbi.c
index f89e46356a8d1b9c2d9ae4dbbcc6aa9141aa9c99..db93857fad42d9103d40c24d243fb48511af807e 100644 (file)
--- a/src/utils/dbi.c
+++ b/src/utils/dbi.c
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include "utils/error.h"
+#include "core/error.h"
#include "utils/dbi.h"
#include <assert.h>
diff --git a/src/utils/error.c b/src/utils/error.c
--- a/src/utils/error.c
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * SysDB - src/utils/error.c
- * Copyright (C) 2013 Sebastian 'tokkee' Harl <sh@tokkee.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "utils/error.h"
-#include "utils/strbuf.h"
-
-#include <pthread.h>
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-
-#include <stdlib.h>
-
-/*
- * private data types
- */
-
-typedef struct {
- int prio;
- sdb_strbuf_t *msg;
- _Bool logged;
-} sdb_error_ctx_t;
-#define SDB_ERROR_INIT { -1, NULL, 1 }
-
-/*
- * private variables
- */
-
-static sdb_error_ctx_t default_error_ctx = SDB_ERROR_INIT;
-
-static pthread_key_t error_ctx_key;
-static _Bool error_ctx_key_initialized = 0;
-
-/*
- * private helper functions
- */
-
-static void
-sdb_error_ctx_destructor(void *p)
-{
- sdb_error_ctx_t *ctx = p;
-
- if (! ctx)
- return;
-
- sdb_strbuf_destroy(ctx->msg);
- free(ctx);
-} /* sdb_error_ctx_destructor */
-
-static void
-sdb_error_ctx_init(void)
-{
- if (error_ctx_key_initialized)
- return;
-
- pthread_key_create(&error_ctx_key, sdb_error_ctx_destructor);
- error_ctx_key_initialized = 1;
-} /* sdb_error_init */
-
-static sdb_error_ctx_t *
-sdb_error_ctx_create(void)
-{
- sdb_error_ctx_t *ctx;
-
- ctx = malloc(sizeof(*ctx));
- if (! ctx)
- return NULL;
-
- *ctx = default_error_ctx;
- ctx->msg = sdb_strbuf_create(64);
- if (! ctx->msg) {
- free(ctx);
- return NULL;
- }
-
- if (! error_ctx_key_initialized)
- sdb_error_ctx_init();
- pthread_setspecific(error_ctx_key, ctx);
- return ctx;
-} /* sdb_error_ctx_create */
-
-static sdb_error_ctx_t *
-sdb_error_get_ctx(void)
-{
- sdb_error_ctx_t *ctx;
-
- if (! error_ctx_key_initialized)
- sdb_error_ctx_init();
- ctx = pthread_getspecific(error_ctx_key);
-
- if (! ctx)
- ctx = sdb_error_ctx_create();
- if (! ctx)
- return NULL;
- return ctx;
-} /* sdb_error_get_ctx */
-
-static int
-sdb_error_vprintf(const char *fmt, va_list ap)
-{
- sdb_error_ctx_t *ctx;
-
- ctx = sdb_error_get_ctx();
- if (! ctx)
- return -1;
-
- ctx->logged = 0;
- return (int)sdb_strbuf_vsprintf(ctx->msg, fmt, ap);
-} /* sdb_error_vprintf */
-
-static int
-sdb_error_vappend(const char *fmt, va_list ap)
-{
- sdb_error_ctx_t *ctx;
-
- ctx = sdb_error_get_ctx();
- if (! ctx)
- return -1;
-
- ctx->logged = 0;
- return (int)sdb_strbuf_vappend(ctx->msg, fmt, ap);
-} /* sdb_error_vappend */
-
-static int
-sdb_do_log(int prio)
-{
- sdb_error_ctx_t *ctx;
- int ret;
-
- ctx = sdb_error_get_ctx();
- if (! ctx)
- return -1;
-
- if (prio >= 0)
- ctx->prio = prio;
-
- if (ctx->logged)
- return 0;
-
- ret = fprintf(stderr, "[%s] %s\n",
- SDB_LOG_PRIO_TO_STRING(prio),
- sdb_strbuf_string(ctx->msg));
- ctx->logged = 1;
- return ret;
-} /* sdb_do_log */
-
-/*
- * public API
- */
-
-int
-sdb_log(int prio, const char *fmt, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, fmt);
- ret = sdb_error_vprintf(fmt, ap);
- va_end(ap);
-
- if (ret > 0)
- sdb_do_log(prio);
- return ret;
-} /* sdb_log */
-
-int
-sdb_error_set(const char *fmt, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, fmt);
- ret = sdb_error_vprintf(fmt, ap);
- va_end(ap);
-
- return ret;
-} /* sdb_error_set */
-
-int
-sdb_error_append(const char *fmt, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, fmt);
- ret = sdb_error_vappend(fmt, ap);
- va_end(ap);
-
- return ret;
-} /* sdb_error_append */
-
-int
-sdb_error_chomp(void)
-{
- sdb_error_ctx_t *ctx;
-
- ctx = sdb_error_get_ctx();
- if (! ctx)
- return -1;
-
- sdb_strbuf_chomp(ctx->msg);
- return 0;
-} /* sdb_error_chomp */
-
-int
-sdb_error_log(int prio)
-{
- return sdb_do_log(prio);
-} /* sdb_error_log */
-
-const char *
-sdb_error_get(void)
-{
- sdb_error_ctx_t *ctx;
-
- ctx = sdb_error_get_ctx();
- if (! ctx)
- return "success";
- return sdb_strbuf_string(ctx->msg);
-} /* sdb_error_get */
-
-int
-sdb_error_get_prio(void)
-{
- sdb_error_ctx_t *ctx;
-
- ctx = sdb_error_get_ctx();
- if (! ctx)
- return -1;
- return ctx->prio;
-} /* sdb_error_get_prio */
-
-char *
-sdb_strerror(int errnum, char *strerrbuf, size_t buflen)
-{
-#if STRERROR_R_CHAR_P
- {
- char *tmp = strerror_r(errnum, strerrbuf, buflen);
- if (*strerrbuf = '\0') {
- if (tmp && (tmp != strerrbuf) && (*tmp != '\0'))
- strncpy(strerrbuf, tmp, buflen);
- else
- snprintf(strerrbuf, buflen, "unknown error #%i "
- "(strerror_r(3) did not return an error message)",
- errnum);
- }
- }
-#else
- if (strerror_r(errnum, strerrbuf, buflen))
- snprintf(strerrbuf, buflen, "unknown error #%i "
- "(strerror_r(3) failed)", errnum);
-#endif
-
- strerrbuf[buflen - 1] = '\0';
- return strerrbuf;
-} /* sdb_strerror */
-
-/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
-
diff --git a/src/utils/time.c b/src/utils/time.c
--- a/src/utils/time.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * SysDB - src/utils/time.c
- * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
- * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
- * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
- * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
- * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "utils/time.h"
-
-#include <time.h>
-
-#include <string.h>
-
-/*
- * public API
- */
-
-sdb_time_t
-sdb_gettime(void)
-{
- struct timespec ts_now = { 0, 0 };
-
- if (clock_gettime(CLOCK_REALTIME, &ts_now))
- return 0;
- return TIMESPEC_TO_SDB_TIME(ts_now);
-} /* sdb_gettime */
-
-int
-sdb_sleep(sdb_time_t reg, sdb_time_t *rem)
-{
- struct timespec ts_reg, ts_rem = { 0, 0 };
- int status;
-
- ts_reg.tv_sec = (time_t)SDB_TIME_TO_SECS(reg);
- ts_reg.tv_nsec = (long int)(reg % (sdb_time_t)1000000000);
-
- status = nanosleep(&ts_reg, &ts_rem);
- if (rem)
- *rem = TIMESPEC_TO_SDB_TIME(ts_rem);
- return status;
-} /* sdb_sleep */
-
-size_t
-sdb_strftime(char *s, size_t len, const char *format, sdb_time_t t)
-{
- time_t tstamp;
- struct tm tm;
-
- memset(&tm, 0, sizeof(tm));
-
- tstamp = (time_t)SDB_TIME_TO_SECS(t);
- if (! localtime_r (&tstamp, &tm))
- return 0;
-
- return strftime(s, len, format, &tm);
-} /* sdb_strftime */
-
-/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
-
diff --git a/src/utils/unixsock.c b/src/utils/unixsock.c
index 8c0abb2558a7c233bc4836ae3d8e953e91eede61..138205d936bfc6573d08b99c77246f7c93e103ea 100644 (file)
--- a/src/utils/unixsock.c
+++ b/src/utils/unixsock.c
*/
#include "utils/unixsock.h"
-#include "utils/error.h"
+#include "core/error.h"
#include <assert.h>
#include <errno.h>