kvm tools: Make 'vm sandbox' more user-friendly
PATCH 1/1 kvm tools: Make 'vm sandbox' more user-friendly
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 <[email protected]>
Cc Cyrill Gorcunov <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Sasha Levin <[email protected]>
Signed-off-by Pekka Enberg <[email protected]>
--- tools/kvm/builtin-run.c | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-)
tools/kvm/builtin-run.c +26 -3
@@ -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--; }
Signature · 1 line
1.7.6.5
Quoted 19 lines · Pekka Enberg
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 --dangerousCc Asias He <[email protected]>Cc Cyrill Gorcunov <[email protected]>Cc Ingo Molnar <[email protected]>Cc Sasha Levin <[email protected]>Signed-off-by Pekka Enberg <[email protected]>--- tools/kvm/builtin-run.c | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-)tools/kvm/builtin-run.c +0
-0
tools/kvm/builtin-run.c static void kvm_write_sandbox_cmd_exactly(int fd, const char *arg) · line 854
Quoted 8 lines
tools/kvm/builtin-run.c +5
-0@@ -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