aboutsummaryrefslogtreecommitdiff
path: root/toolsrc/src
diff options
context:
space:
mode:
authorAlexander Karatarakis <alkarata@microsoft.com>2017-08-23 16:47:54 -0700
committerAlexander Karatarakis <alkarata@microsoft.com>2017-08-24 16:29:41 -0700
commit88d96a3699118cf21f6ec92284eb591db25d3a6a (patch)
tree83d7eca28ed58fa7a032106274fcd34566e06209 /toolsrc/src
parente237682cad4eaa582a10b5ad03a59ca6449e0795 (diff)
downloadvcpkg-88d96a3699118cf21f6ec92284eb591db25d3a6a.tar.gz
vcpkg-88d96a3699118cf21f6ec92284eb591db25d3a6a.zip
Run cleanup before exiting instead of calling atexit
Diffstat (limited to 'toolsrc/src')
-rw-r--r--toolsrc/src/vcpkg.cpp7
-rw-r--r--toolsrc/src/vcpkg_Checks.cpp24
2 files changed, 23 insertions, 8 deletions
diff --git a/toolsrc/src/vcpkg.cpp b/toolsrc/src/vcpkg.cpp
index 3ccb33aad..7294d8692 100644
--- a/toolsrc/src/vcpkg.cpp
+++ b/toolsrc/src/vcpkg.cpp
@@ -191,12 +191,7 @@ int wmain(const int argc, const wchar_t* const* const argv)
GlobalState::timer = ElapsedTime::create_started();
- atexit([]() {
- auto elapsed_us = GlobalState::timer.microseconds();
- Metrics::track_metric("elapsed_us", elapsed_us);
- GlobalState::debugging = false;
- Metrics::flush();
- });
+ // Checks::register_console_ctrl_handler();
Metrics::track_property("version", Commands::Version::version());
diff --git a/toolsrc/src/vcpkg_Checks.cpp b/toolsrc/src/vcpkg_Checks.cpp
index 2674b889a..6ae595a54 100644
--- a/toolsrc/src/vcpkg_Checks.cpp
+++ b/toolsrc/src/vcpkg_Checks.cpp
@@ -1,11 +1,31 @@
#include "pch.h"
+#include "metrics.h"
#include "vcpkg_Checks.h"
+#include "vcpkg_GlobalState.h"
#include "vcpkg_System.h"
#include "vcpkglib.h"
namespace vcpkg::Checks
{
+ [[noreturn]] static void cleanup_and_exit(const int exit_code)
+ {
+ auto elapsed_us = GlobalState::timer.microseconds();
+ Metrics::track_metric("elapsed_us", elapsed_us);
+ GlobalState::debugging = false;
+ Metrics::flush();
+
+ ::exit(exit_code);
+ }
+
+ static BOOL CtrlHandler(DWORD fdwCtrlType)
+ {
+ Metrics::track_metric("SignalCaptured", fdwCtrlType);
+ cleanup_and_exit(EXIT_FAILURE);
+ }
+
+ void register_console_ctrl_handler() { SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE); }
+
[[noreturn]] void unreachable(const LineInfo& line_info)
{
System::println(System::Color::error, "Error: Unreachable code was reached");
@@ -13,14 +33,14 @@ namespace vcpkg::Checks
#ifndef NDEBUG
std::abort();
#else
- ::exit(EXIT_FAILURE);
+ cleanup_and_exit(EXIT_FAILURE);
#endif
}
[[noreturn]] void exit_with_code(const LineInfo& line_info, const int exit_code)
{
Debug::println(System::Color::error, line_info.to_string());
- ::exit(exit_code);
+ cleanup_and_exit(exit_code);
}
[[noreturn]] void exit_with_message(const LineInfo& line_info, const CStringView errorMessage)