From 1e06aef681a078dbc51ec36a602c9be9735b8ab9 Mon Sep 17 00:00:00 2001 From: Jean-Christophe PLAGNIOL-VILLARD Date: Sat, 3 Dec 2011 06:47:50 +0100 Subject: sanbox: add linux_execve and linux_exec command this will allow to execute a program of the host from barebox Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD Signed-off-by: Sascha Hauer --- arch/sandbox/mach-sandbox/include/mach/linux.h | 2 ++ arch/sandbox/os/common.c | 22 ++++++++++++++++++++++ commands/Kconfig | 6 ++++++ commands/Makefile | 1 + 4 files changed, 31 insertions(+) diff --git a/arch/sandbox/mach-sandbox/include/mach/linux.h b/arch/sandbox/mach-sandbox/include/mach/linux.h index 7c2386d247..5917fe93de 100644 --- a/arch/sandbox/mach-sandbox/include/mach/linux.h +++ b/arch/sandbox/mach-sandbox/include/mach/linux.h @@ -10,6 +10,8 @@ ssize_t linux_write(int fd, const void *buf, size_t count); off_t linux_lseek(int fildes, off_t offset); int linux_tstc(int fd); +int linux_execve(const char * filename, char *const argv[], char *const envp[]); + int barebox_register_console(char *name_template, int stdinfd, int stdoutfd); struct linux_console_data { diff --git a/arch/sandbox/os/common.c b/arch/sandbox/os/common.c index 9258c66156..92b7dbb2c7 100644 --- a/arch/sandbox/os/common.c +++ b/arch/sandbox/os/common.c @@ -45,6 +45,7 @@ #include #include #include +#include /* * ...except the ones needed to connect with barebox */ @@ -185,6 +186,27 @@ off_t linux_lseek(int fd, off_t offset) return lseek(fd, offset, SEEK_SET); } +int linux_execve(const char * filename, char *const argv[], char *const envp[]) +{ + pid_t pid, tpid; + int execve_status; + + pid = fork(); + + if (pid == -1) { + perror("linux_execve"); + return pid; + } else if (pid == 0) { + exit(execve(filename, argv, envp)); + } else { + do { + tpid = wait(&execve_status); + } while(tpid != pid); + + return execve_status; + } +} + extern void start_barebox(void); extern void mem_malloc_init(void *start, void *end); diff --git a/commands/Kconfig b/commands/Kconfig index 2badea3b7b..ebc9c7f2d0 100644 --- a/commands/Kconfig +++ b/commands/Kconfig @@ -107,6 +107,12 @@ config CMD_TIME checking for ctrl-c, so the time command can be used with commands which are interruptible with ctrl-c. +config CMD_LINUX_EXEC + bool "linux exec" + depends on LINUX + help + This command executes a command on the Linux host. + endmenu menu "file commands " diff --git a/commands/Makefile b/commands/Makefile index e95fdc375d..aa013de107 100644 --- a/commands/Makefile +++ b/commands/Makefile @@ -61,3 +61,4 @@ obj-$(CONFIG_CMD_TIME) += time.o obj-$(CONFIG_CMD_OFTREE) += oftree.o obj-$(CONFIG_CMD_MAGICVAR) += magicvar.o obj-$(CONFIG_CMD_IOMEM) += iomem.o +obj-$(CONFIG_CMD_LINUX_EXEC) += linux_exec.o -- cgit v1.2.3