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
This commit is contained in:
@@ -25,6 +25,7 @@ KernelMergeObject posix_unistd.o :
|
||||
sbrk.c
|
||||
sleep.c
|
||||
sync.c
|
||||
system.cpp
|
||||
terminal.c
|
||||
truncate.c
|
||||
ttyname.c
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
** Copyright 2004, Ingo Weinhold, [email protected]. All rights reserved.
|
||||
** Distributed under the terms of the Haiku License.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <OS.h>
|
||||
|
||||
#include <syscalls.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user