[PATCH] Adds the ability to abort an MD5 sum check.

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

 



If the user presses [ENTER] then the check will exit. The return code
will be 2 and a message stating the check was aborted displayed to the
user.

Bumps the version from 1.0.5 to 1.0.6.

Signed-off-by: Darryl L. Pierce <dpierce@xxxxxxxxxx>
---
 Makefile         |    2 +-
 checkisomd5.c    |   24 +++++++++++++++++++++++-
 libcheckisomd5.c |    2 +-
 libcheckisomd5.h |    2 +-
 4 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/Makefile b/Makefile
index 9c209ad..214c2bf 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ PYVER  := $(shell python -c 'import sys; print sys.version[0:3]')
 PYTHON = python$(PYVER)
 PYTHONINCLUDE = /usr/include/$(PYTHON)
 
-VERSION=1.0.5
+VERSION=1.0.6
 
 ifneq (,$(filter sparc64 ppc64 x86_64 s390x,$(shell uname -m)))
 LIBDIR = lib64
diff --git a/checkisomd5.c b/checkisomd5.c
index c721f86..dc2c41e 100644
--- a/checkisomd5.c
+++ b/checkisomd5.c
@@ -32,7 +32,23 @@ struct progressCBData {
     int gaugeat;
 };
 
-static void outputCB(void *co, long long offset, long long total) {
+int user_bailing_out() {
+  int retval = 0;
+  struct timeval timev;
+  fd_set rfds;
+
+  FD_ZERO(&rfds);
+  FD_SET(0,&rfds);
+
+  timev.tv_sec = 0;
+  timev.tv_usec = 0;
+
+  retval = select(1, &rfds, NULL, NULL, &timev);
+
+  return retval;
+}
+
+static int outputCB(void *co, long long offset, long long total) {
     struct progressCBData *data = co;
     int gaugeval = -1;
 
@@ -48,6 +64,8 @@ static void outputCB(void *co, long long offset, long long total) {
             data->gaugeat = gaugeval;
         }
     }
+
+    return user_bailing_out();
 }
 
 static void usage(void) {
@@ -101,6 +119,8 @@ int main(int argc, char **argv) {
     if (md5only)
 	exit(0);
 
+    printf("Press [ENTER] to abort check.\n");
+
     rc = mediaCheckFile((char *)args[0], outputCB, &data);
 
     if (data.verbose)
@@ -108,6 +128,8 @@ int main(int argc, char **argv) {
 
     if (rc == 0)
 	result = "FAIL.\n\nIt is not recommended to use this media.";
+    else if (rc == 2)
+      result = "UNKNOWN.\n\nThe media check was aborted.";
     else if (rc > 0)
 	result = "PASS.\n\nIt is OK to use this media.";
     else
diff --git a/libcheckisomd5.c b/libcheckisomd5.c
index 435f2c1..cd450df 100644
--- a/libcheckisomd5.c
+++ b/libcheckisomd5.c
@@ -270,7 +270,7 @@ static int checkmd5sum(int isofd, char *mediasum, char *computedsum, checkCallba
         }
 	offset = offset + nread;
 	if (cb)
-	    cb(cbdata, offset, isosize - skipsectors*2048);
+          if(cb(cbdata, offset, isosize - skipsectors*2048)) return 2;
     }
 
     if (cb)
diff --git a/libcheckisomd5.h b/libcheckisomd5.h
index 96f1ae9..5569a85 100644
--- a/libcheckisomd5.h
+++ b/libcheckisomd5.h
@@ -1,7 +1,7 @@
 #ifndef __LIBCHECKISOMD5_H__
 #define  __LIBCHECKISOMD5_H__
 
-typedef void (*checkCallback)(void *, long long offset, long long total);
+typedef int (*checkCallback)(void *, long long offset, long long total);
 
 int mediaCheckFile(char *iso, checkCallback cb, void *cbdata);
 void printMD5SUM(char *file);
-- 
1.6.5.2

_______________________________________________
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