1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-01 07:38:10 +00:00

Implement argc/argv support for spawned tasks.

Celebrate the new functionality with a simple /bin/cat implementation. :^)
This commit is contained in:
Andreas Kling 2018-10-26 11:16:56 +02:00
parent 53abfa7ea1
commit df87dda63c
13 changed files with 105 additions and 17 deletions

View file

@ -16,10 +16,21 @@ static int runcmd(char* cmd)
{
if (cmd[0] == 0)
return 0;
//printf("command: '%s'\n", cmd);
char buf[128];
sprintf(buf, "/bin/%s", cmd);
int ret = spawn(buf);
const char* argv[32];
size_t argi = 1;
argv[0] = &buf[0];
size_t buflen = strlen(buf);
for (size_t i = 0; i < buflen; ++i) {
if (buf[i] == ' ') {
buf[i] = '\0';
argv[argi++] = &buf[i + 1];
}
}
argv[argi + 1] = nullptr;
int ret = spawn(argv[0], argv);
if (ret == -1) {
printf("spawn failed: %s (%s)\n", cmd, strerror(errno));
return 1;