Support in the lguest userpace utility for triple-Ctrl-Z. Three fast  
taps of Ctrl-Z will suspend the lguest VM.

Signed-off-by: Mark Wallis <[EMAIL PROTECTED]>

--- lguest.orig 2008-01-31 12:23:53.000000000 +1100
+++ lguest.c    2008-01-31 12:23:37.000000000 +1100
@@ -689,7 +689,7 @@
        tcsetattr(STDIN_FILENO, TCSANOW, &orig_term);
  }

-/* We associate some data with the console for our exit hack. */
+/* We associate some data with the console for our exit and suspend  
hacks. */
  struct console_abort
  {
        /* How many times have they hit ^C? */
@@ -698,6 +698,12 @@
        struct timeval start;
  };

+struct console_suspend
+{
+       int count;
+       struct timeval start;
+};
+
  /* This is the routine which handles console input (ie. stdin). */
  static bool handle_console_input(int fd, struct device *dev)
  {
@@ -706,6 +712,7 @@
        unsigned int num;
        struct iovec iov[LGUEST_MAX_DMA_SECTIONS];
        struct console_abort *abort = dev->priv;
+       struct console_suspend *suspend = dev->priv;

        /* First we get the console buffer from the Guest.  The key is dev- 
 >mem
         * which was set to 0 in setup_console(). */
@@ -757,9 +764,23 @@
                        }
                        abort->count = 0;
                }
-       } else
-               /* Any other key resets the abort counter. */
+       } else if (len == 1 && ((char *)iov[0].iov_base)[0] == 26) {
+               if (!suspend->count++)
+                       gettimeofday(&suspend->start, NULL);
+               else if (suspend->count == 3) {
+                       struct timeval now;
+                       gettimeofday(&now, NULL);
+                       if (now.tv_sec <= suspend->start.tv_sec+1) {
+                               // Suspend the lguest process
+                               kill(getpid(), SIGSTOP);
+                               cfmakeraw(&orig_term);
+                       }
+                       suspend->count = 0;
+               }
+       } else {
+               suspend->count = 0;
                abort->count = 0;
+       }

        /* Now, if we didn't read anything, put the input terminal back and
         * return failure (meaning, don't call us again). */





_______________________________________________
Lguest mailing list
[email protected]
https://ozlabs.org/mailman/listinfo/lguest

Reply via email to