X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fproc.cpp;h=c219c723effe3050b3e5c52221ce497a88f15610;hb=c0a5ece0f6bacea1b85157a908d710070fb0affd;hp=3137b0433a990e839a691a3d59f5d023e1c22cf7;hpb=fd86376a8e7d3f1b09be3d018f772ef884937238;p=blank.git diff --git a/src/app/proc.cpp b/src/app/proc.cpp index 3137b04..c219c72 100644 --- a/src/app/proc.cpp +++ b/src/app/proc.cpp @@ -1,5 +1,7 @@ #include "Process.hpp" +#include "error.hpp" + #ifdef _WIN32 # include # include @@ -22,8 +24,8 @@ struct Process::Impl { Impl( const string &path_in, - const vector &args, - const vector &env); + const Arguments &args, + const Environment &env); ~Impl(); size_t WriteIn(const void *buffer, size_t max_len); @@ -50,8 +52,8 @@ struct Process::Impl { Process::Process( const string &path, - const vector &args, - const vector &env) + const Arguments &args, + const Environment &env) : impl(new Impl(path, args, env)) , joined(false) , status(0) { @@ -94,8 +96,8 @@ int Process::Join() { Process::Impl::Impl( const string &path_in, - const vector &args, - const vector &env + const Arguments &args, + const Environment &env ) { const char *path = path_in.c_str(); char *envp[env.size() + 1]; @@ -166,18 +168,18 @@ Process::Impl::Impl( argv[args.size()] = nullptr; if (pipe(fd_in) != 0) { - throw runtime_error("failed to open pipe for child process' stdin"); + throw SysError("failed to open pipe for child process' stdin"); } if (pipe(fd_out) != 0) { - throw runtime_error("failed to open pipe for child process' stdout"); + throw SysError("failed to open pipe for child process' stdout"); } if (pipe(fd_err) != 0) { - throw runtime_error("failed to open pipe for child process' stderr"); + throw SysError("failed to open pipe for child process' stderr"); } pid = fork(); if (pid == -1) { - throw runtime_error("fork"); + throw SysError("fork"); } else if (pid == 0) { if (dup2(fd_in[0], STDIN_FILENO) == -1) { @@ -228,7 +230,7 @@ size_t Process::Impl::WriteIn(const void *buffer, size_t max_len) { if (errno == EAGAIN) { return 0; } else { - throw runtime_error("failed to write to child process' input stream"); + throw SysError("failed to write to child process' input stream"); } } return written; @@ -248,7 +250,7 @@ size_t Process::Impl::ReadOut(void *buffer, size_t max_len) { if (errno == EAGAIN) { return 0; } else { - throw runtime_error("failed to read from child process' output stream"); + throw SysError("failed to read from child process' output stream"); } } return ret; @@ -268,7 +270,7 @@ size_t Process::Impl::ReadErr(void *buffer, size_t max_len) { if (errno == EAGAIN) { return 0; } else { - throw runtime_error("failed to read from child process' error stream"); + throw SysError("failed to read from child process' error stream"); } } return ret; @@ -281,7 +283,7 @@ void Process::Impl::Terminate() { #else if (kill(pid, SIGTERM) == -1) { #endif - throw runtime_error("failed to terminate child process"); + throw SysError("failed to terminate child process"); } } @@ -307,7 +309,7 @@ int Process::Impl::Join() { int status; int result = waitpid(pid, &status, 0); if (result == -1) { - throw runtime_error("error waiting on child process"); + throw SysError("error waiting on child process"); } if (result == pid && WIFEXITED(status)) { return WEXITSTATUS(status);