Skip to contentSkip to conversation

sanbox: add linux_execve and linux_exec command

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 2 messages Dec 3, 2011

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 sanbox: add linux_execve and linux_exec command

this will allow to execute a program of the host from barebox

---
v2:

fix missing free

Best Regards,
J.

 arch/sandbox/mach-sandbox/include/mach/linux.h |    2 +
 arch/sandbox/os/common.c                       |   22 +++++++++
 commands/Kconfig                               |    4 ++
 commands/Makefile                              |    1 +
 commands/linux_exec.c                          |   60 ++++++++++++++++++++++++
 5 files changed, 89 insertions(+), 0 deletions(-)
 create mode 100644 commands/linux_exec.c
arch/sandbox/mach-sandbox/include/mach/linux.h +2 -0
index 7c2386d..5917fe9 100644
@@ -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 {
arch/sandbox/os/common.c +22 -0
index 1c5ae5d..34db022 100644
@@ -45,6 +45,7 @@
 #include <errno.h>
 #include <signal.h>
 #include <sys/select.h>
+#include <sys/wait.h>
 /*
  * ...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);
 
commands/Kconfig +4 -0
index c2492fa..978cc67 100644
@@ -107,6 +107,10 @@ 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
+
 endmenu
 
 menu "file commands                 "
commands/Makefile +1 -0
index f82dcfa..e4e94fb 100644
@@ -60,3 +60,4 @@ obj-$(CONFIG_CMD_USB)		+= usb.o
 obj-$(CONFIG_CMD_TIME)		+= time.o
 obj-$(CONFIG_CMD_OFTREE)	+= oftree.o
 obj-$(CONFIG_CMD_MAGICVAR)	+= magicvar.o
+obj-$(CONFIG_CMD_LINUX_EXEC)	+= linux_exec.o
commands/linux_exec.c new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
1.7.7
#1 lore raw

PATCH v2 1/1 sanbox: add linux_execve and linux_exec command

Le Sat, 3 Dec 2011 06:42:02 +0100,
Jean-Christophe PLAGNIOL-VILLARD <[email protected]> a ?crit :

Quoted 3 lines

this will allow to execute a program of the host from barebox

I guess your intention was to send this patch to the Barebox mailing list and not to the Linux ARM kernel mailing list, no?

Thomas

Signature · 4 lines
Thomas Petazzoni, Free Electrons
Kernel, drivers, real-time and embedded Linux
development, consulting, training and support.
http://free-electrons.com