X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fproc.cpp;h=dff8dee525fcb8957034e939b91f70fccd9618e8;hb=7bd3601fafbecae415bd96fc24404b21338cd7a4;hp=876eefc0527aaf110d215a3c0ec683c1cae6c966;hpb=0644360107ca50d681ae8b8cad608c7bc2ec7a40;p=blank.git diff --git a/src/app/proc.cpp b/src/app/proc.cpp index 876eefc..dff8dee 100644 --- a/src/app/proc.cpp +++ b/src/app/proc.cpp @@ -23,11 +23,16 @@ namespace blank { struct Process::Impl { Impl( - const string &path_in, + const string &path, const Arguments &args, - const Environment &env); + char *const env[]); ~Impl(); + static Impl *EnvHelper( + const string &path, + const Arguments &args, + const Environment &env); + size_t WriteIn(const void *buffer, size_t max_len); void CloseIn(); @@ -63,11 +68,18 @@ struct Process::Impl { }; +Process::Process( + const string &path, + const Arguments &args) +: impl(new Impl(path, args, nullptr)) { + +} + Process::Process( const string &path, const Arguments &args, const Environment &env) -: impl(new Impl(path, args, env)) { +: impl(Impl::EnvHelper(path, args, env)) { } @@ -112,22 +124,29 @@ int Process::Join() { return impl->Join(); } +Process::Impl *Process::Impl::EnvHelper( + const string &path, + const Arguments &args, + const Environment &env +) { + char *envp[env.size() + 1]; + for (size_t i = 0; i < env.size(); ++i) { + envp[i] = const_cast(env[i].c_str()); + } + envp[env.size()] = nullptr; + return new Impl(path, args, envp); +} Process::Impl::Impl( const string &path_in, const Arguments &args, - const Environment &env) + char *const envp[]) : joined(false) , status(0) , in_closed(false) , out_closed(false) , err_closed(false) { const char *path = path_in.c_str(); - char *envp[env.size() + 1]; - for (size_t i = 0; i < env.size(); ++i) { - envp[i] = const_cast(env[i].c_str()); - } - envp[env.size()] = nullptr; #ifdef _WIN32 string cmdline; for (const auto &arg : args) { @@ -222,7 +241,11 @@ Process::Impl::Impl( close(fd_err[0]); close(fd_err[1]); - execve(path, argv, envp); + if (envp) { + execve(path, argv, envp); + } else { + execv(path, argv); + } // if execve returns, something bad happened exit(EXIT_FAILURE);