All of lore.kernel.org
 help / color / mirror / Atom feed
From: Allan Graves <allan.graves@oracle.com>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: [uml-devel] new patch
Date: Fri, 26 Aug 2005 15:56:16 -0400	[thread overview]
Message-ID: <430F73E0.3050508@oracle.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 53 bytes --]

Jeff, here we have fscanf. :)
Sorry bout that.
Allan

[-- Attachment #2: interrupt.patch --]
[-- Type: text/plain, Size: 2837 bytes --]

--- uml_mconsole.c.orig	2005-08-26 13:08:33.000000000 -0400
+++ uml_mconsole.c	2005-08-26 15:53:11.000000000 -0400
@@ -37,13 +37,20 @@
 #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;
+  char pid[32]="";
+  int x=-1;
 
   if(stat(file, &buf) == -1){
     fprintf(stderr, "Warning: couldn't stat file: %s - ", file);
@@ -53,6 +60,18 @@
   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"))) {
+    uml_pid=-1;
+    return(0);
+  }
+
+  if(fscanf(fd, "%ld", &uml_pid)!=1){
+    uml_pid=-1;
+    return(0);
+  }
   return(0);
 }
 
@@ -65,19 +84,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 +286,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 +367,19 @@
   return(0);
 }
 
+static int int_cmd(int fd, char *command)
+{
+
+  if (uml_pid == -1) {
+    printf("Cannot determine the PID of your UML session, not sending signal.\n");
+    return(0);
+  }
+
+  kill(uml_pid, SIGINT);
+
+  return(0);
+}
+
 struct cmd {
   char *command;
   int (*proc)(int, char *);
@@ -355,6 +391,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" */
 };

                 reply	other threads:[~2005-08-26 19:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=430F73E0.3050508@oracle.com \
    --to=allan.graves@oracle.com \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.