[tip:tools/kvm] kvm tools: Make 'vm sandbox' more user-friendly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Commit-ID:  708adc547162256f4df69b3971e3e494c205f776
Gitweb:     http://git.kernel.org/tip/708adc547162256f4df69b3971e3e494c205f776
Author:     Pekka Enberg <penberg@xxxxxxxxxx>
AuthorDate: Wed, 7 Mar 2012 20:49:54 +0200
Committer:  Pekka Enberg <penberg@xxxxxxxxxx>
CommitDate: Thu, 8 Mar 2012 08:25:13 +0200

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 <asias.hejun@xxxxxxxxx>
Cc: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
Cc: Ingo Molnar <mingo@xxxxxxx>
Cc: Sasha Levin <levinsasha928@xxxxxxxxx>
Signed-off-by: Pekka Enberg <penberg@xxxxxxxxxx>
---
 tools/kvm/builtin-run.c |   30 +++++++++++++++++++++++++++---
 1 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 6acc490..ff53e72 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -847,9 +847,27 @@ 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;
+
+	if (stat(src, &st) < 0)
+		die("Unable to resolve program %s: %s", src, strerror(errno));
+
+	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 +879,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--;
 	}
--
To unsubscribe from this list: send the line "unsubscribe linux-tip-commits" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Stable Commits]     [Linux Stable Kernel]     [Linux Kernel]     [Linux USB Devel]     [Linux Video &Media]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux