Commit 5dc0078c authored by Marek Vavrusa's avatar Marek Vavrusa

Unified error codes.

fixes #1772 @2.5h
parent fd3a8bb1
......@@ -49,8 +49,6 @@ src/libknot/util/utils.h
src/libknot/util/utils.c
src/libknot/util/descriptor.h
src/libknot/util/descriptor.c
src/libknot/util/libknot_error.c
src/libknot/util/error.h
src/libknot/zone/zonedb.h
src/libknot/zone/zonedb.c
src/libknot/zone/node.h
......@@ -91,6 +89,8 @@ src/common/evqueue.c
src/common/evqueue.h
src/common/evsched.c
src/common/evsched.h
src/common/errcode.h
src/common/errcode.c
src/common/errors.h
src/common/errors.c
src/common/acl.c
......@@ -135,8 +135,6 @@ src/knot/ctl/knotc_main.c
src/knot/ctl/process.c
src/knot/ctl/process.h
src/knot/other/debug.h
src/knot/other/error.c
src/knot/other/error.h
src/knot/stat/gatherer.c
src/knot/stat/gatherer.h
src/knot/stat/stat.h
......
......@@ -150,7 +150,6 @@ knotd_SOURCES = \
noinst_LTLIBRARIES = libknot.la libknotd.la libknots.la
libknot_la_SOURCES = \
libknot/util/libknot_error.c \
libknot/util/utils.c \
libknot/util/debug.c \
libknot/util/debug.h \
......@@ -249,6 +248,8 @@ libknots_la_SOURCES = \
common/ref.c \
common/errors.h \
common/errors.c \
common/errcode.h \
common/errcode.c \
common/dSFMT.h \
common/dSFMT-params.h \
common/dSFMT-params521.h \
......@@ -273,8 +274,6 @@ libknotd_la_SOURCES = \
knot/stat/stat.h \
knot/common.h \
knot/other/debug.h \
knot/other/error.h \
knot/other/error.c \
knot/conf/cf-parse.y \
knot/conf/cf-lex.l \
knot/conf/conf.c \
......
......@@ -14,28 +14,46 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "util/error.h"
#include "common/errcode.h"
#include "common/errors.h"
const error_table_t knot_error_msgs[KNOT_ERROR_COUNT] = {
const error_table_t knot_error_msgs[] = {
{KNOT_EOK, "OK"},
{KNOT_ERROR, "General error."},
/* TSIG errors. */
{KNOT_TSIG_EBADSIG, "Failed to verify TSIG MAC." },
{KNOT_TSIG_EBADKEY, "TSIG key not recognized or invalid." },
{KNOT_TSIG_EBADTIME, "TSIG signing time out of range." },
/* Directly mapped error codes. */
{KNOT_ENOMEM, "Not enough memory."},
{KNOT_EINVAL, "Invalid parameter."},
{KNOT_ENOTSUP, "Operation not supported."},
{KNOT_EBUSY, "Requested resource is busy."},
{KNOT_EAGAIN, "OS lacked necessary resources."},
{KNOT_EACCES, "Operation not permitted."},
{KNOT_ECONNREFUSED, "Connection refused."},
{KNOT_EISCONN, "Already connected."},
{KNOT_EADDRINUSE, "Address already in use."},
{KNOT_ENOENT, "Resource not found."},
{KNOT_ERANGE, "Value is out of range."},
{KNOT_EBADARG, "Wrong argument supplied."},
/* General errors. */
{KNOT_ERROR, "General error."},
{KNOT_ENOTRUNNING, "Resource is not running."},
{KNOT_EPARSEFAIL, "Parser failed."},
{KNOT_ENOIPV6, "IPv6 support disabled."},
{KNOT_EEXPIRED, "Resource is expired."},
{KNOT_EUPTODATE, "Zone is up-to-date."},
{KNOT_EFEWDATA, "Not enough data to parse."},
{KNOT_ESPACE, "Not enough space provided."},
{KNOT_EMALF, "Malformed data."},
{KNOT_ENOENT, "Resource not found."},
{KNOT_EACCES, "Permission to perform requested operation is denied."},
{KNOT_ECRYPTO, "Error in crypto library."},
{KNOT_ENSEC3PAR, "Missing or wrong NSEC3PARAM record."},
{KNOT_ENSEC3CHAIN, "Missing or wrong NSEC3 chain in the zone."},
{KNOT_EBADZONE, "Name does not belong to the zone."},
{KNOT_EHASH, "Error in hash table."},
{KNOT_EZONEIN, "Error inserting zone."},
{KNOT_EZONEINVAL, "Invalid zone file."},
{KNOT_ENOZONE, "No such zone found."},
{KNOT_ENONODE, "No such node in zone found."},
{KNOT_ENORRSET, "No such RRSet found."},
......@@ -47,12 +65,10 @@ const error_table_t knot_error_msgs[KNOT_ERROR_COUNT] = {
{KNOT_ENOIXFR, "Transfer is not IXFR (is in AXFR format)."},
{KNOT_EXFRREFUSED, "Zone transfer refused by the server."},
{KNOT_EXFRDENIED, "Transfer not allowed."},
{KNOT_TSIG_EBADSIG, "Failed to verify TSIG MAC." },
{KNOT_TSIG_EBADKEY, "TSIG key not recognized or invalid." },
{KNOT_TSIG_EBADTIME, "TSIG signing time out of range." },
{KNOT_ECONN, "Connection reset."},
{KNOT_EIXFRSPACE, "IXFR reply did not fit in."},
{KNOT_ECNAME, "CNAME loop found in zone."},
{KNOT_ENODIFF, "Cannot create zone diff."},
{KNOT_ERROR, 0}
};
/*!
* \file error.h
* \file errcode.h
*
* \author Lubos Slovak <lubos.slovak@nic.cz>
* \author Marek Vavrusa <marek.vavrusa@nic.cz>
*
* \brief Error codes and function for getting error message.
*
* \addtogroup libknot
* \addtogroup common_lib
* @{
*/
/* Copyright (C) 2011 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
......@@ -24,38 +25,49 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _KNOT_ERROR_H_
#define _KNOT_ERROR_H_
#ifndef _KNOTD_COMMON_ERRCODE_H_
#define _KNOTD_COMMON_ERRCODE_H_
#include "common/errors.h"
/*! \brief Error codes used in the library. */
enum knot_error {
KNOT_EOK = 0, /*!< OK */
KNOT_EOK = 0, /*!< OK */
/* TSIG errors. */
KNOT_TSIG_EBADSIG = -16, /*!< Failed to verify TSIG MAC. */
KNOT_TSIG_EBADKEY = -17, /*!< TSIG key not recognized or invalid. */
KNOT_TSIG_EBADTIME = -18,/*!< TSIG signing time out of range. */
KNOT_TSIG_EBADSIG = -16, /*!< Failed to verify TSIG MAC. */
KNOT_TSIG_EBADKEY = -17, /*!< TSIG key not recognized or invalid. */
KNOT_TSIG_EBADTIME = -18, /*!< TSIG signing time out of range. */
/* Directly mapped error codes. */
KNOT_ENOMEM = -ENOMEM, /*!< Out of memory. */
KNOT_EINVAL = -EINVAL, /*!< Invalid parameter passed. */
KNOT_ENOTSUP = -ENOTSUP, /*!< Parameter not supported. */
KNOT_EBUSY = -EBUSY, /*!< Requested resource is busy. */
KNOT_EAGAIN = -EAGAIN, /*!< OS lacked necessary resources. */
KNOT_EACCES = -EACCES, /*!< Permission is denied. */
KNOT_ECONNREFUSED = -ECONNREFUSED, /*!< Connection is refused. */
KNOT_EISCONN = -EISCONN, /*!< Already connected. */
KNOT_EADDRINUSE = -EADDRINUSE, /*!< Address already in use. */
KNOT_ENOENT = -ENOENT, /*!< Resource not found. */
KNOT_ERANGE = -ERANGE, /*!< Value is out of range. */
/* General errors. */
KNOT_ERROR = -10000, /*!< General error. */
KNOT_ENOMEM, /*!< Not enough memory. */
KNOT_ENOTSUP, /*!< Operation not supported. */
KNOT_EAGAIN, /*!< OS lacked necessary resources. */
KNOT_ERANGE, /*!< Value is out of range. */
KNOT_EBADARG, /*!< Wrong argument supported. */
KNOT_ENOTRUNNING, /*!< Resource is not running. */
KNOT_EPARSEFAIL, /*!< Parser fail. */
KNOT_ENOIPV6, /*!< No IPv6 support. */
KNOT_EEXPIRED, /*!< Resource is expired. */
KNOT_EUPTODATE, /*!< Zone is up-to-date. */
KNOT_EFEWDATA, /*!< Not enough data to parse. */
KNOT_ESPACE, /*!< Not enough space provided. */
KNOT_EMALF, /*!< Malformed data. */
KNOT_ENOENT, /*!< Resource not found. */
KNOT_EACCES, /*!< Permission is denied. */
KNOT_ECRYPTO, /*!< Error in crypto library. */
KNOT_ENSEC3PAR, /*!< Missing or wrong NSEC3PARAM record. */
KNOT_ENSEC3CHAIN, /*!< Missing or wrong NSEC3 chain in the zone. */
KNOT_EBADZONE, /*!< Domain name does not belong to the zone. */
KNOT_EHASH, /*!< Error in hash table. */
KNOT_EZONEIN, /*!< Error inserting zone. */
KNOT_EZONEINVAL, /*!< Invalid zone file. */
KNOT_ENOZONE, /*!< No such zone found. */
KNOT_ENONODE, /*!< No such node in zone found. */
KNOT_ENORRSET, /*!< No such RRSet found. */
......@@ -70,12 +82,11 @@ enum knot_error {
KNOT_ECONN, /*!< Connection reset. */
KNOT_EIXFRSPACE, /*!< IXFR reply did not fit in. */
KNOT_ECNAME, /*!< CNAME loop found in zone. */
KNOT_ENODIFF, /*!< No zone diff can be created. */
KNOT_ERROR_COUNT = 37
KNOT_ENODIFF /*!< No zone diff can be created. */
};
/*! \brief Table linking error messages to error codes. */
extern const error_table_t knot_error_msgs[KNOT_ERROR_COUNT];
extern const error_table_t knot_error_msgs[];
/*!
* \brief Returns error message for the given error code.
......@@ -89,6 +100,18 @@ static inline const char *knot_strerror(int code)
return error_to_str((const error_table_t*)knot_error_msgs, code);
}
#endif /* _KNOT_ERROR_H_ */
/*!
* \brief errno mapper that automatically prepends fallback value.
*
* \see map_errno()
*
* \param err POSIX errno.
* \param ... List of handled codes.
*
* \return Mapped error code.
*/
#define knot_map_errno(err...) map_errno(KNOT_ERROR, err);
#endif /* _KNOTD_COMMON_ERRCODE_H_ */
/*! @} */
......@@ -58,7 +58,7 @@ int _map_errno(int fallback_value, int arg0, ...)
va_list ap;
va_start(ap, arg0);
/* KNOTD_ERROR serves as a sentinel. */
/* KNOT_ERROR serves as a sentinel. */
for (int c = arg0; c != 0; c = va_arg(ap, int)) {
/* Error code matches with mapped. */
......
......@@ -26,7 +26,6 @@
#include "common/log.h"
#include "common/lists.h"
#include "knot/common.h"
#include "knot/other/error.h"
#include "knot/conf/conf.h"
/*! Log source table. */
......@@ -43,7 +42,7 @@ int log_setup(int logfiles)
{
/* Check facilities count. */
if (logfiles < 0) {
return KNOTD_EINVAL;
return KNOT_EINVAL;
}
/* Ensure minimum facilities count. */
......@@ -57,7 +56,7 @@ int log_setup(int logfiles)
LOG_FCL_SIZE = 0;
LOG_FCL = malloc(new_size);
if (!LOG_FCL) {
return KNOTD_ENOMEM;
return KNOT_ENOMEM;
}
/* Reserve space for logfiles. */
......@@ -66,14 +65,14 @@ int log_setup(int logfiles)
if (!LOG_FDS) {
free(LOG_FCL);
LOG_FCL = 0;
return KNOTD_ENOMEM;
return KNOT_ENOMEM;
}
memset(LOG_FDS, 0, sizeof(FILE*) * logfiles);
}
memset(LOG_FCL, 0, new_size);
LOG_FCL_SIZE = new_size; // Assign only when all is set
return KNOTD_EOK;
return KNOT_EOK;
}
......@@ -87,7 +86,7 @@ int log_init()
LOG_FDS_OPEN = 0;
/* Setup initial state. */
int ret = KNOTD_EOK;
int ret = KNOT_EOK;
int emask = LOG_MASK(LOG_WARNING)|LOG_MASK(LOG_ERR)|LOG_MASK(LOG_FATAL);
int imask = LOG_MASK(LOG_INFO)|LOG_MASK(LOG_NOTICE);
......@@ -138,14 +137,14 @@ int log_isopen()
int log_open_file(const char* filename)
{
// Check facility
if (unlikely(!LOG_FCL_SIZE || LOGT_FILE + LOG_FDS_OPEN >= LOG_FCL_SIZE)) {
return KNOTD_ERROR;
if (knot_unlikely(!LOG_FCL_SIZE || LOGT_FILE + LOG_FDS_OPEN >= LOG_FCL_SIZE)) {
return KNOT_ERROR;
}
// Open file
LOG_FDS[LOG_FDS_OPEN] = fopen(filename, "a");
if (!LOG_FDS[LOG_FDS_OPEN]) {
return KNOTD_EINVAL;
return KNOT_EINVAL;
}
// Disable buffering
......@@ -157,7 +156,7 @@ int log_open_file(const char* filename)
uint8_t log_levels(int facility, logsrc_t src)
{
// Check facility
if (unlikely(!LOG_FCL_SIZE || facility >= LOG_FCL_SIZE)) {
if (knot_unlikely(!LOG_FCL_SIZE || facility >= LOG_FCL_SIZE)) {
return 0;
}
......@@ -167,8 +166,8 @@ uint8_t log_levels(int facility, logsrc_t src)
int log_levels_set(int facility, logsrc_t src, uint8_t levels)
{
// Check facility
if (unlikely(!LOG_FCL_SIZE || facility >= LOG_FCL_SIZE)) {
return KNOTD_EINVAL;
if (knot_unlikely(!LOG_FCL_SIZE || facility >= LOG_FCL_SIZE)) {
return KNOT_EINVAL;
}
// Get facility pointer from offset
......@@ -184,7 +183,7 @@ int log_levels_set(int facility, logsrc_t src, uint8_t levels)
}
}
return KNOTD_EOK;
return KNOT_EOK;
}
int log_levels_add(int facility, logsrc_t src, uint8_t levels)
......@@ -196,7 +195,7 @@ int log_levels_add(int facility, logsrc_t src, uint8_t levels)
static int _log_msg(logsrc_t src, int level, const char *msg)
{
if(!log_isopen()) {
return KNOTD_ERROR;
return KNOT_ERROR;
}
int ret = 0;
......@@ -250,7 +249,7 @@ static int _log_msg(logsrc_t src, int level, const char *msg)
}
if (ret < 0) {
return KNOTD_EINVAL;
return KNOT_EINVAL;
}
return ret;
......@@ -278,7 +277,7 @@ int log_msg(logsrc_t src, int level, const char *msg, ...)
/* Prepend prefix. */
int plen = strlen(prefix);
if (plen > buflen) {
return KNOTD_ENOMEM;
return KNOT_ENOMEM;
}
if (plen > 0) {
strncpy(buf, prefix, plen + 1);
......
......@@ -73,8 +73,8 @@ typedef enum {
*
* \param logfiles Number of extra logfiles.
*
* \retval KNOTD_EOK on success.
* \retval KNOTD_EINVAL invalid number of logfiles (negative).
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid number of logfiles (negative).
*/
int log_setup(int logfiles);
......@@ -83,8 +83,8 @@ int log_setup(int logfiles);
*
* \see syslog.h
*
* \retval KNOTD_EOK on success.
* \retval KNOTD_ENOMEM out of memory error.
* \retval KNOT_EOK on success.
* \retval KNOT_ENOMEM out of memory error.
*/
int log_init();
......@@ -112,8 +112,8 @@ int log_isopen();
* \param filename File path.
*
* \retval associated facility index on success.
* \retval KNOTD_EINVAL filename cannot be opened for writing.
* \retval KNOTD_ERROR unspecified error.
* \retval KNOT_EINVAL filename cannot be opened for writing.
* \retval KNOT_ERROR unspecified error.
*/
int log_open_file(const char* filename);
......@@ -135,8 +135,8 @@ uint8_t log_levels(int facility, logsrc_t src);
* \param src Logging source (LOG_SERVER...LOG_ANY).
* \param levels Bitmask of specified log levels.
*
* \retval KNOTD_EOK on success.
* \retval KNOTD_EINVAL invalid parameters (facility out of range).
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters (facility out of range).
*/
int log_levels_set(int facility, logsrc_t src, uint8_t levels);
......@@ -150,8 +150,8 @@ int log_levels_set(int facility, logsrc_t src, uint8_t levels);
* \param src Logging source (LOG_SERVER...LOG_ANY).
* \param levels Bitmask of specified log levels.
*
* \retval KNOTD_EOK on success.
* \retval KNOTD_EINVAL invalid parameters (facility out of range).
* \retval KNOT_EOK on success.
* \retval KNOT_EINVAL invalid parameters (facility out of range).
*/
int log_levels_add(int facility, logsrc_t src, uint8_t levels);
......@@ -166,8 +166,8 @@ int log_levels_add(int facility, logsrc_t src, uint8_t levels);
*
* \retval Number of logged bytes on success.
* \retval 0 When the message is ignored.
* \retval KNOTD_EINVAL invalid parameters.
* \retval KNOTD_ERROR unspecified error.
* \retval KNOT_EINVAL invalid parameters.
* \retval KNOT_ERROR unspecified error.
*/
int log_msg(logsrc_t src, int level, const char *msg, ...)
__attribute__((format(printf, 3, 4)));
......
......@@ -42,11 +42,11 @@
#endif
/* Optimisation macros. */
#ifndef likely
#define likely(x) __builtin_expect((x),1)
#ifndef knot_likely
#define knot_likely(x) __builtin_expect((x),1)
#endif
#ifndef unlikely
#define unlikely(x) __builtin_expect((x),0)
#ifndef knot_unlikely
#define knot_unlikely(x) __builtin_expect((x),0)
#endif
#ifdef MEM_DEBUG
......
......@@ -338,7 +338,7 @@ slab_t* slab_create(slab_cache_t* cache)
slab_t* slab = slab_depot_alloc(cache->bufsize);
if (unlikely(slab == 0)) {
if (knot_unlikely(slab == 0)) {
dbg_mem("%s: failed to allocate aligned memory block\n",
__func__);
return 0;
......@@ -361,7 +361,7 @@ slab_t* slab_create(slab_cache_t* cache)
/* Ensure the item size can hold at least a size of ptr. */
size_t item_size = slab->bufsize;
if (unlikely(item_size < SLAB_MIN_BUFLEN)) {
if (knot_unlikely(item_size < SLAB_MIN_BUFLEN)) {
item_size = SLAB_MIN_BUFLEN;
}
......@@ -369,7 +369,7 @@ slab_t* slab_create(slab_cache_t* cache)
size_t data_size = size - sizeof(slab_t);
#ifdef MEM_COLORING
size_t free_space = data_size % item_size;
if (unlikely(free_space < SLAB_MINCOLOR)) {
if (knot_unlikely(free_space < SLAB_MINCOLOR)) {
free_space = SLAB_MINCOLOR;
}
......@@ -439,12 +439,12 @@ void* slab_alloc(slab_t* slab)
#endif
// Move to full?
if (unlikely(slab->bufs_free == 0)) {
if (knot_unlikely(slab->bufs_free == 0)) {
slab_list_move(&slab->cache->slabs_full, slab);
} else {
#ifdef MEM_SLAB_CAP
// Mark not empty?
if (unlikely(slab->bufs_free == slab->bufs_count - 1)) {
if (knot_unlikely(slab->bufs_free == slab->bufs_count - 1)) {
--slab->cache->empty;
}
#endif
......@@ -456,7 +456,7 @@ void* slab_alloc(slab_t* slab)
void slab_free(void* ptr)
{
// Null pointer check
if (unlikely(!ptr)) {
if (knot_unlikely(!ptr)) {
return;
}
......@@ -478,12 +478,12 @@ void slab_free(void* ptr)
#endif
// Return to partial
if(unlikely(slab->bufs_free == 1)) {
if(knot_unlikely(slab->bufs_free == 1)) {
slab_list_move(&slab->cache->slabs_free, slab);
} else {
#ifdef MEM_SLAB_CAP
// Recycle if empty
if(unlikely(slab_isempty(slab))) {
if(knot_unlikely(slab_isempty(slab))) {
if(slab->cache->empty == MEM_SLAB_CAP) {
slab_destroy(&slab);
} else {
......@@ -513,7 +513,7 @@ void slab_free(void* ptr)
int slab_cache_init(slab_cache_t* cache, size_t bufsize)
{
if (unlikely(!bufsize)) {
if (knot_unlikely(!bufsize)) {
return -1;
}
......@@ -609,7 +609,7 @@ void slab_alloc_destroy(slab_alloc_t* alloc)
void* slab_alloc_alloc(slab_alloc_t* alloc, size_t size)
{
// Invalid size check
if (unlikely(!size)) {
if (knot_unlikely(!size)) {
return 0;
}
......@@ -618,7 +618,7 @@ void* slab_alloc_alloc(slab_alloc_t* alloc, size_t size)
size += sizeof(int);
#endif
// Directly map large block
if (unlikely(size > SLAB_SIZE/2)) {
if (knot_unlikely(size > SLAB_SIZE/2)) {
// Map block
size += sizeof(slab_obj_t);
......@@ -649,10 +649,10 @@ void* slab_alloc_alloc(slab_alloc_t* alloc, size_t size)
unsigned cache_id = slab_cache_id(size);
// Check if associated cache exists
if (unlikely(alloc->caches[cache_id] == 0)) {
if (knot_unlikely(alloc->caches[cache_id] == 0)) {
// Assert minimum cache size
if (unlikely(size < SLAB_MIN_BUFLEN)) {
if (knot_unlikely(size < SLAB_MIN_BUFLEN)) {
size = SLAB_MIN_BUFLEN;
}
......
......@@ -80,19 +80,20 @@ typedef unsigned int uint; /*!< \brief Unsigned. */
#include "common/latency.h"
#include "common/print.h"
#include "common/log.h"
#include "common/errcode.h"
#include "knot/other/debug.h"
/*! \brief Eliminate compiler warning with unused parameters. */
#define UNUSED(param) (void)(param)
/* Optimisation macros. */
#ifndef likely
#ifndef knot_likely
/*! \brief Optimize for x to be true value. */
#define likely(x) __builtin_expect((x),1)
#define knot_likely(x) __builtin_expect((x),1)
#endif
#ifndef unlikely
#ifndef knot_unlikely
/*! \brief Optimize for x to be false value. */
#define unlikely(x) __builtin_expect((x),0)
#define knot_unlikely(x) __builtin_expect((x),0)
#endif
/*! \todo Refactor theese. We should have an allocator function handling this.*/
......
......@@ -26,7 +26,6 @@
#include <urcu.h>
#include "knot/conf/conf.h"
#include "knot/common.h"
#include "knot/other/error.h"
/*
* Defaults.
......@@ -70,7 +69,7 @@ void cf_error(void *scanner, const char *msg)
new_config->filename, msg, lineno, text);
_parser_res = KNOTD_EPARSEFAIL;
_parser_res = KNOT_EPARSEFAIL;
}
/*!
......@@ -107,7 +106,7 @@ static int conf_process(conf_t *conf)
if (conf->storage == NULL) {
conf->storage = strdup("/var/lib/"PROJECT_EXEC);
if (conf->storage == NULL) {
return KNOTD_ENOMEM;
return KNOT_ENOMEM;
}
}
......@@ -119,25 +118,25 @@ static int conf_process(conf_t *conf)
if (stat(conf->storage, &st) == -1) {
log_server_error("Could not open storage directory '%s'\n", conf->storage);
// I assume that conf->* is freed elsewhere
return KNOTD_EINVAL;
return KNOT_EINVAL;
}
// Storage directory is a directory?
if (S_ISDIR(st.st_mode) == 0) {
log_server_error("Configured storage '%s' not a directory\n", conf->storage);
return KNOTD_EINVAL;
return KNOT_EINVAL;
}
// Create PID file
if (conf->pidfile == NULL) {
conf->pidfile = strcdup(conf->storage, "/" PID_FILE);
if (conf->pidfile == NULL) {
return KNOTD_ENOMEM;
return KNOT_ENOMEM;
}
}
// Postprocess zones
int ret = KNOTD_EOK;
int ret = KNOT_EOK;
node *n = 0;
WALK_LIST (n, conf->zones) {
conf_zone_t *zone = (conf_zone_t*)n;
......@@ -194,7 +193,7 @@ static int conf_process(conf_t *conf)
free(zone->file);
zone->file = ap;
} else {
ret = KNOTD_ENOMEM;
ret = KNOT_ENOMEM;
continue;
}
}
......@@ -203,7 +202,7 @@ static int conf_process(conf_t *conf)
zone->file = strcpath(zone->file);
if (zone->file == NULL) {
zone->db = NULL;
ret = KNOTD_ENOMEM;
ret = KNOT_ENOMEM;
continue;
}
......@@ -214,7 +213,7 @@ static int conf_process(conf_t *conf)
char *dest = malloc(size);
if (dest == NULL) {
zone->db = NULL; /* Not enough memory. */
ret = KNOTD_ENOMEM; /* Error report. */
ret = KNOT_ENOMEM; /* Error report. */
continue;
}
char *dpos = dest;
......@@ -243,7 +242,7 @@ static int conf_process(conf_t *conf)
dest = malloc(size);
if (dest == NULL) {
zone->ixfr_db = NULL; /* Not enough memory. */
ret = KNOTD_ENOMEM; /* Error report. */
ret = KNOT_ENOMEM; /* Error report. */
continue;
}
dpos = dest;
......@@ -342,10 +341,10 @@ void __attribute__ ((destructor)) conf_deinit()
static int conf_fparser(conf_t *conf)
{
if (!conf->filename) {
return KNOTD_EINVAL;
return KNOT_EINVAL;
}
int ret = KNOTD_EOK;
int ret = KNOT_EOK;
pthread_mutex_lock(&_parser_lock);
// {
// Hook new configuration
......@@ -353,11 +352,11 @@ static int conf_fparser(conf_t *conf)
FILE *f = fopen(conf->filename, "r");
if (f == 0) {
pthread_mutex_unlock(&_parser_lock);
return KNOTD_ENOENT;
return KNOT_ENOENT;
}
// Parse config
_parser_res = KNOTD_EOK;
_parser_res = KNOT_EOK;
new_config->filename = conf->filename;
void *sc = NULL;
cf_lex_init(&sc);
......@@ -377,17 +376,17 @@ static int conf_fparser(conf_t *conf)
static int conf_strparser(conf_t *conf, const char *src)
{
if (!src) {
return KNOTD_EINVAL;
return KNOT_EINVAL;
}
int ret = KNOTD_EOK;
int ret = KNOT_EOK;
pthread_mutex_lock(&_parser_lock);
// {
// Hook new configuration
new_config = conf;
// Parse config
_parser_res = KNOTD_EOK;
_parser_res = KNOT_EOK;
char *oldfn = new_config->filename;
new_config->filename = "(stdin)";
void *sc = NULL;
......@@ -442,7 +441,7 @@ int conf_add_hook(conf_t * conf, int sections,
{
conf_hook_t *hook = malloc(sizeof(conf_hook_t));
if (!hook) {
return KNOTD_ENOMEM;
return KNOT_ENOMEM;
}
hook->sections = sections;
......@@ -451,7 +450,7 @@ int conf_add_hook(conf_t * conf, int sections,
add_tail(&conf->hooks, &hook->n);
++conf->hooks_count;
return KNOTD_EOK;
return KNOT_EOK;
}
int conf_parse(conf_t *conf)
......@@ -467,10 +466,10 @@ int conf_parse(conf_t *conf)
}
if (ret < 0) {
return KNOTD_EPARSEFAIL;
return KNOT_EPARSEFAIL;
}