From 9333bf301badb88e684b8bad8aefeccb30ca016c Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Fri, 15 Jul 2005 00:14:51 +0000 Subject: [PATCH] consoled now supports a program to be run instead of the shell being supplied via command line parameters. Not tested yet. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13677 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/tests/kernel/consoled/consoled.cpp | 47 +++++++++++++++++++------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/tests/kernel/consoled/consoled.cpp b/src/tests/kernel/consoled/consoled.cpp index 2e4304974f..7abf6b514b 100644 --- a/src/tests/kernel/consoled/consoled.cpp +++ b/src/tests/kernel/consoled/consoled.cpp @@ -7,15 +7,16 @@ */ -#include #include +#include -#include -#include +#include #include -#include #include #include +#include +#include +#include //#define USE_INPUT_SERVER @@ -291,7 +292,7 @@ start_process(int argc, const char **argv, struct console *con) int -main(void) +main(int argc, char **argv) { int err; @@ -309,18 +310,38 @@ main(void) dup2(gConsole.tty_slave_fd, 1); dup2(gConsole.tty_slave_fd, 2); - for (;;) { - pid_t shell_process; + if (argc > 1) { + // a command was given: we run it only once + + // get the command argument vector + int commandArgc = argc - 1; + const char **commandArgv = new const char*[commandArgc + 1]; + for (int i = 0; i < commandArgc; i++) + commandArgv[i] = argv[i + 1]; + + commandArgv[commandArgc] = NULL; + + // start the process + pid_t process; status_t returnCode; - const char *argv[3]; - argv[0] = "/bin/sh"; - argv[1] = "--login"; - shell_process = start_process(2, argv, &gConsole); + process = start_process(commandArgc, commandArgv, &gConsole); - wait_for_thread(shell_process, &returnCode); + wait_for_thread(process, &returnCode); - puts("Restart shell"); + } else { + // no command given: start a shell in an endless loop + for (;;) { + pid_t shellProcess; + status_t returnCode; + const char *shellArgv[] = { "/bin/sh", "--login", NULL }; + + shellProcess = start_process(2, shellArgv, &gConsole); + + wait_for_thread(shellProcess, &returnCode); + + puts("Restart shell"); + } } acquire_sem(gConsole.wait_sem);