From 6c6b078a56177fd46522f25f79c8c03e725b3083 Mon Sep 17 00:00:00 2001
From: Daniel Salzman <daniel.salzman@nic.cz>
Date: Sun, 17 Oct 2021 20:19:05 +0200
Subject: [PATCH] utils: unify error logging

---
 src/utils/common/msg.h         |  5 ++++-
 src/utils/common/util_conf.c   | 14 +++++++-------
 src/utils/kcatalogprint/main.c |  5 +++--
 src/utils/keymgr/functions.c   | 32 +++++++++++++++++---------------
 src/utils/keymgr/functions.h   |  3 ---
 src/utils/keymgr/main.c        | 15 ++++++++-------
 src/utils/keymgr/offline_ksk.c | 15 ++++++++-------
 src/utils/kjournalprint/main.c | 21 +++++++++++----------
 src/utils/kzonesign/main.c     | 26 ++++++++++++++------------
 9 files changed, 72 insertions(+), 64 deletions(-)

diff --git a/src/utils/common/msg.h b/src/utils/common/msg.h
index 02eedcc37c..9ab5a493f1 100644
--- a/src/utils/common/msg.h
+++ b/src/utils/common/msg.h
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2021 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
 
     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
@@ -36,3 +36,6 @@ int msg_debug(const char *fmt, ...);
 
 /*! \brief Debug message for null input. */
 #define DBG_NULL	DBG("%s: null parameter\n", __func__)
+
+#define ERR2(msg, ...)	{ fprintf(stderr, "Error: "   msg, ##__VA_ARGS__); fflush(stderr); }
+#define WARN2(msg, ...)	{ fprintf(stderr, "Warning: " msg, ##__VA_ARGS__); fflush(stderr); }
diff --git a/src/utils/common/util_conf.c b/src/utils/common/util_conf.c
index 5a706538ab..81edb9c95b 100644
--- a/src/utils/common/util_conf.c
+++ b/src/utils/common/util_conf.c
@@ -32,7 +32,7 @@ bool util_conf_initialized(void)
 int util_conf_init_confdb(const char *confdb)
 {
 	if (util_conf_initialized()) {
-		ERR("Configuration already initialized.\n");
+		ERR2("configuration already initialized\n");
 		util_conf_deinit();
 		return KNOT_ESEMCHECK;
 	}
@@ -47,8 +47,8 @@ int util_conf_init_confdb(const char *confdb)
 	conf_t *new_conf = NULL;
 	int ret = conf_new(&new_conf, conf_schema, confdb, max_conf_size, flags);
 	if (ret != KNOT_EOK) {
-		ERR("failed opening configuration database %s (%s)\n",
-		    (confdb == NULL ? "" : confdb), knot_strerror(ret));
+		ERR2("failed opening configuration database %s (%s)\n",
+		     (confdb == NULL ? "" : confdb), knot_strerror(ret));
 	} else {
 		conf_update(new_conf, CONF_UPD_FNONE);
 	}
@@ -64,8 +64,8 @@ int util_conf_init_file(const char *conffile)
 
 	ret = conf_import(conf(), conffile, true, false);
 	if (ret != KNOT_EOK) {
-		ERR("failed opening configuration file %s (%s)\n",
-		    conffile, knot_strerror(ret));
+		ERR2("failed opening configuration file %s (%s)\n",
+		     conffile, knot_strerror(ret));
 	}
 	return ret;
 }
@@ -87,7 +87,7 @@ int util_conf_init_justdb(const char *db_type, const char *db_path)
 	ret = conf_import(conf(), conf_str, false, false);
 	free(conf_str);
 	if (ret != KNOT_EOK) {
-		ERR("failed creating temporary configuration (%s)\n", knot_strerror(ret));
+		ERR2("failed creating temporary configuration (%s)\n", knot_strerror(ret));
 	}
 	return ret;
 }
