From: David VaĊĦek Date: Thu, 16 Dec 2021 22:38:58 +0000 (+0100) Subject: ctl/purge: add a simple error logging X-Git-Tag: v3.3.dev~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0c4cb2006d744e11bd329e58db060063bbe4978c;p=thirdparty%2Fknot-dns.git ctl/purge: add a simple error logging --- diff --git a/src/knot/ctl/commands.c b/src/knot/ctl/commands.c index 873cff6f13..e27acf178c 100644 --- a/src/knot/ctl/commands.c +++ b/src/knot/ctl/commands.c @@ -48,13 +48,6 @@ #define MATCH_AND_FILTER(args, code) ((args)->data[KNOT_CTL_IDX_FILTER] != NULL && \ strchr((args)->data[KNOT_CTL_IDX_FILTER], (code)) != NULL) -#define RETURN_IF_FAILED(exception) \ -{ \ - if (ret != KNOT_EOK && ret != (exception)) { \ - return ret; \ - } \ -} - typedef struct { ctl_args_t *args; int type_filter; // -1: no specific type, [0, 2^16]: specific type. @@ -1335,6 +1328,15 @@ static int orphans_purge(ctl_args_t *args) return KNOT_EOK; } +#define RETURN_IF_FAILED(str, exception) \ +{ \ + if (ret != KNOT_EOK && ret != (exception)) { \ + log_zone_error(zone->name, \ + "failed to %s (%s)", (str), knot_strerror(ret)); \ + return ret; \ + } \ +} + static int zone_purge(zone_t *zone, ctl_args_t *args) { int ret = KNOT_EOK; @@ -1342,7 +1344,7 @@ static int zone_purge(zone_t *zone, ctl_args_t *args) // Abort possible editing transaction. if (MATCH_OR_FILTER(args, CTL_FILTER_PURGE_EXPIRE)) { ret = zone_txn_abort(zone, args); - RETURN_IF_FAILED(KNOT_TXN_ENOTEXISTS); + RETURN_IF_FAILED("abort pending transaction", KNOT_TXN_ENOTEXISTS); } // Purge the zone timers. @@ -1350,7 +1352,7 @@ static int zone_purge(zone_t *zone, ctl_args_t *args) memset(&zone->timers, 0, sizeof(zone->timers)); ret = zone_timers_sweep(&args->server->timerdb, zone_names_distinct, zone->name); - RETURN_IF_FAILED(KNOT_ENOENT); + RETURN_IF_FAILED("purge timers", KNOT_ENOENT); } // Expire the zone. @@ -1364,13 +1366,13 @@ static int zone_purge(zone_t *zone, ctl_args_t *args) char *zonefile = conf_zonefile(conf(), zone->name); ret = (unlink(zonefile) == -1 ? knot_map_errno() : KNOT_EOK); free(zonefile); - RETURN_IF_FAILED(KNOT_ENOENT); + RETURN_IF_FAILED("purge zone file", KNOT_ENOENT); } // Purge the zone journal. if (MATCH_OR_FILTER(args, CTL_FILTER_PURGE_JOURNAL)) { ret = journal_scrape_with_md(zone_journal(zone), true); - RETURN_IF_FAILED(KNOT_ENOENT); + RETURN_IF_FAILED("purge journal", KNOT_ENOENT); } // Purge KASP DB. @@ -1379,7 +1381,7 @@ static int zone_purge(zone_t *zone, ctl_args_t *args) if (ret == KNOT_EOK) { ret = kasp_db_delete_all(zone_kaspdb(zone), zone->name); } - RETURN_IF_FAILED(KNOT_ENOENT); + RETURN_IF_FAILED("purge KASP DB", KNOT_ENOENT); } return KNOT_EOK;