]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
daemon/kres-gen: generate directly to file instead of stdout
authorTomas Krizek <tomas.krizek@nic.cz>
Tue, 19 Feb 2019 10:58:10 +0000 (11:58 +0100)
committerTomas Krizek <tomas.krizek@nic.cz>
Tue, 12 Mar 2019 09:43:32 +0000 (10:43 +0100)
daemon/lua/kres-gen.sh

index 3f17cd2b54df0a0a5ba81c4168ed149d4c1b5e8f..e87ed2dfea9b499651a671ac927fe202a807220e 100755 (executable)
@@ -1,6 +1,18 @@
 #!/bin/bash
 set -o pipefail -o errexit
 
+cd "$(dirname ${0})"
+CDEFS="../../scripts/gen-cdefs.sh"
+
+# Write to .kres-gen.lua.tmp instead of STDOUT
+exec 1<&-
+exec 1<>.kres-gen.lua.tmp
+err_handle() {
+    (>&2 echo "Failed to re-generate kres-gen.lua! Missing debugsymbols?")
+    rm -f .kres-gen.lua.tmp
+}
+trap err_handle ERR INT TERM
+
 ### Dev's guide
 #
 # C declarations for lua are (mostly) generated to simplify maintenance.
@@ -40,7 +52,7 @@ typedef void (*trace_log_f) (const struct kr_query *, const char *, const char *
 typedef void (*trace_callback_f)(struct kr_request *);
 "
 
-./scripts/gen-cdefs.sh libkres types <<-EOF
+${CDEFS} libkres types <<-EOF
        knot_section_t
        knot_rrinfo_t
        knot_dname_t
@@ -49,13 +61,13 @@ typedef void (*trace_callback_f)(struct kr_request *);
 EOF
 
 genResType() {
-       echo "$1" | ./scripts/gen-cdefs.sh libkres types
+       echo "$1" | ${CDEFS} libkres types
 }
 
 # No simple way to fixup this rename in ./kres.lua AFAIK.
 genResType "knot_rrset_t" | sed 's/\<owner\>/_owner/; s/\<ttl\>/_ttl/'
 
-./scripts/gen-cdefs.sh libkres types <<-EOF
+${CDEFS} libkres types <<-EOF
        knot_pkt_t
        knot_edns_options_t
        knot_pktsection_t
@@ -100,7 +112,7 @@ genResType "struct kr_context" | sed '/kr_nsrep_rtt_lru_t/,$ d'
 printf "\tchar _stub[];\n};\n"
 
 ## libknot API
-./scripts/gen-cdefs.sh libknot functions <<-EOF
+${CDEFS} libknot functions <<-EOF
 # Utils
        knot_strerror
 # Domain names
@@ -129,7 +141,7 @@ printf "\tchar _stub[];\n};\n"
 EOF
 
 ## libkres API
-./scripts/gen-cdefs.sh libkres functions <<-EOF
+${CDEFS} libkres functions <<-EOF
 # Resolution request
        kr_resolve_plan
        kr_resolve_pool
@@ -197,7 +209,7 @@ EOF
 
 
 ## libzscanner API for ./zonefile.lua
-./scripts/gen-cdefs.sh libzscanner types <<-EOF
+${CDEFS} libzscanner types <<-EOF
        zs_win_t
        zs_apl_t
        zs_loc_t
@@ -205,7 +217,7 @@ EOF
        zs_scanner_t
        struct zs_scanner
 EOF
-./scripts/gen-cdefs.sh libzscanner functions <<-EOF
+${CDEFS} libzscanner functions <<-EOF
        zs_deinit
        zs_init
        zs_parse_record
@@ -216,4 +228,7 @@ EOF
 
 printf "]]\n"
 
+mv .kres-gen-lua.tmp kres-gen.lua
+(>&2 echo "Successfully re-generated "${PWD}/kres-gen.lua")
+
 exit 0