@@ -102,7 +102,7 @@ int util_conf_init_default(void)
 	} else if (stat(CONF_DEFAULT_FILE, &st) == 0) {
 		return util_conf_init_file(CONF_DEFAULT_FILE);
 	} else {
-		ERR("couldn't initialize configuration, please provide -c, -C, or -D option\n");
+		ERR2("couldn't initialize configuration, please provide -c, -C, or -D option\n");
 		return KNOT_EINVAL;
 	}
 }
diff --git a/src/utils/kcatalogprint/main.c b/src/utils/kcatalogprint/main.c
index e25ce5aace..4ee055096a 100644
--- a/src/utils/kcatalogprint/main.c
+++ b/src/utils/kcatalogprint/main.c
@@ -19,6 +19,7 @@
 #include <string.h>
 
 #include "knot/catalog/catalog_db.h"
+#include "utils/common/msg.h"
 #include "utils/common/params.h"
 #include "utils/common/util_conf.h"
 
@@ -69,7 +70,7 @@ static void catalog_print(catalog_t *cat)
 			ret = catalog_apply(cat, NULL, catalog_print_cb, &total, false);
 		}
 		if (ret != KNOT_EOK) {
-			printf("Catalog print failed (%s)\n", knot_strerror(ret));
+			ERR2("failed to print catalog (%s)\n", knot_strerror(ret));
 			return;
 		}
 	}
@@ -120,7 +121,7 @@ int main(int argc, char *argv[])
 
 	// Backward compatibility.
 	if (argc - optind > 0) {
-		fprintf(stderr, "Warning: obsolete parameter specified\n");
+		WARN2("obsolete parameter specified\n");
 		if (util_conf_init_justdb("catalog-db", argv[optind]) != KNOT_EOK) {
 			goto failure;
 		}
diff --git a/src/utils/keymgr/functions.c b/src/utils/keymgr/functions.c
index 0dc35cbe89..409999e51b 100644
--- a/src/utils/keymgr/functions.c
+++ b/src/utils/keymgr/functions.c
@@ -21,6 +21,8 @@
 #include <fcntl.h>
 
 #include "utils/keymgr/functions.h"
+
+#include "utils/common/msg.h"
 #include "utils/keymgr/bind_privkey.h"
 #include "contrib/base64.h"
 #include "contrib/color.h"
@@ -45,7 +47,7 @@ int parse_timestamp(char *arg, knot_time_t *stamp)
 	int ret = knot_time_parse("YMDhms|'now'+-#u|'t'+-#u|+-#u|'t'+-#|+-#|#",
 	                          arg, stamp);
 	if (ret < 0) {
-		ERROR("invalid timestamp: %s\n", arg);
+		ERR2("invalid timestamp: %s\n", arg);
 		return KNOT_EINVAL;
 	}
 	return KNOT_EOK;
@@ -139,7 +141,7 @@ static bool genkeyargs(int argc, char *argv[], bool just_timing,
 				}
 			}
 			if (alg > 255) {
-				ERROR("unknown algorithm: %s\n", argv[i] + 10);
+				ERR2("unknown algorithm: %s\n", argv[i] + 10);
 				return false;
 			}
 			*algorithm = alg;
@@ -152,13 +154,13 @@ static bool genkeyargs(int argc, char *argv[], bool just_timing,
 			bitmap_set(flags, DNSKEY_GENERATE_SEP_ON, str2bool(argv[i] + 4));
 		} else if (!just_timing && strncasecmp(argv[i], "size=", 5) == 0) {
 			if (str_to_u16(argv[i] + 5, keysize) != KNOT_EOK) {
-				ERROR("invalid size: '%s'\n", argv[i] + 5);
+				ERR2("invalid size: '%s'\n", argv[i] + 5);
 				return false;
 			}
 		} else if (!just_timing && strncasecmp(argv[i], "addtopolicy=", 12) == 0) {
 			*addtopolicy = argv[i] + 12;
 		} else if (!init_timestamps(argv[i], timing)) {
-			ERROR("invalid parameter: %s\n", argv[i]);
+			ERR2("invalid parameter: %s\n", argv[i]);
 			return false;
 		}
 	}
