Loading src/urd.cpp +22 −6 Original line number Diff line number Diff line Loading @@ -586,19 +586,20 @@ urd::command_handler(const request_ptr base_request) { case command_type::ping: break; // nothing special to do here case command_type::pause_accept: if(!m_is_paused) { m_is_paused = true; } pause_accept(); break; case command_type::resume_accept: if(m_is_paused) { m_is_paused = false; } resume_accept(); break; case command_type::shutdown: { // TODO LOGGER_WARN("Shutdown requested!"); pause_accept(); break; } case command_type::unknown: resp->set_error_code(urd_error::bad_args); break; Loading Loading @@ -1027,6 +1028,21 @@ void urd::print_farewell() { LOGGER_INFO("{}", fsep); } void urd::pause_accept() { bool expected = false; while(!m_is_paused.compare_exchange_weak(expected, true) && !expected); LOGGER_WARN("Daemon locked: incoming requests will be rejected"); } void urd::resume_accept() { bool expected = true; while(!m_is_paused.compare_exchange_weak(expected, false) && expected); LOGGER_WARN("Daemon unlocked: incoming requests will be processed"); } int urd::run() { // initialize logging facilities Loading src/urd.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,9 @@ private: bool track, const bfs::path& mount, uint32_t quota); void pause_accept(); void resume_accept(); private: std::atomic<bool> m_is_paused; Loading tests/api-send-command.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,15 @@ SCENARIO("send control commands to urd", "[api::nornsctl_send_command]") { REQUIRE(task.t_id == 1); } } AND_WHEN("further NORNSCTL_COMMAND_PAUSE_ACCEPT commands are sent") { rv = nornsctl_send_command(NORNSCTL_COMMAND_PAUSE_ACCEPT, NULL); THEN("nornsctl_send_command() returns NORNS_SUCCESS") { REQUIRE(rv == NORNS_SUCCESS); } } } } Loading @@ -77,6 +86,14 @@ SCENARIO("send control commands to urd", "[api::nornsctl_send_command]") { THEN("nornsctl_send_command() returns NORNS_SUCCESS") { REQUIRE(rv == NORNS_SUCCESS); AND_WHEN("further NORNSCTL_COMMAND_RESUME_ACCEPT commands are sent") { rv = nornsctl_send_command(NORNSCTL_COMMAND_RESUME_ACCEPT, NULL); THEN("nornsctl_send_command() returns NORNS_SUCCESS") { REQUIRE(rv == NORNS_SUCCESS); } } } } Loading Loading
src/urd.cpp +22 −6 Original line number Diff line number Diff line Loading @@ -586,19 +586,20 @@ urd::command_handler(const request_ptr base_request) { case command_type::ping: break; // nothing special to do here case command_type::pause_accept: if(!m_is_paused) { m_is_paused = true; } pause_accept(); break; case command_type::resume_accept: if(m_is_paused) { m_is_paused = false; } resume_accept(); break; case command_type::shutdown: { // TODO LOGGER_WARN("Shutdown requested!"); pause_accept(); break; } case command_type::unknown: resp->set_error_code(urd_error::bad_args); break; Loading Loading @@ -1027,6 +1028,21 @@ void urd::print_farewell() { LOGGER_INFO("{}", fsep); } void urd::pause_accept() { bool expected = false; while(!m_is_paused.compare_exchange_weak(expected, true) && !expected); LOGGER_WARN("Daemon locked: incoming requests will be rejected"); } void urd::resume_accept() { bool expected = true; while(!m_is_paused.compare_exchange_weak(expected, false) && expected); LOGGER_WARN("Daemon unlocked: incoming requests will be processed"); } int urd::run() { // initialize logging facilities Loading
src/urd.hpp +3 −0 Original line number Diff line number Diff line Loading @@ -122,6 +122,9 @@ private: bool track, const bfs::path& mount, uint32_t quota); void pause_accept(); void resume_accept(); private: std::atomic<bool> m_is_paused; Loading
tests/api-send-command.cpp +17 −0 Original line number Diff line number Diff line Loading @@ -68,6 +68,15 @@ SCENARIO("send control commands to urd", "[api::nornsctl_send_command]") { REQUIRE(task.t_id == 1); } } AND_WHEN("further NORNSCTL_COMMAND_PAUSE_ACCEPT commands are sent") { rv = nornsctl_send_command(NORNSCTL_COMMAND_PAUSE_ACCEPT, NULL); THEN("nornsctl_send_command() returns NORNS_SUCCESS") { REQUIRE(rv == NORNS_SUCCESS); } } } } Loading @@ -77,6 +86,14 @@ SCENARIO("send control commands to urd", "[api::nornsctl_send_command]") { THEN("nornsctl_send_command() returns NORNS_SUCCESS") { REQUIRE(rv == NORNS_SUCCESS); AND_WHEN("further NORNSCTL_COMMAND_RESUME_ACCEPT commands are sent") { rv = nornsctl_send_command(NORNSCTL_COMMAND_RESUME_ACCEPT, NULL); THEN("nornsctl_send_command() returns NORNS_SUCCESS") { REQUIRE(rv == NORNS_SUCCESS); } } } } Loading