[prev in list] [next in list] [prev in thread] [next in thread] 

List:       user-mode-linux-devel
Subject:    [uml-devel] patch, try #3 for interrupt
From:       Allan Graves <allan.graves () oracle ! com>
Date:       2005-08-26 22:10:50
Message-ID: 430F936A.9020404 () oracle ! com
[Download RAW message or body]

I must be perfect.  Really, really perfect.  If not, Jeff will make me.

["interrupt.patch" (text/plain)]

--- uml_mconsole.c.orig	2005-08-26 13:08:33.000000000 -0400
+++ uml_mconsole.c	2005-08-26 18:07:10.000000000 -0400
@@ -37,13 +37,18 @@
 #include <sys/uio.h>
 #include <readline/readline.h>
 #include <readline/history.h>
+#include <signal.h>
+
 
 static char uml_name[11];
 static struct sockaddr_un sun;
+static long int uml_pid;
 
-static int do_switch(char *file, char *name)
+static int do_switch(char *dir, char *file, char *name)
 {
   struct stat buf;
+  char pid_path[MAXPATHLEN + 1]="";
+  FILE *fd;
 
   if(stat(file, &buf) == -1){
     fprintf(stderr, "Warning: couldn't stat file: %s - ", file);
@@ -53,6 +58,14 @@
   sun.sun_family = AF_UNIX;
   strncpy(sun.sun_path, file, sizeof(sun.sun_path));
   strncpy(uml_name, name, sizeof(uml_name));
+
+  /* Open and read PID file */
+  snprintf(pid_path, sizeof(pid_path), "%s/%s/pid", dir, name);
+  if(!(fd=fopen(pid_path, "r")) || (fscanf(fd, "%ld", &uml_pid)!=1)) {
+      uml_pid=-1;
+      return(0);
+  }
+
   return(0);
 }
 
@@ -65,19 +78,22 @@
     snprintf(dir, sizeof(dir), "%s/.uml", home);
     snprintf(file, sizeof(file), "%s/%s/mconsole", dir, name);
     if(strncmp(name, dir, strlen(dir))){
-      if(!do_switch(file, name)) return(0);
+      if(!do_switch(dir,file, name)) return(0);
       try_file = 0;
     }
   }
 
+  snprintf(dir, sizeof(dir), "/tmp/uml/%s", name);
   snprintf(tmp, sizeof(tmp), "/tmp/uml/%s/mconsole", name);
   if(strncmp(name, "/tmp/uml/", strlen("/tmp/uml/"))){
-    if(!do_switch(tmp, name)) return(0);
+    if(!do_switch(dir,tmp, name)) return(0);
   }
 
-  if(!do_switch(name, name)) return(0);
+
+  snprintf(dir, sizeof(dir), "./");
+  if(!do_switch(dir, name, name)) return(0);
   if(!try_file) return(-1);
-  return(do_switch(file, name));
+  return(do_switch(dir,file, name));
 }
 
 #define MCONSOLE_MAGIC (0xcafebabe)
@@ -264,7 +280,8 @@
     quit - Quit mconsole\n\
     switch <socket-name> - Switch control to the given machine\n\
     log -f <filename> - use contents of <filename> as UML log messages\n\
-    mconsole-version - version of this mconsole program\n";
+    mconsole-version - version of this mconsole program\n\
+    int  - Interrupt UML session \n";
 
 static int help_cmd(int fd, char *command)
 {
@@ -344,6 +361,24 @@
   return(0);
 }
 
+static int int_cmd(int fd, char *command)
+{
+  extern int errno;
+  char er_string[255];
+
+  if (uml_pid == -1) {
+    perror("Cannot determine the PID of your UML session, not sending signal.\n");
+    return(0);
+  }
+
+  if(kill(uml_pid, SIGINT) == -1) {
+    sprintf(er_string, "Unable to interrupt process %ld.\n", uml_pid);
+    perror(er_string);
+  }
+
+  return(0);
+}
+
 struct cmd {
   char *command;
   int (*proc)(int, char *);
@@ -355,6 +390,7 @@
   { "switch", switch_cmd },
   { "log", log_cmd },
   { "mconsole-version", mversion_cmd },
+  { "int", int_cmd },
   { NULL, default_cmd }
   /* default_cmd means "send it to the UML" */
 };

-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic