From: BlaisorBlade <blaisorblade_spam@yahoo.it>
To: user-mode-linux-devel@lists.sourceforge.net,
user-mode-linux-user@lists.sourceforge.net
Cc: Jeff Dike <jdike@addtoit.com>
Subject: [uml-devel] [PATCH] Mconsole exec support - rewritten completely
Date: Thu, 22 Jul 2004 16:53:38 +0200 [thread overview]
Message-ID: <200407221653.38293.blaisorblade_spam@yahoo.it> (raw)
[-- 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);
_
next reply other threads:[~2004-07-22 18:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-22 14:53 BlaisorBlade [this message]
2004-07-26 18:16 ` [uml-devel] [PATCH] Mconsole exec support - rewritten completely Jeff Dike
2004-07-27 3:13 ` Matt Zimmerman
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=200407221653.38293.blaisorblade_spam@yahoo.it \
--to=blaisorblade_spam@yahoo.it \
--cc=jdike@addtoit.com \
--cc=user-mode-linux-devel@lists.sourceforge.net \
--cc=user-mode-linux-user@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox