]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
kjournalprint: dont silently skip failed knot_rrset_txt_dump
authorLibor Peltan <libor.peltan@nic.cz>
Tue, 12 Aug 2025 09:56:46 +0000 (11:56 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Tue, 12 Aug 2025 16:57:21 +0000 (18:57 +0200)
src/knot/updates/changesets.c
src/knot/updates/changesets.h
src/knot/zone/zone-dump.c
src/utils/kjournalprint/main.c

index 5e24481a7820e6a1c36f0382350999610500a050..72334f88e2a6670e27ac55907e3d774b8f0876fe 100644 (file)
@@ -592,10 +592,11 @@ int changeset_walk(const changeset_t *changeset, changeset_walk_callback callbac
        return KNOT_EOK;
 }
 
-void changeset_print(const changeset_t *changeset, FILE *outfile, bool color)
+int changeset_print(const changeset_t *changeset, FILE *outfile, bool color)
 {
        size_t buflen = 1024;
        char *buff = malloc(buflen);
+       int ret = KNOT_EOK;
 
        knot_dump_style_t style = KNOT_DUMP_STYLE_DEFAULT;
        style.now = knot_time();
@@ -605,20 +606,25 @@ void changeset_print(const changeset_t *changeset, FILE *outfile, bool color)
                fprintf(outfile, "%s;; Removed%s\n", style.color, COL_RST(color));
        }
        if (changeset->soa_from != NULL && buff != NULL) {
-               (void)knot_rrset_txt_dump(changeset->soa_from, &buff, &buflen, &style);
+               ret = knot_rrset_txt_dump(changeset->soa_from, &buff, &buflen, &style);
                fprintf(outfile, "%s%s%s", style.color, buff, COL_RST(color));
        }
-       (void)zone_dump_text(changeset->remove, NULL, outfile, false, style.color);
+       if (ret >= 0 && changeset->remove != NULL) { // Can be NULL if zone-in-journal
+               ret = zone_dump_text(changeset->remove, NULL, outfile, false, style.color);
+       }
 
        style.color = COL_GRN(color);
        if (changeset->soa_to != NULL || !zone_contents_is_empty(changeset->add)) {
                fprintf(outfile, "%s;; Added%s\n", style.color, COL_RST(color));
        }
-       if (changeset->soa_to != NULL && buff != NULL) {
-               (void)knot_rrset_txt_dump(changeset->soa_to, &buff, &buflen, &style);
+       if (changeset->soa_to != NULL && buff != NULL && ret >= 0) {
+               ret = knot_rrset_txt_dump(changeset->soa_to, &buff, &buflen, &style);
                fprintf(outfile, "%s%s%s", style.color, buff, COL_RST(color));
        }
-       (void)zone_dump_text(changeset->add, NULL, outfile, false, style.color);
+       if (ret >= 0) {
+               ret = zone_dump_text(changeset->add, NULL, outfile, false, style.color);
+       }
 
        free(buff);
+       return ret >= 0 ? KNOT_EOK : ret;
 }
index 5c4187080e443fbe5aac2e0fad99b25e086c4f8d..534f61cf14ae61afe9ec1f02a4dc74f51473f7c6 100644 (file)
@@ -275,5 +275,7 @@ int changeset_walk(const changeset_t *changeset, changeset_walk_callback callbac
  * \param changeset Changeset.
  * \param outfile   File to write into.
  * \param color     Use unix tty color metacharacters.
+ * 
+ * \return KNOT_E*
  */
-void changeset_print(const changeset_t *changeset, FILE *outfile, bool color);
+int changeset_print(const changeset_t *changeset, FILE *outfile, bool color);
index 8724701c2b057dd54f8f231c2538cc40dcc0ab2e..7793922e0b101296a8296ff2f272fbe0472ef3d5 100644 (file)
@@ -80,8 +80,7 @@ static int node_dump_text(zone_node_t *node, void *data)
        // Zone apex rrsets.
        if (node->owner == params->origin && !params->dump_rrsig &&
            !params->dump_nsec) {
-               apex_node_dump_text(node, params);
-               return KNOT_EOK;
+               return apex_node_dump_text(node, params);
        }
 
        // Dump non-apex rrsets.
index 57d9fb3ca73fe7f6773f1cd55fd39bf94ff43233..6d536c141234c3205866dbf76cc4bf938ac6ba61 100644 (file)
@@ -71,7 +71,7 @@ typedef struct {
        uint64_t merged_ts;
 } print_params_t;
 
-static void print_changeset(const changeset_t *chs, uint64_t timestamp, print_params_t *params)
+static int print_changeset(const changeset_t *chs, uint64_t timestamp, print_params_t *params)
 {
        char time_buf[64] = { 0 };
        (void)knot_time_print(TIME_PRINT_UNIX, timestamp, time_buf, sizeof(time_buf));
@@ -93,7 +93,7 @@ static void print_changeset(const changeset_t *chs, uint64_t timestamp, print_pa
                       time_buf,
                       COL_RST(params->color));
        }
-       changeset_print(chs, stdout, params->color);
+       return changeset_print(chs, stdout, params->color);
 }
 
 typedef struct {
@@ -198,6 +198,7 @@ static int merge_changeset_cb(bool special, const changeset_t *ch, uint64_t time
 static int print_changeset_cb(bool special, const changeset_t *ch, uint64_t timestamp, void *ctx)
 {
        print_params_t *params = ctx;
+       int ret = KNOT_EOK;
        if (ch != NULL && params->counter++ >= params->limit) {
                if (params->merge) {
                        return merge_changeset_cb(special, ch, timestamp, ctx);
@@ -205,13 +206,13 @@ static int print_changeset_cb(bool special, const changeset_t *ch, uint64_t time
                        print_changeset_debugmode(ch, timestamp);
                        params->changes++;
                } else {
-                       print_changeset(ch, timestamp, params);
+                       ret = print_changeset(ch, timestamp, params);
                }
                if (special && params->debug) {
                        printf("---------------------------------------------\n");
                }
        }
-       return KNOT_EOK;
+       return ret;
 }
 
 int print_journal(char *path, knot_dname_t *name, print_params_t *params)