summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSpencer Hall <spencer@pinfosec.dev>2022-03-22 10:01:44 -0400
committerRobby Zambito <contact@robbyzambito.me>2022-03-23 00:15:04 -0400
commit3d8b5fd7f58a1f76fc887adc8ea18d61ca569c45 (patch)
tree70e674383a907b9d3b0e9f49798cee94ee51dfcb
parent98181b833eb4dc6440b73205e64ac010cc4b364c (diff)
capturing pid exit statusHEADmaster
Signed-off-by: Spencer Hall <spencer@pinfosec.dev>
-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);
}