From: Igor Kotrasinski Date: Fri, 20 Jul 2018 12:30:26 +0000 (+0200) Subject: Gracefully shutdown debugproxy when sent SIGTERM X-Git-Tag: submit/tizen/20180828.110226~8 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e69e79a8e7d2421b57d910f462823059bbeb10f4;p=platform%2Fcore%2Fsecurity%2Ftef-simulator.git Gracefully shutdown debugproxy when sent SIGTERM Change-Id: Idfb58076028d9c78e2ac297927d99c2da75217b2 Signed-off-by: Igor Kotrasinski --- diff --git a/simulatordaemon/debugproxy/CMakeLists.txt b/simulatordaemon/debugproxy/CMakeLists.txt index 32c7503..b55eaaf 100644 --- a/simulatordaemon/debugproxy/CMakeLists.txt +++ b/simulatordaemon/debugproxy/CMakeLists.txt @@ -43,7 +43,7 @@ LINK_DIRECTORIES( ) TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DEBUGPROXY} - boost_system boost_signals boost_coroutine + boost_system boost_signals boost_coroutine pthread ${TARGET_TEF_SIMULATOR_LOG} ${DEBUGPROXY_DEPS_LIBRARIES} ) diff --git a/simulatordaemon/debugproxy/inc/DebugproxySocket.h b/simulatordaemon/debugproxy/inc/DebugproxySocket.h index f6eaff5..d07d4a4 100644 --- a/simulatordaemon/debugproxy/inc/DebugproxySocket.h +++ b/simulatordaemon/debugproxy/inc/DebugproxySocket.h @@ -13,11 +13,11 @@ class DebugproxySocket public: DebugproxySocket(boost::asio::io_service &io); void start_accept(); + void shutdown(); private: void async_accept(yield_ctx yield); void handle_connection(std::shared_ptr local_sock, yield_ctx yield); - boost::asio::io_service &io; local::stream_protocol::endpoint ep; local::stream_protocol::acceptor acceptor; diff --git a/simulatordaemon/debugproxy/src/DebugproxySocket.cpp b/simulatordaemon/debugproxy/src/DebugproxySocket.cpp index dcacf9a..fa586fb 100644 --- a/simulatordaemon/debugproxy/src/DebugproxySocket.cpp +++ b/simulatordaemon/debugproxy/src/DebugproxySocket.cpp @@ -55,3 +55,10 @@ void DebugproxySocket::handle_connection(const std::shared_ptr local LOGE(MODULE_DEBUGPROXY, "Forwarding session ended: %s", e.what()); } } + +void DebugproxySocket::shutdown() +{ + LOGD(MODULE_DEBUGPROXY, "Shutting down gracefully"); + this->acceptor.cancel(); + this->acceptor.close(); +} diff --git a/simulatordaemon/debugproxy/src/main.cpp b/simulatordaemon/debugproxy/src/main.cpp index c53ae19..8febefc 100644 --- a/simulatordaemon/debugproxy/src/main.cpp +++ b/simulatordaemon/debugproxy/src/main.cpp @@ -6,6 +6,13 @@ int main() boost::asio::io_service io; DebugproxySocket socket(io); socket.start_accept(); + + boost::asio::signal_set graceful_shutdown_sigs(io, SIGTERM); + graceful_shutdown_sigs.async_wait( + [&socket](const boost::system::error_code &e, int number) { + socket.shutdown(); + }); + io.run(); return 0; }