]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
knotc: return failed if semantic-check warning in the forced mode
authorDaniel Salzman <daniel.salzman@nic.cz>
Wed, 15 May 2019 09:10:15 +0000 (11:10 +0200)
committerDaniel Salzman <daniel.salzman@nic.cz>
Wed, 15 May 2019 09:10:24 +0000 (11:10 +0200)
src/knot/events/handlers/load.c
src/knot/zone/semantic-check.h
src/knot/zone/zone-load.c
src/knot/zone/zone-load.h
src/knot/zone/zonefile.c
src/utils/knotc/commands.c

index 407c0d592af1846881b25bf8ee05d9234a98ad74..54379e82b9e47b0ad8f7a304283fb78b64a473f9 100644 (file)
@@ -82,7 +82,7 @@ int event_load(conf_t *conf, zone_t *zone)
                                           zone->zonefile.mtime.tv_nsec == mtime.tv_nsec);
                free(filename);
                if (ret == KNOT_EOK) {
-                       ret = zone_load_contents(conf, zone->name, &zf_conts);
+                       ret = zone_load_contents(conf, zone->name, &zf_conts, false);
                }
                if (ret != KNOT_EOK) {
                        zf_conts = NULL;
index a66c1291b8a32e2940c7332425cf03d72fc60671..7ceb7b1dc9df6b5972712901570066dd6edc788d 100644 (file)
@@ -105,6 +105,7 @@ typedef void (*sem_callback) (sem_handler_t *ctx, const zone_contents_t *zone,
 struct sem_handler {
        sem_callback cb;
        bool fatal_error;
+       bool warning;
 };
 
 /*!
index cf7cfa0450b364f01984d49eea09276590becb0e..f99010ad9b84c0d33643c0fa73df8c9261a9b9ae 100644 (file)
@@ -26,7 +26,7 @@
 #include "libknot/libknot.h"
 
 int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
-                       zone_contents_t **contents)
+                       zone_contents_t **contents, bool fail_on_warning)
 {
        if (conf == NULL || zone_name == NULL || contents == NULL) {
                return KNOT_EINVAL;
@@ -54,6 +54,9 @@ int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
        if (*contents == NULL) {
                return KNOT_ERROR;
        }
+       if (handler.warning && fail_on_warning) {
+               return KNOT_ESEMCHECK;
+       }
 
        zone_trees_unify_binodes((*contents)->nodes, (*contents)->nsec3_nodes);
 
index 9fc5b4a4255155a6d31ab1682217e06a2a151cb8..fb8dcc7db8b940aba23ee92080536824ceddabd9 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2019 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
  * \param conf
  * \param zone_name
  * \param contents
- * \return KNOT_EOK or an error
+ * \param fail_on_warning
+ *
+ * \retval KNOT_EOK        if success.
+ * \retval KNOT_ESEMCHECK  if any semantic check warning.
+ * \retval KNOT_E*         if error.
  */
 int zone_load_contents(conf_t *conf, const knot_dname_t *zone_name,
-                       zone_contents_t **contents);
+                       zone_contents_t **contents, bool fail_on_warning);
 
 /*!
  * \brief Update zone contents from the journal.
index d76c778b228f956546e742fbbec977ce4d8b8a50..a8475a41fda1bea0306f6f5091d8dbb5b9a5acdb 100644 (file)
@@ -333,6 +333,10 @@ void err_handler_logger(sem_handler_t *handler, const zone_contents_t *zone,
        assert(handler != NULL);
        assert(zone != NULL);
 
+       if (!handler->fatal_error) {
+               handler->warning = true;
+       }
+
        char buff[KNOT_DNAME_TXT_MAXLEN + 1] = "";
        if (node != NULL) {
                (void)knot_dname_to_str(buff, node->owner, sizeof(buff));
index 0bf99f74c7830a0650d51ccd02fb29440723e174..3c9c804db1372297a2bc33d2b947737a320a6eb6 100644 (file)
@@ -1,4 +1,4 @@
-/*  Copyright (C) 2018 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
+/*  Copyright (C) 2019 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
@@ -556,19 +556,17 @@ static int zone_exec(cmd_args_t *args, int (*fcn)(const knot_dname_t *, void *),
 
 static int zone_check(const knot_dname_t *dname, void *data)
 {
-       UNUSED(data);
+       cmd_args_t *args = data;
 
-       zone_contents_t *contents;
-       int ret = zone_load_contents(conf(), dname, &contents);
-       if (ret == KNOT_EOK) {
-               zone_contents_deep_free(contents);
-       }
+       zone_contents_t *contents = NULL;
+       int ret = zone_load_contents(conf(), dname, &contents, args->force);
+       zone_contents_deep_free(contents);
        return ret;
 }
 
 static int cmd_zone_check(cmd_args_t *args)
 {
-       return zone_exec(args, zone_check, NULL);
+       return zone_exec(args, zone_check, args);
 }
 
 static int zone_memstats(const knot_dname_t *dname, void *data)