Hi, To be able to abort suspending while using splashy, we have to move the abort logic to the splashy struct so it can be overridden when libsplashy is used for splashy support.
OK to commit? grts Tim Index: splash.c =================================================================== RCS file: /cvsroot/suspend/suspend/splash.c,v retrieving revision 1.4 diff -u -r1.4 splash.c --- splash.c 18 Sep 2006 12:00:09 -0000 1.4 +++ splash.c 9 Jan 2007 15:34:43 -0000 @@ -16,6 +16,8 @@ #include "bootsplash.h" #include "splashy_funcs.h" #include "encrypt.h" +#include <unistd.h> +#include <termios.h> /** * dummy functions in case if no splash system was found or @@ -32,6 +34,33 @@ printf(prompt); return getchar(); } +static int prepare_abort(struct termios *oldtrm, struct termios *newtrm) { + int ret; + + ret = !tcgetattr(0, oldtrm); + if (ret) { + *newtrm = *oldtrm; + newtrm->c_cc[VMIN] = 0; + newtrm->c_cc[VTIME] = 1; + newtrm->c_iflag = IGNBRK | IGNPAR | ICRNL | IMAXBEL; + newtrm->c_lflag = 0; + ret = !tcsetattr(0, TCSANOW, newtrm); + } + + return ret; +} + +static int key_pressed(const char key){ + char c; + if (read(0, &c, 1) > 0 && c == key) + return 1; + + return 0; +} + +static void restore_abort(struct termios *oldtrm) { + tcsetattr(0, TCSANOW, oldtrm); +} /* Tries to find a splash system and initializes interface functions */ void splash_prepare(struct splash *splash, int enabled) @@ -47,6 +76,9 @@ #else splash->read_password = splash_dummy_readpass; #endif + splash->prepare_abort = prepare_abort; + splash->restore_abort = restore_abort; + splash->key_pressed = key_pressed; if (!enabled) return; Index: splash.h =================================================================== RCS file: /cvsroot/suspend/suspend/splash.h,v retrieving revision 1.3 diff -u -r1.3 splash.h --- splash.h 18 Sep 2006 12:00:09 -0000 1.3 +++ splash.h 9 Jan 2007 15:34:43 -0000 @@ -12,6 +12,8 @@ #ifndef SPLASH_H #define SPLASH_H +#include <termios.h> + /* generic interface functions for an arbitary splash method */ struct splash { int (*finish) (void); @@ -19,6 +21,9 @@ void (*switch_to) (void); void (*read_password) (char *, int); int (*dialog) (const char *); + int (*prepare_abort) (struct termios *, struct termios *); + int (*key_pressed) (const char key); + void (*restore_abort) (struct termios *); }; void splash_prepare(struct splash *splash, int enabled); Index: suspend.c =================================================================== RCS file: /cvsroot/suspend/suspend/suspend.c,v retrieving revision 1.65 diff -u -r1.65 suspend.c --- suspend.c 7 Nov 2006 21:13:33 -0000 1.65 +++ suspend.c 9 Jan 2007 15:34:43 -0000 @@ -446,7 +446,6 @@ unsigned int m, writeout_rate; int ret, abort_possible; struct termios newtrm, savedtrm; - char c = 0; int error = 0; /* Switch the state of the terminal so that we can read the keyboard @@ -454,15 +453,8 @@ * * stdin must be attached to the terminal now. */ - abort_possible = !tcgetattr(0, &savedtrm); - if (abort_possible) { - newtrm = savedtrm; - newtrm.c_cc[VMIN] = 0; - newtrm.c_cc[VTIME] = 1; - newtrm.c_iflag = IGNBRK | IGNPAR | ICRNL | IMAXBEL; - newtrm.c_lflag = 0; - abort_possible = !tcsetattr(0, TCSANOW, &newtrm); - } + abort_possible = splash.prepare_abort(&savedtrm, &newtrm); + if (abort_possible) printf("suspend: Saving %u image data pages " "(press " ABORT_KEY_NAME " to abort) ... ", @@ -491,13 +483,11 @@ if (!(nr_pages % m)) { printf("\b\b\b\b%3d%%", nr_pages / m); splash.progress(20 + (nr_pages / m) * 0.75); - if (abort_possible) { - ret = read(0, &c, 1); - if (ret > 0 && c == ABORT_KEY_CODE) { - printf(" aborted!\n"); - return -EINTR; - } - ret = 1; + if (abort_possible && + splash.key_pressed(ABORT_KEY_CODE) ) { + + printf(" aborted!\n"); + return -EINTR; } } if (!(nr_pages % writeout_rate)) @@ -513,7 +503,7 @@ printf(" done (%u pages)\n", nr_pages); if (abort_possible) - tcsetattr(0, TCSANOW, &savedtrm); + splash.restore_abort(&savedtrm); return error; } ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Suspend-devel mailing list Suspend-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/suspend-devel