From 85b102a2a014a51d6c0c2d587defcd8366ca1595 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 31 Oct 2017 23:04:37 +0900 Subject: [PATCH] Fix bug that signal handler does not work with libaria2 This commit fixes the bug that signal handler does not work with libaria2 when aria2::RUN_ONCE is passed to aria2::run(). --- src/DownloadEngine.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/DownloadEngine.cc b/src/DownloadEngine.cc index 111009bd..a79702d0 100644 --- a/src/DownloadEngine.cc +++ b/src/DownloadEngine.cc @@ -150,14 +150,22 @@ void executeCommand(std::deque>& commands, namespace { class GlobalHaltRequestedFinalizer { public: - GlobalHaltRequestedFinalizer() = default; - ~GlobalHaltRequestedFinalizer() { global::globalHaltRequested = 5; } + GlobalHaltRequestedFinalizer(bool oneshot) : oneshot_(oneshot) {} + ~GlobalHaltRequestedFinalizer() + { + if (!oneshot_) { + global::globalHaltRequested = 5; + } + } + +private: + bool oneshot_; }; } // namespace int DownloadEngine::run(bool oneshot) { - GlobalHaltRequestedFinalizer ghrf; + GlobalHaltRequestedFinalizer ghrf(oneshot); while (!commands_.empty() || !routineCommands_.empty()) { if (!commands_.empty()) { waitData();