On Thursday, 2 November 2006 11:29, Rafael J. Wysocki wrote: > On Thursday, 2 November 2006 11:24, Pavel Machek wrote: > > Hi! > > > > > The appended patch allows the users of suspend to abort the image saving > > > by > > > pressing Ctrl+c. > > > > It would be nice to abort with escape or something... ctrl+c is going > > to be "interesting" for users using splashscreen. > > OK > > > > - printf("suspend: Saving image data pages (%u pages) ... ", > > > nr_pages); > > > + /* Switch the state of the terminal so that we can read the keyboard > > > + * without blocking and with no echo. > > > + * > > > + * stdin must be attached to the terminal now. > > > + */ > > > + abort_possible = !tcgetattr(0 , &savedtrm); > > > > Extra space before , ... > > Yes, thanks. > > > > @@ -451,20 +476,34 @@ static int save_image(struct swap_map_ha > > > error = swap_write_page(handle); > > > if (error) > > > break; > > > + > > > 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 == 3) { > > > + printf(" aborted!\n"); > > > + return -EINTR; > > > + } > > > > So you can easily switch to escape here, right? > > Sure, no problem. > > > Otherwise it looks okay. > > Thanks.
Another go. Added #defines for the abort key code and name to swsusp.h in case somebody wants to change them without hacking the code. --- suspend.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++--- swsusp.h | 3 +++ 2 files changed, 49 insertions(+), 3 deletions(-) Index: suspend/suspend.c =================================================================== --- suspend.orig/suspend.c +++ suspend/suspend.c @@ -31,6 +31,7 @@ #include <string.h> #include <errno.h> #include <signal.h> +#include <termios.h> #ifdef CONFIG_COMPRESS #include <lzf.h> #else @@ -442,17 +443,42 @@ static int save_image(struct swap_map_ha unsigned int nr_pages) { unsigned int m, writeout_rate; - int ret; + int ret, abort_possible; + struct termios newtrm, savedtrm; + char c = 0; int error = 0; - printf("suspend: Saving image data pages (%u pages) ... ", nr_pages); + /* Switch the state of the terminal so that we can read the keyboard + * without blocking and with no echo. + * + * 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); + } + if (abort_possible) + printf("suspend: Saving %u image data pages " + "(press " ABORT_KEY_NAME " to abort) ... ", + nr_pages); + else + printf("suspend: Saving image data pages (%u pages) ... ", + nr_pages); + m = nr_pages / 100; if (!m) m = 1; + if (early_writeout) writeout_rate = m; else writeout_rate = nr_pages; + nr_pages = 0; do { ret = read(handle->dev, handle->page_buffer, page_size); @@ -460,20 +486,34 @@ static int save_image(struct swap_map_ha error = swap_write_page(handle); if (error) break; + 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 (!(nr_pages % writeout_rate)) start_writeout(handle->fd); + nr_pages++; } } while (ret > 0); if (ret < 0) error = -errno; + if (!error) printf(" done (%u pages)\n", nr_pages); + if (abort_possible) + tcsetattr(0, TCSANOW, &savedtrm); + return error; } @@ -1307,8 +1347,11 @@ int main(int argc, char *argv[]) splash_prepare(&splash, splash_param); - if (lock_vt() < 0) + if (lock_vt() < 0) { + ret = errno; + fprintf(stderr, "suspend: Could not lock the terminal\n"); goto Restore_console; + } splash.progress(5); Index: suspend/swsusp.h =================================================================== --- suspend.orig/swsusp.h +++ suspend/swsusp.h @@ -212,3 +212,6 @@ struct buf_block { #endif #define PARAM_NO (GEN_PARAM + COMPRESS_PARAM + ENCRYPT_PARAM) + +#define ABORT_KEY_CODE 27 +#define ABORT_KEY_NAME "ESC" ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 _______________________________________________ Suspend-devel mailing list Suspend-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/suspend-devel