[PATCH isomd5sum rhel6 5/5] Abort check with 'Esc' instead of 'Enter' (#555107)

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

 



Needs to switch off terminal line buffering during the check.
---
 checkisomd5.1 |    2 +-
 checkisomd5.c |   15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/checkisomd5.1 b/checkisomd5.1
index 295b45a..ea45f66 100644
--- a/checkisomd5.1
+++ b/checkisomd5.1
@@ -8,7 +8,7 @@ checkisomd5 \(em check an MD5 checksum implanted by \fBimplantisomd5\fR
 .PP
 This manual page documents briefly the \fBcheckisomd5\fR command.  \fBcheckisomd5\fR is a program that checks an embedded MD5 checksum in a ISO9660 image (.iso), or block device.  The checksum is embedded by the corresponding \fBimplantisomd5\fR command.
 .PP
-The check can be aborted by pressing ENTER key.
+The check can be aborted by pressing Esc key.
 .PP
 Program returns exit status 0 if the checksum is correct, or 1 if the checksum is incorrect, non-existent, or check was aborted.
 .SH "OPTIONS"
diff --git a/checkisomd5.c b/checkisomd5.c
index d306b3f..67041a1 100644
--- a/checkisomd5.c
+++ b/checkisomd5.c
@@ -22,6 +22,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <popt.h>
+#include <termios.h>
 
 #include "md5.h"
 #include "libcheckisomd5.h"
@@ -36,6 +37,7 @@ int user_bailing_out() {
   int retval = 0;
   struct timeval timev;
   fd_set rfds;
+  char ch;
 
   FD_ZERO(&rfds);
   FD_SET(0,&rfds);
@@ -43,7 +45,9 @@ int user_bailing_out() {
   timev.tv_sec = 0;
   timev.tv_usec = 0;
 
-  retval = select(1, &rfds, NULL, NULL, &timev);
+  if (select(1, &rfds, NULL, NULL, &timev))
+    if ((ch = getchar()) == 27)
+      retval = 1;
 
   return retval;
 }
@@ -97,6 +101,8 @@ int main(int argc, char **argv) {
 	{ 0, 0, 0, 0, 0}
     };
 
+    static struct termios oldt, newt;
+
     optCon = poptGetContext("checkisomd5", argc, (const char **)argv, options, 0);
 
     if ((rc = poptGetNextOpt(optCon)) < -1) {
@@ -119,9 +125,14 @@ int main(int argc, char **argv) {
     if (md5only)
 	exit(0);
 
-    printf("Press [ENTER] to abort check.\n");
+    printf("Press [Esc] to abort check.\n");
 
+    tcgetattr(0, &oldt);
+    newt = oldt;
+    newt.c_lflag &= ~(ICANON | ECHO | ECHONL | ISIG | IEXTEN);
+    tcsetattr(0, TCSANOW, &newt);
     rc = mediaCheckFile((char *)args[0], outputCB, &data);
+    tcsetattr(0, TCSANOW, &oldt);
 
     if (data.verbose)
 	printf("\n");
-- 
1.6.0.6

_______________________________________________
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