On Friday 27 July 2007, Alon Bar-Lev wrote: > On Friday 27 July 2007, Rafael J. Wysocki wrote: > > Apart from this you should also clear the PLATFORM_SUSPEND flag in the image > > header. Otherwise, resume will be confused if shutdown_method is originally > > set to "platform".
Well... This is cleaner patch, with somewhat more modification. It introduces a single variable that controls the shutdown method. Best Regards, Alon Bar-Lev. --- Index: splash.c =================================================================== RCS file: /cvsroot/suspend/suspend/splash.c,v retrieving revision 1.7 diff -u -B -r1.7 splash.c --- splash.c 12 May 2007 20:37:47 -0000 1.7 +++ splash.c 28 Jul 2007 09:41:11 -0000 @@ -51,13 +51,13 @@ return ret; } -static int key_pressed(const char key) +static char key_pressed(void) { char c; - if (read(0, &c, 1) > 0 && c == key) - return 1; + if (read(0, &c, 1) == 0) + return 0; - return 0; + return c; } static void restore_abort(struct termios *oldtrm) Index: splash.h =================================================================== RCS file: /cvsroot/suspend/suspend/splash.h,v retrieving revision 1.5 diff -u -B -r1.5 splash.h --- splash.h 12 May 2007 20:37:47 -0000 1.5 +++ splash.h 28 Jul 2007 09:41:11 -0000 @@ -25,7 +25,7 @@ void (*read_password) (char *, int); int (*dialog) (const char *); int (*prepare_abort) (struct termios *, struct termios *); - int (*key_pressed) (const char key); + char (*key_pressed) (void); void (*restore_abort) (struct termios *); }; Index: suspend.c =================================================================== RCS file: /cvsroot/suspend/suspend/suspend.c,v retrieving revision 1.80 diff -u -B -r1.80 suspend.c --- suspend.c 13 May 2007 20:16:53 -0000 1.80 +++ suspend.c 28 Jul 2007 09:41:12 -0000 @@ -80,8 +76,12 @@ static char early_writeout; static char splash_param; #define SHUTDOWN_LEN 16 -static char shutdown_method[SHUTDOWN_LEN] = "platform"; -static int use_platform_suspend; +static char shutdown_method_value[SHUTDOWN_LEN] = ""; +static enum { + SHUTDOWN_METHOD_SHUTDOWN, + SHUTDOWN_METHOD_PLATFORM, + SHUTDOWN_METHOD_REBOOT +} shutdown_method = SHUTDOWN_METHOD_PLATFORM; static int suspend_swappiness = SUSPEND_SWAPPINESS; static struct splash splash; @@ -160,7 +160,7 @@ { .name = "shutdown method", .fmt = "%s", - .ptr = shutdown_method, + .ptr = shutdown_method_value, .len = SHUTDOWN_LEN, }, }; @@ -489,11 +491,18 @@ if (!(nr_pages % m)) { printf("\b\b\b\b%3d%%", nr_pages / m); splash.progress(20 + (nr_pages / m) * 0.75); - if (abort_possible && - splash.key_pressed(ABORT_KEY_CODE)) { - printf(" aborted!\n"); - return -EINTR; + switch (splash.key_pressed()) { + case ABORT_KEY_CODE: + if (abort_possible) { + printf(" aborted!\n"); + return -EINTR; + } + break; + case REBOOT_KEY_CODE: + printf (" reboot enabled\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); + shutdown_method = SHUTDOWN_METHOD_REBOOT; + break; } } if (!(nr_pages % writeout_rate)) @@ -597,8 +606,6 @@ header->image_flags |= IMAGE_COMPRESSED; max_block_size += sizeof(short); } - if (use_platform_suspend) - header->image_flags |= PLATFORM_SUSPEND; #ifdef CONFIG_ENCRYPT if (encrypt) { @@ -649,6 +656,14 @@ gettimeofday(&begin, NULL); error = save_image(&handle, header->pages - 1); } + + /* + * NOTICE: + * This should be after save_image() as + * the user may modify the behavior + */ + if (shutdown_method == SHUTDOWN_METHOD_PLATFORM) + header->image_flags |= PLATFORM_SUSPEND; } if (!error) { error = flush_swap_writer(&handle); @@ -728,9 +743,9 @@ static void suspend_shutdown(int snapshot_fd) { - if (!strcmp(shutdown_method, "reboot")) { + if (shutdown_method == SHUTDOWN_METHOD_REBOOT) { reboot(); - } else if (use_platform_suspend) { + } else if (shutdown_method == SHUTDOWN_METHOD_PLATFORM) { int ret = platform_enter(snapshot_fd); if (ret < 0) suspend_error("pm_ops->enter failed, calling power_off."); @@ -769,12 +784,12 @@ if (error) goto Unfreeze; - if (use_platform_suspend) { + if (shutdown_method == SHUTDOWN_METHOD_PLATFORM) { int ret = platform_prepare(snapshot_fd); if (ret < 0) { suspend_error("pm_ops->prepare failed, using " "'shutdown mode = shutdown'."); - use_platform_suspend = 0; + shutdown_method = SHUTDOWN_METHOD_SHUTDOWN; } } @@ -832,7 +847,7 @@ /* We get here during the resume or when we failed to suspend. * Remember, suspend_shutdown() never returns! */ - if (use_platform_suspend) + if (shutdown_method == SHUTDOWN_METHOD_PLATFORM) platform_finish(snapshot_fd); Unfreeze: @@ -1318,9 +1333,17 @@ if (early_writeout != 'n' && early_writeout != 'N') early_writeout = 1; - use_platform_suspend = !strcmp(shutdown_method, "platform"); + if (!strcmp (shutdown_method_value, "shutdown")) { + shutdown_method = SHUTDOWN_METHOD_SHUTDOWN; + } + else if (!strcmp (shutdown_method_value, "platform")) { + shutdown_method = SHUTDOWN_METHOD_PLATFORM; + } + else if (!strcmp (shutdown_method_value, "reboot")) { + shutdown_method = SHUTDOWN_METHOD_REBOOT; + } page_size = getpagesize(); buffer_size = BUFFER_PAGES * page_size; mem_size = 3 * page_size + buffer_size; Index: swsusp.h =================================================================== RCS file: /cvsroot/suspend/suspend/swsusp.h,v retrieving revision 1.34 diff -u -B -r1.34 swsusp.h --- swsusp.h 16 Mar 2007 16:02:23 -0000 1.34 +++ swsusp.h 28 Jul 2007 09:41:12 -0000 @@ -216,3 +216,5 @@ #define ABORT_KEY_CODE 127 #define ABORT_KEY_NAME "backspace" +#define REBOOT_KEY_CODE 'r' +#define REBOOT_KEY_NAME "r" ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Suspend-devel mailing list Suspend-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/suspend-devel