diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Exec.cpp | 35 | ||||
-rw-r--r-- | src/main.cpp | 5 |
2 files changed, 36 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 diff --git a/src/main.cpp b/src/main.cpp index 151e5a5..b1982bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,11 @@ using namespace std; using namespace sibs; +// TODO: Fail if multiple versions of the same dependency is used +// as linking will fail because of multiple definitions of the same thing + +// TODO: Detect recursive dependencies and give error. + void usage() { printf("usage: sibs COMMAND\n\n"); |