All of lore.kernel.org
 help / color / mirror / Atom feed
* [uml-devel] [PATCH] Mconsole exec support - rewritten completely
@ 2004-07-22 14:53 BlaisorBlade
  2004-07-26 18:16 ` Jeff Dike
  0 siblings, 1 reply; 3+ messages in thread
From: BlaisorBlade @ 2004-07-22 14:53 UTC (permalink / raw)
  To: user-mode-linux-devel, user-mode-linux-user; +Cc: Jeff Dike

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

This is a new version (much lighter) of the mconsole exec support.

I.e., from mconsole, you run "exec <whatever>" and inside the UML, the kernel 
will start /bin/sh -c "<whatever>"; I especially recommend using 
redirections. It is nice to do something like "exec exec /bin/bash <> 
/dev/tty2" to open a new temp console as root (adjust the command as needed).

This time, it simply exec "/bin/sh -c" with the right arguments, so it's much 
safer than the old version of one year ago. Jeff, you can still think that 
this feature should not be in the kernel support (but why then bother with 
the "proc" command?), even if this time there is no more any parsing code; 
but anyway, it will stay available for who wants it.

Bye
-- 
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729

[-- Attachment #2: mconsole_exec.patch --]
[-- Type: text/x-diff, Size: 4699 bytes --]



Adds the "exec" command to mconsole; the command is passed to /bin/sh -c, so
you know its syntax. It uses call_usermodehelper.


---

 uml-linux-2.6.7-paolo/arch/um/Kconfig                 |    9 +++++
 uml-linux-2.6.7-paolo/arch/um/drivers/mconsole_kern.c |   32 +++++++++++++++++-
 uml-linux-2.6.7-paolo/arch/um/drivers/mconsole_user.c |    4 ++
 uml-linux-2.6.7-paolo/arch/um/include/mconsole.h      |    1 
 4 files changed, 45 insertions(+), 1 deletion(-)

diff -puN arch/um/drivers/mconsole_kern.c~mconsole_exec arch/um/drivers/mconsole_kern.c
--- uml-linux-2.6.7/arch/um/drivers/mconsole_kern.c~mconsole_exec	2004-06-21 16:54:17.000000000 +0200
+++ uml-linux-2.6.7-paolo/arch/um/drivers/mconsole_kern.c	2004-06-21 16:54:17.000000000 +0200
@@ -19,6 +19,7 @@
 #include "linux/fs.h"
 #include "linux/namei.h"
 #include "linux/proc_fs.h"
+#include "linux/kmod.h"
 #include "asm/irq.h"
 #include "asm/uaccess.h"
 #include "user_util.h"
@@ -118,6 +119,27 @@ void mconsole_log(struct mc_request *req
 	mconsole_reply(req, "", 0, 0);
 }
 
+
+#ifdef CONFIG_MCONSOLE_EXEC
+void mconsole_exec(struct mc_request *req)
+{
+	int res;
+
+	char *envp[] = { "HOME=/", "TERM=linux", "PATH=/sbin:/usr/sbin:/bin:/usr/bin", NULL };
+	char *argv[] = { "/bin/sh", "-c", req->request.data + strlen("exec "), NULL };
+	res = call_usermodehelper("/bin/sh", argv, envp, 0);
+
+	if (res < 0) {
+		char buf[60];
+		snprintf(buf, 60, "call_usermodehelper failed in mconsole_exec with error code: %d", -res);
+		mconsole_reply(req, buf, 1, 0);
+		return;
+	}
+
+	mconsole_reply(req, "The command has been started successfully.", 0, 0);
+}
+#endif
+
 void mconsole_proc(struct mc_request *req)
 {
 	struct nameidata nd;
@@ -193,6 +215,14 @@ void mconsole_proc(struct mc_request *re
  out: ;
 }
 
+#ifdef CONFIG_MCONSOLE_EXEC
+#  define EXEC_HELPTEXT "\
+    exec <command> - runs the specified command through /bin/sh -c\n"
+#else
+#  define EXEC_HELPTEXT ""
+#endif
+
+    /*exec - execute a command as root inside the UML\n"*/
 #define UML_MCONSOLE_HELPTEXT \
 "Commands: \n\
     version - Get kernel version \n\
@@ -207,7 +237,7 @@ void mconsole_proc(struct mc_request *re
     cad - invoke the Ctl-Alt-Del handler \n\
     stop - pause the UML; it will do nothing until it receives a 'go' \n\
     go - continue the UML after a 'stop' \n\
-    log <string> - make UML enter <string> into the kernel log\n\
+    log <string> - make UML enter <string> into the kernel log\n" EXEC_HELPTEXT "\
     proc <file> - returns the contents of the UML's /proc/<file>\n\
 "
 
diff -puN arch/um/drivers/mconsole_user.c~mconsole_exec arch/um/drivers/mconsole_user.c
--- uml-linux-2.6.7/arch/um/drivers/mconsole_user.c~mconsole_exec	2004-06-21 16:54:17.000000000 +0200
+++ uml-linux-2.6.7-paolo/arch/um/drivers/mconsole_user.c	2004-06-21 16:54:17.000000000 +0200
@@ -16,6 +16,7 @@
 #include "user.h"
 #include "mconsole.h"
 #include "umid.h"
+#include "uml-config.h"
 
 static struct mconsole_command commands[] = {
 	{ "version", mconsole_version, MCONSOLE_INTR },
@@ -30,6 +31,9 @@ static struct mconsole_command commands[
 	{ "go", mconsole_go, MCONSOLE_INTR },
 	{ "log", mconsole_log, MCONSOLE_INTR },
 	{ "proc", mconsole_proc, MCONSOLE_PROC },
+#ifdef UML_CONFIG_MCONSOLE_EXEC
+	{ "exec", mconsole_exec, MCONSOLE_PROC },
+#endif
 };
 
 /* Initialized in mconsole_init, which is an initcall */
diff -puN arch/um/Kconfig~mconsole_exec arch/um/Kconfig
--- uml-linux-2.6.7/arch/um/Kconfig~mconsole_exec	2004-06-21 16:54:17.000000000 +0200
+++ uml-linux-2.6.7-paolo/arch/um/Kconfig	2004-06-21 16:56:00.000000000 +0200
@@ -129,6 +129,15 @@ config MCONSOLE
 
         It is safe to say 'Y' here.
 
+config MCONSOLE_EXEC
+	bool "Management console 'exec' support"
+	depends on MCONSOLE
+	help
+	Adds the 'exec' command to mconsole, which allows execution of arbitrary command
+	inside UML.
+	All its parameters are passed to /bin/sh -c inside UML, so you can use the full
+	shell syntax, especially redirections.
+
 config MAGIC_SYSRQ
 	bool "Magic SysRq key"
 	depends on MCONSOLE
diff -puN arch/um/include/mconsole.h~mconsole_exec arch/um/include/mconsole.h
--- uml-linux-2.6.7/arch/um/include/mconsole.h~mconsole_exec	2004-06-21 16:54:17.000000000 +0200
+++ uml-linux-2.6.7-paolo/arch/um/include/mconsole.h	2004-06-21 16:54:17.000000000 +0200
@@ -80,6 +80,7 @@ extern void mconsole_cad(struct mc_reque
 extern void mconsole_stop(struct mc_request *req);
 extern void mconsole_go(struct mc_request *req);
 extern void mconsole_log(struct mc_request *req);
+extern void mconsole_exec(struct mc_request *req);
 extern void mconsole_proc(struct mc_request *req);
 
 extern int mconsole_get_request(int fd, struct mc_request *req);

_

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [uml-devel] [PATCH] Mconsole exec support - rewritten completely
  2004-07-22 14:53 [uml-devel] [PATCH] Mconsole exec support - rewritten completely BlaisorBlade
@ 2004-07-26 18:16 ` Jeff Dike
  2004-07-27  3:13   ` Matt Zimmerman
  0 siblings, 1 reply; 3+ messages in thread
From: Jeff Dike @ 2004-07-26 18:16 UTC (permalink / raw)
  To: BlaisorBlade; +Cc: user-mode-linux-devel, user-mode-linux-user

blaisorblade_spam@yahoo.it said:
> Jeff, you can still think that  this feature should not be in the
> kernel support (but why then bother with  the "proc" command?), 

Because "proc" is needed to diagnose sick UMLs, which may not be able to run
commands.  It's also handy to make measurements which may be affected by logging
in.

> even
> if this time there is no more any parsing code;  but anyway, it will
> stay available for who wants it.

You can maintain this yourself if you want, but it's going nowhere near my
tree.  I've said why I don't like it, and haven't heard any real arguments
for it, just whining by people who think parsing login sequences and shell
prompts is hard.

				Jeff



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [uml-devel] [PATCH] Mconsole exec support - rewritten completely
  2004-07-26 18:16 ` Jeff Dike
@ 2004-07-27  3:13   ` Matt Zimmerman
  0 siblings, 0 replies; 3+ messages in thread
From: Matt Zimmerman @ 2004-07-27  3:13 UTC (permalink / raw)
  To: user-mode-linux-devel, user-mode-linux-user

On Mon, Jul 26, 2004 at 02:16:28PM -0400, Jeff Dike wrote:

> You can maintain this yourself if you want, but it's going nowhere near my
> tree.  I've said why I don't like it, and haven't heard any real arguments
> for it, just whining by people who think parsing login sequences and shell
> prompts is hard.

I wouldn't say "hard"..."nasty" seems more appropriate, or "not robust".
Then again, I don't like the mconsole approach, either.  So far, I've been
running a daemon inside UML which speaks a simple protocol over a UML
channel.  This works OK, but has the disadvantage of requiring specialized
software running under the UML guest.

-- 
 - mdz


-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=4721&alloc_id=10040&op=click
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2004-07-27  3:13 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-07-22 14:53 [uml-devel] [PATCH] Mconsole exec support - rewritten completely BlaisorBlade
2004-07-26 18:16 ` Jeff Dike
2004-07-27  3:13   ` Matt Zimmerman

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.