On Fri, Oct 06, 2006 at 03:54:08PM +0200, Stefan Seyfried wrote: > Hi, > > i just had an idea :-)
ok, so how about this: Index: s2ram.c =================================================================== RCS file: /cvsroot/suspend/suspend/s2ram.c,v retrieving revision 1.45 diff -u -p -r1.45 s2ram.c --- s2ram.c 20 Sep 2006 16:23:51 -0000 1.45 +++ s2ram.c 6 Oct 2006 17:32:56 -0000 @@ -10,11 +10,15 @@ #include <getopt.h> #include <errno.h> #include <string.h> +#include <sys/ioctl.h> +#include <syscall.h> +#include <unistd.h> #define S2RAM #include "vbetool/vbetool.h" #include "vt.h" #include "s2ram.h" +#include "swsusp.h" static void *vbe_buffer; /* Flags set from whitelist */ @@ -192,9 +196,15 @@ int s2ram_prepare(void) } /* Actually enter the suspend. May be ran on frozen system. */ -int s2ram_do(void) +int s2ram_do(int frozen, int snapshot_fd) { int ret = 0; + if (frozen) { + printf("calling suspend_to_ram ioctl\n"); + ret = suspend_to_ram(snapshot_fd); + goto out; + } + FILE *f = fopen("/sys/power/state", "w"); if (!f) { printf("/sys/power/state does not exist; what kind of ninja mutant machine is this?\n"); @@ -211,6 +221,7 @@ int s2ram_do(void) ret = errno; perror("s2ram_do"); } + out: return ret; } @@ -267,7 +278,7 @@ static void usage(void) int main(int argc, char *argv[]) { int i, id = -1, ret = 0, test_mode = 0, force = 0; - int active_console = -1; + int active_console = -1, snapshot_fd = -1, frozen = 0; struct option options[] = { { "test", no_argument, NULL, 'n'}, { "help", no_argument, NULL, 'h'}, @@ -354,13 +365,24 @@ int main(int argc, char *argv[]) printf("Switching from vt%d to vt1\n", active_console); chvt(1); + snapshot_fd = open("/dev/snapshot", O_RDONLY); + if (snapshot_fd < 0) + fprintf(stderr, "s2ram: Could not open the snapshot device\n"); + else + frozen = !freeze(snapshot_fd); + + fprintf(stderr, "frozen: %d\n", frozen); ret = s2ram_hacks(); if (ret) goto out; - ret = s2ram_do(); + ret = s2ram_do(frozen, snapshot_fd); s2ram_resume(); out: + if (frozen) + unfreeze(snapshot_fd); + if (snapshot_fd > 0) + close(snapshot_fd); /* if we switched consoles before suspend, switch back */ if (active_console > 0) { printf("switching back to vt%d\n", active_console); Index: s2ram.h =================================================================== RCS file: /cvsroot/suspend/suspend/s2ram.h,v retrieving revision 1.4 diff -u -p -r1.4 s2ram.h --- s2ram.h 28 Mar 2006 13:16:21 -0000 1.4 +++ s2ram.h 6 Oct 2006 17:32:56 -0000 @@ -16,5 +16,5 @@ void dmi_scan(void); int s2ram_check(int id); int s2ram_hacks(void); int s2ram_prepare(void); -int s2ram_do(void); +int s2ram_do(int, int); void s2ram_resume(void); This worked for me on the one machine i have tested it with (and that does not need any workarounds), but this might not indicate anything, not even that this is a good idea or would be useful for anyhting :-) I think i need to link statically and use some mlockall() or something. At least that would explain the segfaults i get about every second try since i added that "calling ioctl" printf: maybe it wants to page in a part of libc but cannot because all processes are stopped? But other than those occasional segfaults, it works :-) Comments? -- Stefan Seyfried | "Please, just tell people QA / R&D Team Mobile Devices | to use KDE." SUSE LINUX Products GmbH, Nürnberg | -- Linus Torvalds ------------------------------------------------------------------------- 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