mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
LibC+Shell: Make system() actually work.
system() will now fork off a child process and execute the command via /bin/sh -c. There are probably some things to fix here, but it's a start.
This commit is contained in:
parent
42cf09fdf1
commit
43604bf71a
2 changed files with 14 additions and 4 deletions
|
@ -206,7 +206,16 @@ void srandom(unsigned seed)
|
|||
|
||||
int system(const char* command)
|
||||
{
|
||||
return execl("/bin/sh", "sh", "-c", command, nullptr);
|
||||
auto child = fork();
|
||||
if (!child) {
|
||||
int rc = execl("/bin/sh", "sh", "-c", command, nullptr);
|
||||
if (rc < 0)
|
||||
perror("execl");
|
||||
exit(0);
|
||||
}
|
||||
int wstatus;
|
||||
waitpid(child, &wstatus, 0);
|
||||
return WEXITSTATUS(wstatus);
|
||||
}
|
||||
|
||||
char* mktemp(char* pattern)
|
||||
|
|
|
@ -413,9 +413,10 @@ int main(int argc, char** argv)
|
|||
endpwent();
|
||||
}
|
||||
|
||||
if (argc > 1 && !strcmp(argv[1], "-c")) {
|
||||
fprintf(stderr, "FIXME: Implement /bin/sh -c\n");
|
||||
return 1;
|
||||
if (argc > 2 && !strcmp(argv[1], "-c")) {
|
||||
dbgprintf("sh -c '%s'\n", argv[2]);
|
||||
run_command(argv[2]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue