diff options
Diffstat (limited to 'progs')
-rw-r--r-- | progs/shel/shel.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/progs/shel/shel.c b/progs/shel/shel.c index e3221f4..9eca8c5 100644 --- a/progs/shel/shel.c +++ b/progs/shel/shel.c @@ -5,6 +5,14 @@ #include <stdbool.h> #include <string.h> +#define P_ALL 0 +#define P_PID 1 +#define P_PGID 2 +#define P_PIDFD 3 +#if !WEXITED +#define WEXITED 0x00000004 +#endif + void parseInput(char *input, char *command, char **argv) { bool reachedArgv = false; char arg[32] = {0}; @@ -42,6 +50,9 @@ void parseInput(char *input, char *command, char **argv) { if (reachedArgv) { arg[idx] = '\0'; argv[argvIdx] = strdup(arg); + } else { + arg[idx] = '\0'; + strcpy(command, arg); } } @@ -52,7 +63,20 @@ int main() { char *env[32] = {"PATH=/bin"}; char path[128] = "/"; - strcpy(input, "/bin/echo meow"); - parseInput(input, command, argv); - execve(command, argv, 0); + while (!false) { + memset(input, 0, sizeof(input)); + memset(command, 0, sizeof(command)); + memset(argv, 0, sizeof(argv)); + write(1, path, strlen(path)); + write(1, " $ ", 3); + int len = read(1, input, sizeof(input)); + input[len - 1] = '\0'; + parseInput(input, command, argv); + __pid_t forkResult = fork(); + if (forkResult == 0) { + execve(command, argv, 0); + } else { + waitid(P_ALL, 0, 0, WEXITED); + } + } } \ No newline at end of file |