[PATCH 3/3] Change printMD5SUM to return an error code instead of exit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This moves error reporting out of printMD5SUM into the call in
checkisomd5.c
---
 checkisomd5.c    |   16 ++++++++++++++--
 libcheckisomd5.c |   18 +++++++-----------
 libcheckisomd5.h |    2 +-
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/checkisomd5.c b/checkisomd5.c
index c721f86..029a9f1 100644
--- a/checkisomd5.c
+++ b/checkisomd5.c
@@ -95,8 +95,20 @@ int main(int argc, char **argv) {
     if (!args || !args[0] || !args[0][0])
 	usage();
 
-    if (md5only|data.verbose)
-	printMD5SUM((char *)args[0]);
+    if (md5only|data.verbose) {
+	rc = printMD5SUM((char *)args[0]);
+
+        if (rc < 0) {
+            if (rc == -1)
+                result = "NA.\nNo checksum information available, unable to verify media.";
+            else if (rc == -2)
+                result = "NA.\n\nFile open failed.";
+            else
+                result = "NA.\n\nUnknown return code from printMD5SUM()";
+            fprintf(stderr, "\n%s\n", result);
+            exit(abs(rc));
+        }
+    }
 
     if (md5only)
 	exit(0);
diff --git a/libcheckisomd5.c b/libcheckisomd5.c
index 8bdb1a4..dbb22bb 100644
--- a/libcheckisomd5.c
+++ b/libcheckisomd5.c
@@ -335,7 +335,7 @@ int mediaCheckFile(char *file, checkCallback cb, void *cbdata) {
     return rc;
 }
 
-void printMD5SUM(char *file) {
+int printMD5SUM(char *file) {
     int isofd;
     char mediasum[64];
     long long isosize;
@@ -347,24 +347,20 @@ void printMD5SUM(char *file) {
     isofd = open(file, O_RDONLY);
 
     if (isofd < 0) {
-	fprintf(stderr, "%s: Unable to find install image.\n", file);
-	exit(2);
+        return -2;
     }
 
     if (parsepvd(isofd, mediasum, &skipsectors, &isosize, &supported, fragmentsums, &fragmentcount) < 0) {
-	fprintf(stderr, "%s: Could not get pvd data", file);
-	fprintf(stderr, "\nUnable to read the disc checksum from the "
-			 "primary volume descriptor.\nThis probably "
-			 "means the disc was created without adding the "
-			 "checksum.");
-	exit(1);
+        return -1;
     }
 
     close(isofd);
-    
+
     printf("%s:   %s\n", file, mediasum);
     if ( (strlen(fragmentsums) > 0) && (fragmentcount > 0) ) {
         printf("Fragment sums: %s\n", fragmentsums);
-        printf("Fragment count: %lld\n", fragmentcount); 
+        printf("Fragment count: %lld\n", fragmentcount);
     }
+
+    return 0;
 }
diff --git a/libcheckisomd5.h b/libcheckisomd5.h
index 96f1ae9..e9f7e5d 100644
--- a/libcheckisomd5.h
+++ b/libcheckisomd5.h
@@ -4,6 +4,6 @@
 typedef void (*checkCallback)(void *, long long offset, long long total);
 
 int mediaCheckFile(char *iso, checkCallback cb, void *cbdata);
-void printMD5SUM(char *file);
+int printMD5SUM(char *file);
 
 #endif
-- 
1.6.6.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux