Commit 7cccac52 authored by Daniel Salzman's avatar Daniel Salzman

libdnssec: remove thread local code from dnssec_strerror + refactoring

parent 4a40d490
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> /* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -104,7 +104,7 @@ enum dnssec_error { ...@@ -104,7 +104,7 @@ enum dnssec_error {
* *
* \param error Error code. * \param error Error code.
* *
* \return Statically allocated error message string. * \return Statically allocated error message string or NULL if unknown.
*/ */
const char *dnssec_strerror(int error); const char *dnssec_strerror(int error);
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz> /* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
...@@ -85,9 +85,5 @@ const char *dnssec_strerror(int error) ...@@ -85,9 +85,5 @@ const char *dnssec_strerror(int error)
} }
} }
static __thread char buffer[128]; return NULL;
if (snprintf(buffer, sizeof(buffer), "unknown error %d", error) < 0) {
buffer[0] = '\0';
}
return buffer;
} }
...@@ -529,7 +529,7 @@ int online_sign_load(knotd_mod_t *mod) ...@@ -529,7 +529,7 @@ int online_sign_load(knotd_mod_t *mod)
int r = online_sign_ctx_new(&ctx, mod); int r = online_sign_ctx_new(&ctx, mod);
if (r != KNOT_EOK) { if (r != KNOT_EOK) {
knotd_mod_log(mod, LOG_ERR, "failed to initialize signing key (%s)", knotd_mod_log(mod, LOG_ERR, "failed to initialize signing key (%s)",
dnssec_strerror(r)); knot_strerror(r));
return KNOT_ERROR; return KNOT_ERROR;
} }
......
...@@ -200,20 +200,22 @@ int knot_error_from_libdnssec(int libdnssec_errcode) ...@@ -200,20 +200,22 @@ int knot_error_from_libdnssec(int libdnssec_errcode)
_public_ _public_
const char *knot_strerror(int code) const char *knot_strerror(int code)
{ {
if (KNOT_ERROR_MIN <= code && code <= 0) { const char *msg;
const char *msg = lookup_message(code);
if (msg != NULL) { switch (code) {
return msg; case KNOT_ERROR_MIN ... KNOT_EOK:
} msg = lookup_message(code); break;
} case DNSSEC_ERROR_MIN ... DNSSEC_ERROR_MAX:
msg = dnssec_strerror(code); break;
if (DNSSEC_ERROR_MIN <= code && code <= DNSSEC_ERROR_MAX) { case MDB_KEYEXIST ... MDB_LAST_ERRCODE:
return dnssec_strerror(code); msg = mdb_strerror(code); break;
default:
msg = NULL;
} }
if (MDB_KEYEXIST <= code && code <= MDB_LAST_ERRCODE) { if (msg != NULL) {
return mdb_strerror(code); return msg;
} else {
return strerror(abs(code));
} }
return strerror(abs(code));
} }
...@@ -85,7 +85,7 @@ static bool parse_nsec3_params(dnssec_nsec3_params_t *params, const char *salt_s ...@@ -85,7 +85,7 @@ static bool parse_nsec3_params(dnssec_nsec3_params_t *params, const char *salt_s
dnssec_binary_t salt = { 0 }; dnssec_binary_t salt = { 0 };
r = str_to_salt(salt_str, &salt); r = str_to_salt(salt_str, &salt);
if (r != DNSSEC_EOK) { if (r != DNSSEC_EOK) {
error("Invalid salt, %s.", dnssec_strerror(r)); error("Invalid salt, %s.", knot_strerror(r));
return false; return false;
} }
...@@ -158,7 +158,7 @@ int main(int argc, char *argv[]) ...@@ -158,7 +158,7 @@ int main(int argc, char *argv[])
int r = dnssec_nsec3_hash(&dname, &nsec3_params, &digest); int r = dnssec_nsec3_hash(&dname, &nsec3_params, &digest);
if (r != DNSSEC_EOK) { if (r != DNSSEC_EOK) {
error("Cannot compute NSEC3 hash, %s.", dnssec_strerror(r)); error("Cannot compute NSEC3 hash, %s.", knot_strerror(r));
goto fail; goto fail;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment