summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rvsh.c13
1 files changed, 13 insertions, 0 deletions
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 <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <unistd.h>
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);
}