From 0174af21196c197a5b3672c87bc6f7a614fddd7d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Tue, 10 Dec 2019 03:01:52 +0000 Subject: CTAN sync 201912100301 --- dviware/dvisvgm/src/Process.cpp | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) (limited to 'dviware/dvisvgm/src/Process.cpp') diff --git a/dviware/dvisvgm/src/Process.cpp b/dviware/dvisvgm/src/Process.cpp index ff73cb5336..de5394f1fd 100644 --- a/dviware/dvisvgm/src/Process.cpp +++ b/dviware/dvisvgm/src/Process.cpp @@ -22,6 +22,7 @@ #include "windows.hpp" #else #include + #include #include #include #include @@ -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 ¶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 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(¶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(params.data())); exit(1); } _readfd = pipefd[0]; -- cgit v1.2.3