From 68dc4d40b5ce17b1b7d387cbe41bbbaec844a733 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 29 Oct 2018 12:20:00 +0100 Subject: [PATCH 1/6] Include windows.h before synchapi.h --- src/subprocess_windows.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/subprocess_windows.h b/src/subprocess_windows.h index 42aaa41f5..40b5a0904 100644 --- a/src/subprocess_windows.h +++ b/src/subprocess_windows.h @@ -3,6 +3,7 @@ #include "subprocess.h" +#include #include class WinImpl : public SubprocessImpl From 29e554b47b3c94e804ba841d8fa4bc7bfcea28a0 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Mon, 29 Oct 2018 14:30:35 +0100 Subject: [PATCH 2/6] Include pthread --- src/aria2.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/aria2.h b/src/aria2.h index 2c30174f6..16b753ccf 100644 --- a/src/aria2.h +++ b/src/aria2.h @@ -13,6 +13,7 @@ #include #include +#include namespace kiwix { From 5ed095531e5bc8b26b718e1d96deb1dfdd59d037 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 30 Oct 2018 12:59:30 +0100 Subject: [PATCH 3/6] Correctly set pkgconfig file for static curl linking. --- meson.build | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 62c0bb26c..83f0b5d1f 100644 --- a/meson.build +++ b/meson.build @@ -19,8 +19,10 @@ libzim_dep = dependency('libzim', version : '>=4.0.0', static:static_deps) pugixml_dep = dependency('pugixml', static:static_deps) libcurl_dep = dependency('libcurl', static:static_deps) +extra_cflags = '' if target_machine.system() == 'windows' and static_deps add_project_arguments('-DCURL_STATICLIB', language : 'cpp') + extra_cflags += '-DCURL_STATICLIB' endif @@ -112,11 +114,10 @@ if xapian_dep.found() pkg_requires += ['xapian-core'] endif -extra_cflags = '' if has_ctpp2_dep extra_libs += ctpp2_link_args if ctpp2_include_path != '' - extra_cflags = '-I'+ctpp2_include_path + extra_cflags = ' -I'+ctpp2_include_path endif endif From ccb3d8639d2955015989fabe8b82ec28fa236756 Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Tue, 30 Oct 2018 18:42:54 +0100 Subject: [PATCH 4/6] Use correct name for aria2c on windows. --- src/aria2.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/aria2.cpp b/src/aria2.cpp index d4dbc7913..544057006 100644 --- a/src/aria2.cpp +++ b/src/aria2.cpp @@ -36,7 +36,11 @@ Aria2::Aria2(): std::string rpc_secret = "--rpc-secret=" + m_secret; m_secret = "token:"+m_secret; +#ifdef _WIN32 + callCmd.push_back("aria2c.exe"); +#else callCmd.push_back("aria2c"); +#endif callCmd.push_back("--enable-rpc"); callCmd.push_back(rpc_secret.c_str()); callCmd.push_back(rpc_port.c_str()); From 1787e304404827292416a8a57cd3e3d5c18c2b3f Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 31 Oct 2018 11:12:44 +0100 Subject: [PATCH 5/6] Better launch of the aria2 process. By setting the ApplicationName to NULL, CreateProcessW will search for the application in the path. --- src/subprocess_windows.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/subprocess_windows.cpp b/src/subprocess_windows.cpp index 226bd5d15..54c36824d 100644 --- a/src/subprocess_windows.cpp +++ b/src/subprocess_windows.cpp @@ -55,15 +55,14 @@ void WinImpl::run(const commandLine_t& commandLine) STARTUPINFOW startInfo = {0}; PROCESS_INFORMATION procInfo; startInfo.cb = sizeof(startInfo); - const char* binary = commandLine[0]; - std::cerr << "running " << binary << std::endl; std::ostringstream oss; for(auto& item: commandLine) { oss << item << " "; } + auto wCommandLine = toWideChar(oss.str()); if (CreateProcessW( - toWideChar(binary).get(), - toWideChar(oss.str()).get(), + NULL, + wCommandLine.get(), NULL, NULL, false, From bb07ff5610c9e898bb6b7a6bb151ceb919ffaefc Mon Sep 17 00:00:00 2001 From: Matthieu Gautier Date: Wed, 31 Oct 2018 12:45:08 +0100 Subject: [PATCH 6/6] Do not add NULL at end of commandLine on Windows. --- src/aria2.cpp | 1 - src/subprocess.cpp | 4 ++-- src/subprocess.h | 6 +++--- src/subprocess_unix.cpp | 3 ++- src/subprocess_unix.h | 2 +- src/subprocess_windows.cpp | 2 +- src/subprocess_windows.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) 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();