Do not add NULL at end of commandLine on Windows.

This commit is contained in:
Matthieu Gautier 2018-10-31 12:45:08 +01:00
parent 1787e30440
commit bb07ff5610
7 changed files with 10 additions and 10 deletions

View File

@ -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");

View File

@ -8,7 +8,7 @@
# include "subprocess_unix.h"
#endif
Subprocess::Subprocess(std::unique_ptr<SubprocessImpl> impl, const commandLine_t& commandLine) :
Subprocess::Subprocess(std::unique_ptr<SubprocessImpl> 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> Subprocess::run(const commandLine_t& commandLine)
std::unique_ptr<Subprocess> Subprocess::run(commandLine_t& commandLine)
{
#ifdef _WIN32
auto impl = std::unique_ptr<SubprocessImpl>(new WinImpl);

View File

@ -11,7 +11,7 @@ typedef std::vector<const char *> 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<SubprocessImpl> mp_impl;
Subprocess(std::unique_ptr<SubprocessImpl> impl, const commandLine_t& commandLine);
Subprocess(std::unique_ptr<SubprocessImpl> impl, commandLine_t& commandLine);
public:
static std::unique_ptr<Subprocess> run(const commandLine_t& commandLine);
static std::unique_ptr<Subprocess> run(commandLine_t& commandLine);
~Subprocess();
bool isRunning();

View File

@ -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<char* const*>(commandLine.data()))) {
perror("Cannot launch\n");
exit(-1);

View File

@ -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();

View File

@ -50,7 +50,7 @@ std::unique_ptr<wchar_t[]> toWideChar(const std::string& value)
}
void WinImpl::run(const commandLine_t& commandLine)
void WinImpl::run(commandLine_t& commandLine)
{
STARTUPINFOW startInfo = {0};
PROCESS_INFORMATION procInfo;

View File

@ -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();