aboutsummaryrefslogtreecommitdiff
path: root/src/Exec.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2017-12-11 18:19:11 +0100
committerdec05eba <dec05eba@protonmail.com>2017-12-11 18:22:00 +0100
commit43b37b2acc7e8876371741d4901cdc11ad7ecadd (patch)
tree36f657810e5ce24b94496d395fc72a634aeaed8a /src/Exec.cpp
parent87c378c20c30c9251c3787f6fd5496b72511f344 (diff)
Fix WEXITSTATUS compile error on openbsd (and ubuntu)
I noticed that WEXITSTATUS was failing when compiling sibs on ubuntu. WEXITSTATUS uses address of input which fails if the input is directly passed by return of a function call. Also added error checking if the process was stopped/killed by receiving a signal or if it failed in any other way.
Diffstat (limited to 'src/Exec.cpp')
-rw-r--r--src/Exec.cpp35
1 files changed, 31 insertions, 4 deletions
diff --git a/src/Exec.cpp b/src/Exec.cpp
index b245fd4..37ffef5 100644
--- a/src/Exec.cpp
+++ b/src/Exec.cpp
@@ -1,5 +1,7 @@
#include "../include/Exec.hpp"
+using namespace std;
+
namespace sibs
{
Result<ExecResult> exec(const char *cmd, bool print)
@@ -20,9 +22,34 @@ namespace sibs
}
}
- ExecResult execResult;
- execResult.execStdout = result;
- execResult.exitCode = WEXITSTATUS(pclose(pipe));
- return Result<ExecResult>::Ok(execResult);
+ int processCloseResult = pclose(pipe);
+ if(WIFEXITED(processCloseResult))
+ {
+ int returned = WEXITSTATUS(processCloseResult);
+ ExecResult execResult;
+ execResult.execStdout = result;
+ execResult.exitCode = returned;
+ return Result<ExecResult>::Ok(execResult);
+ }
+ else if(WIFSIGNALED(processCloseResult))
+ {
+ int signum = WSTOPSIG(processCloseResult);
+ string errMsg = "Exited due to receiving signal ";
+ errMsg += to_string(signum);
+ return Result<ExecResult>::Err(errMsg);
+ }
+ else if(WIFSTOPPED(processCloseResult))
+ {
+ int signum = WSTOPSIG(processCloseResult);
+ string errMsg = "Stopped due to receiving signal ";
+ errMsg += to_string(signum);
+ return Result<ExecResult>::Err(errMsg);
+ }
+ else
+ {
+ string errMsg = "exec unexpected error on pclose: ";
+ errMsg += to_string(processCloseResult);
+ return Result<ExecResult>::Err(errMsg);
+ }
}
} \ No newline at end of file