From 7b1b49c2d1afeec3245d1d3ceefc7a63e9249d18 Mon Sep 17 00:00:00 2001 From: Ahurac Date: Fri, 8 Nov 2024 11:48:43 +0100 Subject: [PATCH] feat: return exit code --- src/command.c | 6 ++++-- src/main.c | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/command.c b/src/command.c index 7a55fed..dd7396b 100644 --- a/src/command.c +++ b/src/command.c @@ -6,12 +6,14 @@ #include unsigned char invoke(struct Args args) { + int status; + pid_t child = fork(); if (child == 0) { execvp(args.argv[0], args.argv); exit(errno); } - waitpid(child, NULL, 0); + wait(&status); - return 0; + return WEXITSTATUS(status); } diff --git a/src/main.c b/src/main.c index 5e073d1..e776132 100644 --- a/src/main.c +++ b/src/main.c @@ -7,19 +7,20 @@ int main() { char *input_line; + unsigned char exit_code = 0; while (1) { printf("$ "); input_line = read_a_line(stdin); if (input_line == NULL) { - return 0; + return exit_code; } struct Args args = parse(input_line); free(input_line); if (args.argc > 0) { - invoke(args); + exit_code = invoke(args); } {