diff --git a/src/aria2.cpp b/src/aria2.cpp index 544057006..0195cccd0 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -61,7 +61,6 @@ Aria2::Aria2(): callCmd.push_back("--max-concurrent-downloads=42"); callCmd.push_back("--rpc-max-request-size=6M"); callCmd.push_back("--file-allocation=none"); - callCmd.push_back(NULL); mp_aria = Subprocess::run(callCmd); mp_curl = curl_easy_init(); curl_easy_setopt(mp_curl, CURLOPT_URL, "http://localhost/rpc"); diff --git a/src/subprocess.cpp b/src/subprocess.cpp index 6c958c489..b69cbc78e 100644 --- a/src/subprocess.cpp +++ b/src/subprocess.cpp @@ -8,7 +8,7 @@ # include "subprocess_unix.h" #endif -Subprocess::Subprocess(std::unique_ptr impl, const commandLine_t& commandLine) : +Subprocess::Subprocess(std::unique_ptr impl, commandLine_t& commandLine) : mp_impl(std::move(impl)) { mp_impl->run(commandLine); @@ -19,7 +19,7 @@ Subprocess::~Subprocess() mp_impl->kill(); } -std::unique_ptr Subprocess::run(const commandLine_t& commandLine) +std::unique_ptr Subprocess::run(commandLine_t& commandLine) { #ifdef _WIN32 auto impl = std::unique_ptr(new WinImpl); diff --git a/src/subprocess.h b/src/subprocess.h index 9ed75eb21..2fa7dccad 100644 --- a/src/subprocess.h +++ b/src/subprocess.h @@ -11,7 +11,7 @@ typedef std::vector commandLine_t; class SubprocessImpl { public: - virtual void run(const commandLine_t& commandLine) = 0; + virtual void run(commandLine_t& commandLine) = 0; virtual bool kill() = 0; virtual bool isRunning() = 0; virtual ~SubprocessImpl() = default; @@ -22,10 +22,10 @@ class Subprocess private: // Impl depends of the system (window, unix, ...) std::unique_ptr mp_impl; - Subprocess(std::unique_ptr impl, const commandLine_t& commandLine); + Subprocess(std::unique_ptr impl, commandLine_t& commandLine); public: - static std::unique_ptr run(const commandLine_t& commandLine); + static std::unique_ptr run(commandLine_t& commandLine); ~Subprocess(); bool isRunning(); diff --git a/src/subprocess_unix.cpp b/src/subprocess_unix.cpp index 08586f952..01921fde1 100644 --- a/src/subprocess_unix.cpp +++ b/src/subprocess_unix.cpp @@ -55,7 +55,7 @@ void* UnixImpl::waitForPID(void* _self) return self; } -void UnixImpl::run(const commandLine_t& commandLine) +void UnixImpl::run(commandLine_t& commandLine) { const char* binary = commandLine[0]; int pid = fork(); @@ -64,6 +64,7 @@ void UnixImpl::run(const commandLine_t& commandLine) std::cerr << "cannot fork" << std::endl; break; case 0: + commandLine.push_back(NULL); if (execvp(binary, const_cast(commandLine.data()))) { perror("Cannot launch\n"); exit(-1); diff --git a/src/subprocess_unix.h b/src/subprocess_unix.h index 750658943..22a03b525 100644 --- a/src/subprocess_unix.h +++ b/src/subprocess_unix.h @@ -18,7 +18,7 @@ class UnixImpl : public SubprocessImpl UnixImpl(); virtual ~UnixImpl(); - void run(const commandLine_t& commandLine); + void run(commandLine_t& commandLine); bool kill(); bool isRunning(); diff --git a/src/subprocess_windows.cpp b/src/subprocess_windows.cpp index 54c36824d..c49d4d841 100644 --- a/src/subprocess_windows.cpp +++ b/src/subprocess_windows.cpp @@ -50,7 +50,7 @@ std::unique_ptr toWideChar(const std::string& value) } -void WinImpl::run(const commandLine_t& commandLine) +void WinImpl::run(commandLine_t& commandLine) { STARTUPINFOW startInfo = {0}; PROCESS_INFORMATION procInfo; diff --git a/src/subprocess_windows.h b/src/subprocess_windows.h index 40b5a0904..36e1b0127 100644 --- a/src/subprocess_windows.h +++ b/src/subprocess_windows.h @@ -18,7 +18,7 @@ class WinImpl : public SubprocessImpl WinImpl(); virtual ~WinImpl(); - void run(const commandLine_t& commandLine); + void run(commandLine_t& commandLine); bool kill(); bool isRunning();