summaryrefslogtreecommitdiff
path: root/dviware/dvisvgm/src/Process.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dviware/dvisvgm/src/Process.cpp')
-rw-r--r--dviware/dvisvgm/src/Process.cpp33
1 files changed, 14 insertions, 19 deletions
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 <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 &paramstr, vector<const char*> &params) {
/** 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*>(&params[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];