From 3d8b5fd7f58a1f76fc887adc8ea18d61ca569c45 Mon Sep 17 00:00:00 2001 From: Spencer Hall Date: Tue, 22 Mar 2022 10:01:44 -0400 Subject: capturing pid exit status Signed-off-by: Spencer Hall --- rvsh.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/rvsh.c b/rvsh.c index 211f3a0..4b57687 100644 --- a/rvsh.c +++ b/rvsh.c @@ -1,6 +1,7 @@ /* This file is a part of rvsh * * Copyright (C) 2021 Robby Zambito + * Copyright (C) 2022 Spencer Hall * * rvsh is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -27,6 +28,7 @@ #include #include #include +#include #include union pipe { @@ -62,6 +64,7 @@ char *get_bash_prompt() { union pipe bash_input, bash_output; FILE *bash_output_f; ssize_t len; + int status; static char *prompt = NULL; static size_t prompt_capacity = 0; @@ -97,6 +100,11 @@ char *get_bash_prompt() { } fclose(bash_output_f); + + do { + waitpid(bash_pid, &status, WUNTRACED); + } while(!WIFEXITED(status) && !WIFSIGNALED(status)); + return prompt; } @@ -129,6 +137,7 @@ void run_reverse_command(char *command) { FILE *bash_input_f, *bash_output_f; char *line; size_t line_capacity; + int status; pipe(bash_input.filedes); pipe(bash_output.filedes); @@ -164,6 +173,10 @@ void run_reverse_command(char *command) { free(line); + do { + waitpid(bash_pid, &status, WUNTRACED); + } while(!WIFEXITED(status) && !WIFSIGNALED(status)); + fclose(bash_input_f); fclose(bash_output_f); } -- cgit v1.2.3