[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r5288 - in branches/OpenDNSSEC-1.3/signer/src: shared signer

Matthijs Mekking matthijs at nlnetlabs.nl
Tue Jul 5 10:34:56 CEST 2011


Author: matthijs
Date: 2011-07-05 10:34:55 +0200 (Tue, 05 Jul 2011)
New Revision: 5288

Modified:
   branches/OpenDNSSEC-1.3/signer/src/shared/file.c
   branches/OpenDNSSEC-1.3/signer/src/shared/file.h
   branches/OpenDNSSEC-1.3/signer/src/signer/tools.c
Log:
Pivotal #15342489: Return better error codes from ods_file_copy

https://www.pivotaltracker.com/story/show/15342489



Modified: branches/OpenDNSSEC-1.3/signer/src/shared/file.c
===================================================================
--- branches/OpenDNSSEC-1.3/signer/src/shared/file.c	2011-07-04 14:50:22 UTC (rev 5287)
+++ branches/OpenDNSSEC-1.3/signer/src/shared/file.c	2011-07-05 08:34:55 UTC (rev 5288)
@@ -355,14 +355,15 @@
  * File copy.
  *
  */
-int
+ods_status
 ods_file_copy(const char* file1, const char* file2)
 {
     char str[SYSTEM_MAXLEN];
     FILE* fd = NULL;
+    int retval = 0;
 
     if (!file1 || !file2) {
-        return 1;
+        return ODS_STATUS_ASSERT_ERR;
     }
 
     if ((fd = ods_fopen(file1, NULL, "r")) != NULL) {
@@ -370,10 +371,15 @@
         snprintf(str, SYSTEM_MAXLEN, "%s %s %s > /dev/null",
             CP_COMMAND, file1, file2);
         ods_log_debug("system call: %s", str);
-        return system(str);
+        retval = system(str);
+        switch (retval) {
+            case 0:
+                return ODS_STATUS_OK;
+            default:
+                return ODS_STATUS_ERR;
+        }
     }
-    /* no such file */
-    return 1;
+    return ODS_STATUS_FOPEN_ERR;
 }
 
 /**

Modified: branches/OpenDNSSEC-1.3/signer/src/shared/file.h
===================================================================
--- branches/OpenDNSSEC-1.3/signer/src/shared/file.h	2011-07-04 14:50:22 UTC (rev 5287)
+++ branches/OpenDNSSEC-1.3/signer/src/shared/file.h	2011-07-05 08:34:55 UTC (rev 5288)
@@ -35,6 +35,7 @@
 #define SHARED_FILE_H
 
 #include "config.h"
+#include "shared/status.h"
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -151,10 +152,10 @@
  * Copy file.
  * \param[in] file1 from file name
  * \param[in] file2 to file name
- * \return 0 on success, 1 on error
+ * \return ods_status
  *
  */
-int ods_file_copy(const char* file1, const char* file2);
+ods_status ods_file_copy(const char* file1, const char* file2);
 
 /**
  * (Create) and change ownership of directories.

Modified: branches/OpenDNSSEC-1.3/signer/src/signer/tools.c
===================================================================
--- branches/OpenDNSSEC-1.3/signer/src/signer/tools.c	2011-07-04 14:50:22 UTC (rev 5287)
+++ branches/OpenDNSSEC-1.3/signer/src/signer/tools.c	2011-07-05 08:34:55 UTC (rev 5288)
@@ -49,7 +49,6 @@
 tools_input(zone_type* zone)
 {
     ods_status status = ODS_STATUS_OK;
-    int error = 0;
     char* tmpname = NULL;
     char* lockname = NULL;
     time_t start = 0;
@@ -106,17 +105,18 @@
             }
             ods_log_assert(fd); /* locked */
 
-            error = ods_file_copy(tmpname, zone->adinbound->configstr);
+            status = ods_file_copy(tmpname, zone->adinbound->configstr);
 
             fclose(fd);
             (void) unlink(lockname); /* unlocked */
 
-            if (error) {
-                ods_log_error("[%s] unable to copy axfr file %s to %s",
-                    tools_str, tmpname, zone->adinbound->configstr);
+            if (status != ODS_STATUS_OK) {
+                ods_log_error("[%s] unable to copy axfr file %s to %s: %s"
+                    "%s", tools_str, tmpname, zone->adinbound->configstr,
+                    ods_status2str(status));
                 free((void*)tmpname);
                 free((void*)lockname);
-                return ODS_STATUS_ERR;
+                return status;
             }
             free((void*)tmpname);
             free((void*)lockname);




More information about the Opendnssec-commits mailing list