* [PATCH] kvm tools: Make 'vm sandbox' more user-friendly
@ 2012-03-07 18:53 Pekka Enberg
2012-03-07 21:50 ` Cyrill Gorcunov
0 siblings, 1 reply; 2+ messages in thread
From: Pekka Enberg @ 2012-03-07 18:53 UTC (permalink / raw)
To: kvm; +Cc: Pekka Enberg, Asias He, Cyrill Gorcunov, Ingo Molnar, Sasha Levin
This patch changes 'vm sandbox' to automatically prefix a program path with
"/host" in the guest side making this, for example, work as expected:
$ ./vm sandbox -- ~/trinity/trinity --mode=random --dangerous
Cc: Asias He <asias.hejun@gmail.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Sasha Levin <levinsasha928@gmail.com>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
---
tools/kvm/builtin-run.c | 29 ++++++++++++++++++++++++++---
1 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 6acc490..ce76b69 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -847,9 +847,26 @@ static void kvm_write_sandbox_cmd_exactly(int fd, const char *arg)
}
}
+static void resolve_program(const char *src, char *dst, size_t len)
+{
+ struct stat st;
+
+ stat(src, &st);
+
+ if (S_ISREG(st.st_mode)) {
+ char resolved_path[PATH_MAX];
+
+ realpath(src, resolved_path);
+
+ snprintf(dst, len, "/host%s", resolved_path);
+ } else
+ strncpy(dst, src, len);
+}
+
static void kvm_run_write_sandbox_cmd(const char **argv, int argc)
{
const char script_hdr[] = "#! /bin/bash\n\n";
+ char program[PATH_MAX];
int fd;
remove(sandbox);
@@ -861,11 +878,17 @@ static void kvm_run_write_sandbox_cmd(const char **argv, int argc)
if (write(fd, script_hdr, sizeof(script_hdr) - 1) <= 0)
die("Failed writing sandbox script");
+ resolve_program(argv[0], program, PATH_MAX);
+ kvm_write_sandbox_cmd_exactly(fd, program);
+
+ argv++;
+ argc--;
+
while (argc) {
+ if (write(fd, " ", 1) <= 0)
+ die("Failed writing sandbox script");
+
kvm_write_sandbox_cmd_exactly(fd, argv[0]);
- if (argc - 1)
- if (write(fd, " ", 1) <= 0)
- die("Failed writing sandbox script");
argv++;
argc--;
}
--
1.7.6.5
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] kvm tools: Make 'vm sandbox' more user-friendly
2012-03-07 18:53 [PATCH] kvm tools: Make 'vm sandbox' more user-friendly Pekka Enberg
@ 2012-03-07 21:50 ` Cyrill Gorcunov
0 siblings, 0 replies; 2+ messages in thread
From: Cyrill Gorcunov @ 2012-03-07 21:50 UTC (permalink / raw)
To: Pekka Enberg; +Cc: kvm, Asias He, Ingo Molnar, Sasha Levin
On Wed, Mar 07, 2012 at 08:53:59PM +0200, Pekka Enberg wrote:
> This patch changes 'vm sandbox' to automatically prefix a program path with
> "/host" in the guest side making this, for example, work as expected:
>
> $ ./vm sandbox -- ~/trinity/trinity --mode=random --dangerous
>
> Cc: Asias He <asias.hejun@gmail.com>
> Cc: Cyrill Gorcunov <gorcunov@openvz.org>
> Cc: Ingo Molnar <mingo@elte.hu>
> Cc: Sasha Levin <levinsasha928@gmail.com>
> Signed-off-by: Pekka Enberg <penberg@kernel.org>
> ---
> tools/kvm/builtin-run.c | 29 ++++++++++++++++++++++++++---
> 1 files changed, 26 insertions(+), 3 deletions(-)
>
> diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
> index 6acc490..ce76b69 100644
> --- a/tools/kvm/builtin-run.c
> +++ b/tools/kvm/builtin-run.c
> @@ -847,9 +847,26 @@ static void kvm_write_sandbox_cmd_exactly(int fd, const char *arg)
> }
> }
>
> +static void resolve_program(const char *src, char *dst, size_t len)
> +{
> + struct stat st;
> +
> + stat(src, &st);
Hi Pekka, looks cool! I suspect we might need to add
a check if stat call has not been failed, on top of this
patch course ;)
Cyrill
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-03-07 21:50 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-07 18:53 [PATCH] kvm tools: Make 'vm sandbox' more user-friendly Pekka Enberg
2012-03-07 21:50 ` Cyrill Gorcunov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox