From c14daba9e61c3f86e1cf210b2ff83f2c5ae5b630 Mon Sep 17 00:00:00 2001 From: Avi Kivity Date: Mon, 8 Sep 2014 21:21:00 +0300 Subject: [PATCH] core: exit program by breaking the loop rather than exit() This gives more destructors the option to run, making an easier job for leak detectors. --- core/reactor.cc | 5 ++++- core/reactor.hh | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/core/reactor.cc b/core/reactor.cc index e9b8abca55..2c11472e8d 100644 --- a/core/reactor.cc +++ b/core/reactor.cc @@ -44,7 +44,7 @@ reactor::reactor() _io_eventfd.wait().then([this] (size_t count) { process_io(count); }); - receive_signal(SIGINT).then([] { ::exit(255); }); + receive_signal(SIGINT).then([this] { _stopped = true; }); } future<> reactor::get_epoll_future(pollable_fd_state& pfd, @@ -266,6 +266,9 @@ void reactor::run() { current_tasks.clear(); } std::array eevt; + if (_stopped) { + break; + } int nr = ::epoll_wait(_epollfd.get(), eevt.data(), eevt.size(), -1); if (nr == -1 && errno == EINTR) { continue; // gdb can cause this diff --git a/core/reactor.hh b/core/reactor.hh index ea4a7dff38..677db57dd9 100644 --- a/core/reactor.hh +++ b/core/reactor.hh @@ -296,6 +296,7 @@ class reactor { signalfd_siginfo _siginfo; }; std::unordered_map _signal_handlers; + bool _stopped = false; public: file_desc _epollfd; readable_eventfd _io_eventfd;