diff options
Diffstat (limited to 'Build/source/texk/dvisvgm/dvisvgm-src/src/Process.cpp')
-rw-r--r-- | Build/source/texk/dvisvgm/dvisvgm-src/src/Process.cpp | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/Build/source/texk/dvisvgm/dvisvgm-src/src/Process.cpp b/Build/source/texk/dvisvgm/dvisvgm-src/src/Process.cpp index ff73cb53366..de5394f1fd4 100644 --- a/Build/source/texk/dvisvgm/dvisvgm-src/src/Process.cpp +++ b/Build/source/texk/dvisvgm/dvisvgm-src/src/Process.cpp @@ -22,6 +22,7 @@ #include "windows.hpp" #else #include <csignal> + #include <cstring> #include <fcntl.h> #include <sys/wait.h> #include <unistd.h> @@ -42,7 +43,7 @@ class Subprocess { enum class State {RUNNING, FINISHED, FAILED}; public: - Subprocess (); + Subprocess () =default; Subprocess (const Subprocess&) =delete; Subprocess (Subprocess&&) =delete; ~Subprocess (); @@ -52,11 +53,11 @@ class Subprocess { private: #ifdef _WIN32 - HANDLE _pipeReadHandle; ///< handle of read end of pipe - HANDLE _childProcHandle; ///< handle of child process + HANDLE _pipeReadHandle=NULL; ///< handle of read end of pipe + HANDLE _childProcHandle=NULL; ///< handle of child process #else - int _readfd; ///< file descriptor of read end of pipe - pid_t _pid; ///< PID of the subprocess + int _readfd=-1; ///< file descriptor of read end of pipe + pid_t _pid=-1; ///< PID of the subprocess #endif }; @@ -113,10 +114,6 @@ static inline void close_and_zero_handle (HANDLE &handle) { } -Subprocess::Subprocess() : _pipeReadHandle(NULL), _childProcHandle(NULL) { -} - - Subprocess::~Subprocess () { if (_pipeReadHandle != NULL) CloseHandle(_pipeReadHandle); @@ -214,10 +211,6 @@ Subprocess::State Subprocess::state () { #else // !_WIN32 -Subprocess::Subprocess () : _readfd(-1), _pid(-1) { -} - - Subprocess::~Subprocess () { if (_readfd >= 0) close(_readfd); @@ -276,12 +269,12 @@ static void split_paramstr (string ¶mstr, vector<const char*> ¶ms) { /** Starts a child process. - * @param[in] cmd name of command to execute - * @param[in] paramstr parameters required by command + * @param[in] cmd name of command to execute or absolute path to executable + * @param[in] paramstr parameters required by the command * @returns true if child process started properly */ bool Subprocess::run (const string &cmd, string paramstr) { int pipefd[2]; - if (pipe(pipefd) < 0) + if (cmd.empty() || pipe(pipefd) < 0) return false; _pid = fork(); @@ -299,9 +292,11 @@ bool Subprocess::run (const string &cmd, string paramstr) { vector<const char*> params; params.push_back(cmd.c_str()); split_paramstr(paramstr, params); - params.push_back(nullptr); // trailing null pointer marks end of parameter list - signal(SIGINT, SIG_IGN); // child process is supposed to ignore ctrl-c events - execvp(cmd.c_str(), const_cast<char* const*>(¶ms[0])); + params.push_back(nullptr); // trailing null pointer marks end of parameter list + signal(SIGINT, SIG_IGN); // child process is supposed to ignore ctrl-c events + if (params[0][0] == '/') // absolute path to executable? + params[0] = strrchr(params[0], '/')+1; // filename of executable + execvp(cmd.c_str(), const_cast<char* const*>(params.data())); exit(1); } _readfd = pipefd[0]; |