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. Signed-off-by: Darryl L. Pierce <dpierce@xxxxxxxxxx> --- checkisomd5.c | 25 ++++++++++++++++++++++++- libcheckisomd5.c | 3 ++- libcheckisomd5.h | 2 +- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/checkisomd5.c b/checkisomd5.c index c721f86..af582c1 100644 --- a/checkisomd5.c +++ b/checkisomd5.c @@ -22,6 +22,7 @@ #include <stdlib.h> #include <string.h> #include <popt.h> +#include <sys/select.h> #include "md5.h" #include "libcheckisomd5.h" @@ -32,7 +33,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 +65,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 +120,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 +129,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..7ad93df 100644 --- a/libcheckisomd5.c +++ b/libcheckisomd5.c @@ -29,6 +29,7 @@ #include <unistd.h> #include <fcntl.h> #include <string.h> +#include <sys/select.h> #include "md5.h" #include "libcheckisomd5.h" @@ -270,7 +271,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