Commit 0a888670 authored by Max Kellermann's avatar Max Kellermann

Main: move top-level exception handler to main()

Allows win32_main() to throw exceptions.
parent 0712314d
...@@ -644,27 +644,26 @@ MainOrThrow(int argc, char *argv[]) ...@@ -644,27 +644,26 @@ MainOrThrow(int argc, char *argv[])
MainConfigured(options, raw_config); MainConfigured(options, raw_config);
} }
int mpd_main(int argc, char *argv[]) noexcept int
mpd_main(int argc, char *argv[])
{ {
AtScopeExit() { log_deinit(); }; MainOrThrow(argc, argv);
return EXIT_SUCCESS;
try {
MainOrThrow(argc, argv);
return EXIT_SUCCESS;
} catch (...) {
LogError(std::current_exception());
return EXIT_FAILURE;
}
} }
int int
main(int argc, char *argv[]) noexcept main(int argc, char *argv[]) noexcept
{ try {
AtScopeExit() { log_deinit(); };
#ifdef _WIN32 #ifdef _WIN32
return win32_main(argc, argv); return win32_main(argc, argv);
#else #else
return mpd_main(argc, argv); return mpd_main(argc, argv);
#endif #endif
} catch (...) {
LogError(std::current_exception());
return EXIT_FAILURE;
} }
#endif #endif
...@@ -40,7 +40,7 @@ extern Instance *global_instance; ...@@ -40,7 +40,7 @@ extern Instance *global_instance;
* after doing some initialization. * after doing some initialization.
*/ */
int int
mpd_main(int argc, char *argv[]) noexcept; mpd_main(int argc, char *argv[]);
#endif #endif
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "util/Compiler.h" #include "util/Compiler.h"
#include "Instance.hxx" #include "Instance.hxx"
#include "system/FatalError.hxx" #include "system/FatalError.hxx"
#include "Log.hxx"
#include <cstdlib> #include <cstdlib>
#include <atomic> #include <atomic>
...@@ -76,7 +77,7 @@ service_dispatcher([[maybe_unused]] DWORD control, [[maybe_unused]] DWORD event_ ...@@ -76,7 +77,7 @@ service_dispatcher([[maybe_unused]] DWORD control, [[maybe_unused]] DWORD event_
static void WINAPI static void WINAPI
service_main([[maybe_unused]] DWORD argc, [[maybe_unused]] LPTSTR argv[]) service_main([[maybe_unused]] DWORD argc, [[maybe_unused]] LPTSTR argv[])
{ try {
service_handle = service_handle =
RegisterServiceCtrlHandlerEx(service_name, RegisterServiceCtrlHandlerEx(service_name,
service_dispatcher, nullptr); service_dispatcher, nullptr);
...@@ -87,6 +88,8 @@ service_main([[maybe_unused]] DWORD argc, [[maybe_unused]] LPTSTR argv[]) ...@@ -87,6 +88,8 @@ service_main([[maybe_unused]] DWORD argc, [[maybe_unused]] LPTSTR argv[])
service_notify_status(SERVICE_START_PENDING); service_notify_status(SERVICE_START_PENDING);
mpd_main(service_argc, service_argv); mpd_main(service_argc, service_argv);
service_notify_status(SERVICE_STOPPED); service_notify_status(SERVICE_STOPPED);
} catch (...) {
LogError(std::current_exception());
} }
static BOOL WINAPI static BOOL WINAPI
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment