feat: return exit code

This commit is contained in:
Ahurac 2024-11-08 11:48:43 +01:00
parent 16743edb4f
commit 7b1b49c2d1
2 changed files with 7 additions and 4 deletions

View file

@ -6,12 +6,14 @@
#include <unistd.h>
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);
}

View file

@ -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);
}
{