]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
If signing a zone fails, remove the partial file. [RT #1131]
authorBrian Wellington <source@isc.org>
Sat, 31 Mar 2001 02:12:26 +0000 (02:12 +0000)
committerBrian Wellington <source@isc.org>
Sat, 31 Mar 2001 02:12:26 +0000 (02:12 +0000)
bin/dnssec/dnssec-signzone.c
bin/dnssec/dnssectool.c
bin/dnssec/dnssectool.h

index 9cdf04ebfff09777bdab2fcb3056c69d6b2ac441..ccbcbdb51ee6177bc5dc7d4467dfa6ec41a64eb9 100644 (file)
@@ -17,7 +17,7 @@
  * PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dnssec-signzone.c,v 1.135 2001/03/31 01:46:13 bwelling Exp $ */
+/* $Id: dnssec-signzone.c,v 1.136 2001/03/31 02:12:23 bwelling Exp $ */
 
 #include <config.h>
 
@@ -99,6 +99,7 @@ static isc_mem_t *mctx = NULL;
 static isc_entropy_t *ectx = NULL;
 static dns_ttl_t zonettl;
 static FILE *fp;
+static char *tempfile = NULL;
 static const dns_master_style_t *masterstyle = &dns_master_style_explicitttl;
 static unsigned int nsigned = 0, nretained = 0, ndropped = 0;
 static unsigned int nverified = 0, nverifyfailed = 0;
@@ -116,6 +117,7 @@ static unsigned int ntasks = 0;
 static isc_boolean_t shuttingdown = ISC_FALSE, finished = ISC_FALSE;
 static unsigned int assigned = 0, completed = 0;
 static isc_boolean_t nokeys = ISC_FALSE;
+static isc_boolean_t removefile = ISC_FALSE;
 
 #define INCSTAT(counter)               \
        if (printstats) {               \
@@ -1486,12 +1488,17 @@ usage(void) {
        exit(0);
 }
 
+static void
+removetempfile(void) {
+       if (removefile)
+               isc_file_remove(tempfile);
+}
+
 int
 main(int argc, char *argv[]) {
        int i, ch;
        char *startstr = NULL, *endstr = NULL, *classname = NULL;
        char *origin = NULL, *file = NULL, *output = NULL;
-       char *tempfile = NULL;
        char *randomfile = NULL;
        char *endp;
        isc_time_t timer_start, timer_finish;
@@ -1726,6 +1733,9 @@ main(int argc, char *argv[]) {
        if (result != ISC_R_SUCCESS)
                fatal("failed to open temporary output file: %s",
                      isc_result_totext(result));
+       removefile = ISC_TRUE;
+       setfatalcallback(&removetempfile);
+
        print_time(fp);
        print_version(fp);
 
@@ -1771,6 +1781,7 @@ main(int argc, char *argv[]) {
 
        result = isc_stdio_close(fp);
        check_result(result, "isc_stdio_close");
+       removefile = ISC_FALSE;
 
        result = isc_file_rename(tempfile, output);
        if (result != ISC_R_SUCCESS)
index fa915fa6d17df1c47eba3672231bd1723be069f9..e86fbce7afd683d7f1c840d184626ed6242a9d68 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dnssectool.c,v 1.27 2001/01/09 21:39:27 bwelling Exp $ */
+/* $Id: dnssectool.c,v 1.28 2001/03/31 02:12:24 bwelling Exp $ */
 
 #include <config.h>
 
@@ -45,6 +45,7 @@ extern const char *program;
 static isc_entropysource_t *source = NULL;
 static isc_keyboard_t kbd;
 static isc_boolean_t wantkeyboard = ISC_FALSE;
+static fatalcallback_t *fatalcallback = NULL;
 
 void
 fatal(const char *format, ...) {
@@ -55,9 +56,16 @@ fatal(const char *format, ...) {
        vfprintf(stderr, format, args);
        va_end(args);
        fprintf(stderr, "\n");
+       if (fatalcallback != NULL)
+               (*fatalcallback)();
        exit(1);
 }
 
+void
+setfatalcallback(fatalcallback_t *callback) {
+       fatalcallback = callback;
+}
+
 void
 check_result(isc_result_t result, const char *message) {
        if (result != ISC_R_SUCCESS) {
index 4d5dd20650aef56ddabb66ae04d05dff2a321bcf..76883e0da154792b767d11c012d956d732576735 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: dnssectool.h,v 1.13 2001/01/09 21:39:28 bwelling Exp $ */
+/* $Id: dnssectool.h,v 1.14 2001/03/31 02:12:26 bwelling Exp $ */
 
 #ifndef DNSSECTOOL_H
 #define DNSSECTOOL_H 1
 #include <dns/rdatastruct.h>
 #include <dst/dst.h>
 
+typedef void (fatalcallback_t)(void);
+
 void
 fatal(const char *format, ...) ISC_FORMAT_PRINTF(1, 2);
 
+void
+setfatalcallback(fatalcallback_t *callback);
+
 void
 check_result(isc_result_t result, const char *message);