@@ -170,7 +172,7 @@ static bool _check_lower(knot_time_t a, knot_time_t b,
 			 const char *a_name, const char *b_name)
 {
 	if (knot_time_cmp(a, b) > 0) {
-		ERROR("semantic error: expected '%s' before '%s'\n", a_name, b_name);
+		ERR2("timestamp '%s' must be before '%s'\n", a_name, b_name);
 		return false;
 	}
 	return true;
@@ -685,28 +687,28 @@ int keymgr_generate_tsig(const char *tsig_name, const char *alg_name, int bits)
 	bits = (bits + CHAR_BIT - 1) / CHAR_BIT * CHAR_BIT;
 
 	if (bits < optimal_bits) {
-		WARN("optimal key size for %s is at least %d bits\n",
-		     dnssec_tsig_algorithm_to_name(alg), optimal_bits);
+		WARN2("optimal key size for %s is at least %d bits\n",
+		       dnssec_tsig_algorithm_to_name(alg), optimal_bits);
 	}
 	assert(bits % CHAR_BIT == 0);
 
 	_cleanup_binary_ dnssec_binary_t key = { 0 };
 	int r = dnssec_binary_alloc(&key, bits / CHAR_BIT);
 	if (r != DNSSEC_EOK) {
-		ERROR("failed to allocate memory\n");
+		ERR2("failed to allocate memory\n");
 		return knot_error_from_libdnssec(r);
 	}
 
 	r = gnutls_rnd(GNUTLS_RND_KEY, key.data, key.size);
 	if (r != 0) {
-		ERROR("failed to generate secret the key\n");
+		ERR2("failed to generate secret the key\n");
 		return knot_error_from_libdnssec(r);
 	}
 
 	_cleanup_binary_ dnssec_binary_t key_b64 = { 0 };
 	r = dnssec_binary_to_base64(&key, &key_b64);
 	if (r != DNSSEC_EOK) {
-		ERROR("failed to convert the key to Base64\n");
+		ERR2("failed to convert the key to Base64\n");
 		return knot_error_from_libdnssec(r);
 	}
 
@@ -745,7 +747,7 @@ int keymgr_get_key(kdnssec_ctx_t *ctx, const char *key_spec, knot_kasp_key_t **k
 	if ((is_keytag && !can_be_keytag) ||
 	    (is_id && !is_hex(key_spec)) ||
 	    (!can_be_keytag && !is_hex(key_spec))) {
-		ERROR("invalid key specification\n");
+		ERR2("invalid key specification\n");
 		return KNOT_EINVAL;
 	}
 
@@ -769,13 +771,13 @@ int keymgr_get_key(kdnssec_ctx_t *ctx, const char *key_spec, knot_kasp_key_t **k
 			if (*key == NULL) {
 				*key = candidate;
 			} else {
-				ERROR("key is not specified uniquely. Please use id=Full_Key_ID\n");
+				ERR2("key not specified uniquely, please use id=Full_Key_ID\n");
 				return KNOT_EINVAL;
 			}
 		}
 	}
 	if (*key == NULL) {
-		ERROR("key not found\n");
+		ERR2("key not found\n");
 		return KNOT_ENOENT;
 	}
 	return KNOT_EOK;
@@ -792,7 +794,7 @@ int keymgr_foreign_key_id(char *argv[], knot_lmdb_db_t *kaspdb, knot_dname_t **k
 	kdnssec_ctx_t kctx = { 0 };
 	int ret = kdnssec_ctx_init(conf(), &kctx, *key_zone, kaspdb, NULL);
 	if (ret != KNOT_EOK) {
-		ERROR("failed to initialize zone %s (%s)\n", argv[0], knot_strerror(ret));
+		ERR2("failed to initialize zone %s (%s)\n", argv[0], knot_strerror(ret));
 		free(*key_zone);
 		*key_zone = NULL;
 		return KNOT_ENOZONE;
@@ -1054,7 +1056,7 @@ int keymgr_list_zones(knot_lmdb_db_t *kaspdb)
 	init_list(&zones);
 	int ret = kasp_db_list_zones(kaspdb, &zones);
 	if (ret != KNOT_EOK) {
-		ERROR("failed to initialize KASP (%s)\n", knot_strerror(ret));
+		ERR2("failed to initialize KASP (%s)\n", knot_strerror(ret));
 		return ret;
 	}
 
diff --git a/src/utils/keymgr/functions.h b/src/utils/keymgr/functions.h
index 15e168a30b..3e07eefd75 100644
--- a/src/utils/keymgr/functions.h
+++ b/src/utils/keymgr/functions.h
@@ -20,9 +20,6 @@
 
 #include "knot/dnssec/context.h"
 
-#define WARN(msg, ...)  { fprintf(stderr, "Warning: " msg, ##__VA_ARGS__); fflush(stderr); }
-#define ERROR(msg, ...) { fprintf(stderr, "Error: "   msg, ##__VA_ARGS__); fflush(stderr); }
-
 typedef struct {
 	knot_time_print_t format;
 	bool brief;
diff --git a/src/utils/keymgr/main.c b/src/utils/keymgr/main.c
index 0aede86b31..030bb77629 100644
--- a/src/utils/keymgr/main.c
+++ b/src/utils/keymgr/main.c
@@ -21,6 +21,7 @@
 #include "contrib/strtonum.h"
 #include "knot/dnssec/zone-keys.h"
 #include "libknot/libknot.h"
+#include "utils/common/msg.h"
 #include "utils/common/params.h"
 #include "utils/common/util_conf.h"
 #include "utils/keymgr/functions.h"
@@ -115,7 +116,7 @@ static int key_command(int argc, char *argv[], int opt_ind, knot_lmdb_db_t *kasp
                        keymgr_list_params_t *list_params)
 {
 	if (argc < opt_ind + 2) {
-		ERROR("zone name and/or command not specified\n");
+		ERR2("zone name or command not specified\n");
 		print_help();
 		return KNOT_EINVAL;
 	}
@@ -132,20 +133,20 @@ static int key_command(int argc, char *argv[], int opt_ind, knot_lmdb_db_t *kasp
 
 	int ret = kdnssec_ctx_init(conf(), &kctx, zone_name, kaspdb, NULL);
 	if (ret != KNOT_EOK) {
-		ERROR("failed to initialize KASP (%s)\n", knot_strerror(ret));
+		ERR2("failed to initialize KASP (%s)\n", knot_strerror(ret));
 		goto main_end;
 	}
 
 #define CHECK_MISSING_ARG(msg) \
 	if (argc < 3) { \
-		ERROR("%s\n", (msg)); \
+		ERR2("%s\n", (msg)); \
 		ret = KNOT_EINVAL; \
 		goto main_end; \
 	}
 
 #define CHECK_MISSING_ARG2(msg) \
 	if (argc < 4) { \
-		ERROR("%s\n", (msg)); \
+		ERR2("%s\n", (msg)); \
 		ret = KNOT_EINVAL; \
 		goto main_end; \
 	}
@@ -268,7 +269,7 @@ static int key_command(int argc, char *argv[], int opt_ind, knot_lmdb_db_t *kasp
 		CHECK_MISSING_ARG("Input file not specified");
 		ret = keymgr_import_skr(&kctx, argv[2]);
 	} else {
-		ERROR("wrong zone-key command: %s\n", argv[1]);
+		ERR2("invalid command '%s'\n", argv[1]);
 		goto main_end;
 	}
 
@@ -277,7 +278,7 @@ static int key_command(int argc, char *argv[], int opt_ind, knot_lmdb_db_t *kasp
 	if (ret == KNOT_EOK) {
 		printf("%s", print_ok_on_succes ? "OK\n" : "");
 	} else {
-		ERROR("%s\n", knot_strerror(ret));
+		ERR2("%s\n", knot_strerror(ret));
 	}
 
 main_end:
@@ -335,7 +336,7 @@ int main(int argc, char *argv[])
 			}
 			ret = keymgr_generate_tsig(optarg, (argc > optind ? argv[optind] : "hmac-sha256"), parm);
 			if (ret != KNOT_EOK) {
-				ERROR("failed to generate TSIG (%s)\n", knot_strerror(ret));
+				ERR2("failed to generate TSIG (%s)\n", knot_strerror(ret));
 				goto failure;
 			}
 			goto success;
diff --git a/src/utils/keymgr/offline_ksk.c b/src/utils/keymgr/offline_ksk.c
index 4db050d8e9..22c3c02c61 100644
--- a/src/utils/keymgr/offline_ksk.c
+++ b/src/utils/keymgr/offline_ksk.c
@@ -27,6 +27,7 @@
 #include "knot/dnssec/zone-keys.h"
 #include "knot/dnssec/zone-sign.h"
 #include "libzscanner/scanner.h"
+#include "utils/common/msg.h"
 #include "utils/keymgr/functions.h"
 
 #define KSR_SKR_VER "1.0"
@@ -38,7 +39,7 @@ static int pregenerate_once(kdnssec_ctx_t *ctx, knot_time_t *next)
 	// generate ZSKs
 	int ret = knot_dnssec_key_rollover(ctx, KEY_ROLL_ALLOW_ZSK_ROLL, &resch);
 	if (ret != KNOT_EOK) {
-		ERROR("key rollover failed\n");
+		ERR2("key rollover failed\n");
 		return ret;
 	}
 	// we don't need to do anything explicitly with the generated ZSKs
@@ -61,7 +62,7 @@ static int load_dnskey_rrset(kdnssec_ctx_t *ctx, knot_rrset_t **_dnskey, zone_ke
 
 	int ret = load_zone_keys(ctx, keyset, false);
 	if (ret != KNOT_EOK) {
-		ERROR("failed to load keys\n");
+		ERR2("failed to load keys\n");
 		return ret;
 	}
 
@@ -70,7 +71,7 @@ static int load_dnskey_rrset(kdnssec_ctx_t *ctx, knot_rrset_t **_dnskey, zone_ke
 		if (key->is_public) {
 			ret = rrset_add_zone_key(dnskey, key);
 			if (ret != KNOT_EOK) {
-				ERROR("failed to add zone key\n");
+				ERR2("failed to add zone key\n");
 				return ret;
 			}
 		}
@@ -101,7 +102,7 @@ int keymgr_pregenerate_zsks(kdnssec_ctx_t *ctx, char *arg_from, char *arg_to)
 
 	if (ctx->policy->dnskey_ttl       == UINT32_MAX ||
 	    ctx->policy->zone_maximal_ttl == UINT32_MAX) {
-		ERROR("dnskey-ttl or zone-max-ttl not configured\n");
+		ERR2("dnskey-ttl or zone-max-ttl not configured\n");
 		return KNOT_ESEMCHECK;
 	}
 
@@ -231,7 +232,7 @@ done:
 
 #define OFFLINE_KSK_CONF_CHECK \
 	if (!ctx->policy->offline_ksk || !ctx->policy->manual) { \
-		ERROR("offline-ksk and manual must be enabled in configuration\n"); \
+		ERR2("offline-ksk and manual must be enabled in configuration\n"); \
 		return KNOT_ESEMCHECK; \
 	}
 
@@ -430,8 +431,8 @@ static void skr_validate_header(zs_scanner_t *sc)
 	if (ctx->timestamp > 0 && ctx->ret == KNOT_EOK) {
 		int ret = key_records_verify(&ctx->r, ctx->kctx, ctx->timestamp);
 		if (ret != KNOT_EOK) { // ctx->ret untouched
-			ERROR("invalid SignedKeyResponse for %"KNOT_TIME_PRINTF" (%s)\n",
-			       ctx->timestamp, knot_strerror(ret));
+			ERR2("invalid SignedKeyResponse for %"KNOT_TIME_PRINTF" (%s)\n",
+			     ctx->timestamp, knot_strerror(ret));
 		}
 		key_records_clear_rdatasets(&ctx->r);
 	}
diff --git a/src/utils/kjournalprint/main.c b/src/utils/kjournalprint/main.c
index 1d55fa0cc5..cbcde21f9e 100644
--- a/src/utils/kjournalprint/main.c
+++ b/src/utils/kjournalprint/main.c
@@ -25,6 +25,7 @@
 #include "knot/journal/journal_read.h"
 #include "knot/journal/serialization.h"
 #include "knot/zone/zone-dump.h"
+#include "utils/common/msg.h"
 #include "utils/common/params.h"
 #include "utils/common/util_conf.h"
 #include "contrib/color.h"
@@ -195,7 +196,7 @@ int print_journal(char *path, knot_dname_t *name, print_params_t *params)
 
 	ret = journal_info(j, &exists, NULL, NULL, NULL, NULL, NULL, &occupied, &occupied_all);
 	if (ret != KNOT_EOK || !exists) {
-		fprintf(stderr, "This zone does not exist in DB %s\n", path);
+		ERR2("zone not exists in the journal DB %s\n", path);
 		knot_lmdb_deinit(&jdb);
 		return ret == KNOT_EOK ? KNOT_ENOENT : ret;
 	}
@@ -203,9 +204,9 @@ int print_journal(char *path, knot_dname_t *name, print_params_t *params)
 	if (params->check) {
 		ret = journal_sem_check(j);
 		if (ret > 0) {
-			fprintf(stderr, "Journal semantic check error: %d\n", ret);
+			ERR2("semantic check failed with code %d\n", ret);
 		} else if (ret != KNOT_EOK) {
-			fprintf(stderr, "Journal semantic check failed (%s).\n", knot_strerror(ret));
+			ERR2("semantic check failed (%s)\n", knot_strerror(ret));
 		}
 	}
 
@@ -390,7 +391,7 @@ int main(int argc, char *argv[])
 
 	// Backward compatibility.
 	if ((justlist && (argc - optind > 0)) || (!justlist && (argc - optind > 1))) {
-		fprintf(stderr, "Warning: obsolete parameter specified\n");
+		WARN2("obsolete parameter specified\n");
 		if (util_conf_init_justdb("journal-db", argv[optind]) != KNOT_EOK) {
 			goto failure;
 		}
@@ -413,13 +414,13 @@ int main(int argc, char *argv[])
 		case KNOT_EOK:
 			goto success;
 		case KNOT_ENODB:
-			fprintf(stderr, "The journal DB does not exist\n");
+			ERR2("the journal DB does not exist\n");
 			goto failure;
 		case KNOT_EMALF:
-			fprintf(stderr, "The journal DB is broken\n");
+			ERR2("the journal DB is broken\n");
 			goto failure;
 		default:
-			fprintf(stderr, "Failed to load zone list (%s)\n", knot_strerror(ret));
+			ERR2("failed to load zone list (%s)\n", knot_strerror(ret));
 			goto failure;
 		}
 	} else {
@@ -443,15 +444,15 @@ int main(int argc, char *argv[])
 			}
 			break;
 		case KNOT_ENODB:
-			fprintf(stderr, "The journal DB does not exist\n");
+			ERR2("the journal DB does not exist\n");
 			goto failure;
 		case KNOT_EOUTOFZONE:
-			fprintf(stderr, "The specified journal DB does not contain the specified zone\n");
+			ERR2("the journal DB does not contain the specified zone\n");
 			goto failure;
 		case KNOT_EOK:
 			break;
 		default:
-			fprintf(stderr, "Failed to load changesets (%s)\n", knot_strerror(ret));
+			ERR2("failed to load changesets (%s)\n", knot_strerror(ret));
 			goto failure;
 		}
 	}
diff --git a/src/utils/kzonesign/main.c b/src/utils/kzonesign/main.c
index 07de547851..34a298ed9b 100644
--- a/src/utils/kzonesign/main.c
+++ b/src/utils/kzonesign/main.c
@@ -23,7 +23,9 @@
 #include "knot/server/server.h"
 #include "knot/zone/zone-load.h"
 #include "knot/zone/zonefile.h"
+#include "utils/common/msg.h"
 #include "utils/common/params.h"
+#include "utils/common/util_conf.h"
 
 #define PROGRAM_NAME "kzonesign"
 
@@ -42,8 +44,8 @@ static bool init_conf(const char *confdb)
 	conf_t *new_conf = NULL;
 	int ret = conf_new(&new_conf, conf_schema, confdb, max_conf_size, flags);
 	if (ret != KNOT_EOK) {
-		printf("Failed opening configuration database %s (%s)\n",
-		       (confdb == NULL ? "" : confdb), knot_strerror(ret));
+		ERR2("failed opening configuration database %s (%s)\n",
+		     (confdb == NULL ? "" : confdb), knot_strerror(ret));
 		return false;
 	}
 	conf_update(new_conf, CONF_UPD_FNONE);
@@ -127,7 +129,7 @@ int main(int argc, char *argv[])
 	zone_str = argv[optind];
 	zone_name = knot_dname_from_str_alloc(zone_str);
 	if (zone_name == NULL) {
-		printf("Invalid zone name '%s'\n", zone_str);
+		ERR2("invalid zone name '%s'\n", zone_str);
 		return EXIT_FAILURE;
 	}
 	knot_dname_to_lower(zone_name);
@@ -139,38 +141,38 @@ int main(int argc, char *argv[])
 
 	int ret = conf_import(conf(), confile, true, false);
 	if (ret != KNOT_EOK) {
-		printf("Failed opening configuration file '%s' (%s)\n",
-		       confile, knot_strerror(ret));
+		ERR2("failed opening configuration file '%s' (%s)\n",
+		     confile, knot_strerror(ret));
 		goto fail;
 	}
 
 	conf_val_t val = conf_zone_get(conf(), C_DOMAIN, zone_name);
 	if (val.code != KNOT_EOK) {
-		printf("Zone '%s' not configured\n", zone_str);
+		ERR2("zone '%s' not configured\n", zone_str);
 		ret = val.code;
 		goto fail;
 	}
 	val = conf_zone_get(conf(), C_DNSSEC_POLICY, zone_name);
 	if (val.code != KNOT_EOK) {
-		printf("Waring: DNSSEC policy not configured for zone '%s', taking defaults\n", zone_str);
+		WARN2("DNSSEC policy not configured for zone '%s', taking defaults\n", zone_str);
 	}
 
 	zone_struct = zone_new(zone_name);
 	if (zone_struct == NULL) {
-		printf("out of memory\n");
+		ERR2("out of memory\n");
 		ret = KNOT_ENOMEM;
 		goto fail;
 	}
 
 	ret = zone_load_contents(conf(), zone_name, &unsigned_conts, false);
 	if (ret != KNOT_EOK) {
-		printf("Failed to load zone contents (%s)\n", knot_strerror(ret));
+		ERR2("failed to load zone contents (%s)\n", knot_strerror(ret));
 		goto fail;
 	}
 
 	ret = zone_update_from_contents(&up, zone_struct, unsigned_conts, UPDATE_FULL);
 	if (ret != KNOT_EOK) {
-		printf("Failed to initialize zone update (%s)\n", knot_strerror(ret));
+		ERR2("failed to initialize zone update (%s)\n", knot_strerror(ret));
 		zone_contents_deep_free(unsigned_conts);
 		goto fail;
 	}
@@ -184,7 +186,7 @@ int main(int argc, char *argv[])
 		ret = knot_dnssec_zone_sign(&up, conf(), 0, rollover, timestamp, &next_sign);
 	}
 	if (ret != KNOT_EOK) {
-		printf("Failed to sign the zone (%s)\n", knot_strerror(ret));
+		ERR2("failed to sign the zone (%s)\n", knot_strerror(ret));
 		zone_update_clear(&up);
 		goto fail;
 	}
@@ -201,7 +203,7 @@ int main(int argc, char *argv[])
 	}
 	zone_update_clear(&up);
 	if (ret != KNOT_EOK) {
-		printf("Failed to flush signed zone file (%s)\n", knot_strerror(ret));
+		ERR2("failed to flush signed zone to file (%s)\n", knot_strerror(ret));
 		goto fail;
 	}
 
-- 
GitLab