From 4ccf7da8d5b8aef9c04c2e0176ca934339e490fb Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Sun, 12 Sep 2004 17:41:34 +0000 Subject: [PATCH] Added provisional implementation of system(). Requires a shell to be available at /bin/sh (a symlink will do). Unfortunately there's some problem with our shell that causes it to crash in most cases. :-( git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8925 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/libroot/posix/unistd/Jamfile | 1 + src/kernel/libroot/posix/unistd/system.cpp | 37 ++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 src/kernel/libroot/posix/unistd/system.cpp diff --git a/src/kernel/libroot/posix/unistd/Jamfile b/src/kernel/libroot/posix/unistd/Jamfile index 29d213effb..636d126078 100644 --- a/src/kernel/libroot/posix/unistd/Jamfile +++ b/src/kernel/libroot/posix/unistd/Jamfile @@ -25,6 +25,7 @@ KernelMergeObject posix_unistd.o : sbrk.c sleep.c sync.c + system.cpp terminal.c truncate.c ttyname.c diff --git a/src/kernel/libroot/posix/unistd/system.cpp b/src/kernel/libroot/posix/unistd/system.cpp new file mode 100644 index 0000000000..0731013ec1 --- /dev/null +++ b/src/kernel/libroot/posix/unistd/system.cpp @@ -0,0 +1,37 @@ +/* +** Copyright 2004, Ingo Weinhold, bonefish@cs.tu-berlin.de. All rights reserved. +** Distributed under the terms of the Haiku License. +*/ + +#include +#include + +#include + +#include + +extern "C" +int +system(const char *command) +{ + if (!command) + return 1; + + const char *argv[] = { "/bin/sh", "-c", command, NULL }; + int argc = 3; + + team_id team = _kern_create_team(argv[0], argv[0], (char**)argv, argc, NULL, + 0, B_NORMAL_PRIORITY); + if (team < 0) { + errno = team; + return -1; + } + + status_t returnValue; + status_t error = _kern_wait_for_team(team, &returnValue); + if (error != B_OK) { + errno = error; + return -1; + } + return returnValue; +}