[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r5333 - in trunk/OpenDNSSEC/signer/src: shared signer

Matthijs Mekking matthijs at nlnetlabs.nl
Thu Jul 14 13:10:40 CEST 2011


Author: matthijs
Date: 2011-07-14 13:10:39 +0200 (Thu, 14 Jul 2011)
New Revision: 5333

Modified:
   trunk/OpenDNSSEC/signer/src/shared/file.c
   trunk/OpenDNSSEC/signer/src/shared/file.h
   trunk/OpenDNSSEC/signer/src/signer/tools.c
Log:
Pivotal Story #15342489: Return better error codes from ods_file_copy
https://www.pivotaltracker.com/story/show/15342489

Chore



Modified: trunk/OpenDNSSEC/signer/src/shared/file.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/shared/file.c	2011-07-14 08:06:11 UTC (rev 5332)
+++ trunk/OpenDNSSEC/signer/src/shared/file.c	2011-07-14 11:10:39 UTC (rev 5333)
@@ -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,17 @@
         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:
+                ods_log_error("[%s] %s failed: return value %i",
+                    file_str, CP_COMMAND, retval);
+                return ODS_STATUS_ERR;
+        }
     }
-    /* no such file */
-    return 1;
+    return ODS_STATUS_FOPEN_ERR;
 }
 
 /**

Modified: trunk/OpenDNSSEC/signer/src/shared/file.h
===================================================================
--- trunk/OpenDNSSEC/signer/src/shared/file.h	2011-07-14 08:06:11 UTC (rev 5332)
+++ trunk/OpenDNSSEC/signer/src/shared/file.h	2011-07-14 11:10:39 UTC (rev 5333)
@@ -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: trunk/OpenDNSSEC/signer/src/signer/tools.c
===================================================================
--- trunk/OpenDNSSEC/signer/src/signer/tools.c	2011-07-14 08:06:11 UTC (rev 5332)
+++ trunk/OpenDNSSEC/signer/src/signer/tools.c	2011-07-14 11:10:39 UTC (rev 5333)
@@ -49,7 +49,6 @@
 tools_input(zone_type* zone)
 {
     ods_status status = ODS_STATUS_OK;
-    int error = 0;
     char* tmpname = NULL;
     time_t start = 0;
     time_t end = 0;
@@ -79,16 +78,16 @@
 
     if (zone->adinbound->type == ADAPTER_FILE) {
         if (zone->fetch) {
-            ods_log_verbose("fetch zone %s",
+            ods_log_verbose("[%s] fetch zone %s", tools_str,
                 zone->name?zone->name:"(null)");
             tmpname = ods_build_path(
                 zone->adinbound->configstr, ".axfr", 0);
-            error = ods_file_copy(tmpname, zone->adinbound->configstr);
-            if (error) {
-                ods_log_error("[%s] unable to copy axfr file %s to %s",
-                    tools_str, tmpname, zone->adinbound->configstr);
-                free((void*)tmpname);
-                return ODS_STATUS_ERR;
+            status = ods_file_copy(tmpname, zone->adinbound->configstr);
+            if (status != ODS_STATUS_OK) {
+                ods_log_error("[%s] unable to copy axfr file %s to %s: %s",
+                    tools_str, tmpname, zone->adinbound->configstr,
+                    ods_status2str(status));
+                return status;
             }
             free((void*)tmpname);
         }
@@ -106,8 +105,8 @@
         free((void*)tmpname);
         tmpname = NULL;
         if (status != ODS_STATUS_OK) {
-            ods_log_error("[%s] unable to copy zone input file %s: "
-                "%s", tools_str, zone->name?zone->name:"(null)",
+            ods_log_error("[%s] unable to copy zone input file %s: %s",
+                tools_str, zone->name?zone->name:"(null)",
                 ods_status2str(status));
         }
     }




More information about the Opendnssec-commits mailing list