From b191962d32a53c6f214f8ff40f2165c89c0dd648 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Mon, 23 May 2022 09:37:11 +0200 Subject: [PATCH] Handle startup errors without calling abort() --- src/main.cpp | 7 ++++++- src/p2pool.cpp | 16 ++++++++-------- src/params.cpp | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 25bb4ee..866663e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -85,10 +85,15 @@ int main(int argc, char* argv[]) memory_tracking_start(); p2pool::init_crypto_cache(); - { + + try { p2pool::p2pool pool(argc, argv); result = pool.run(); } + catch (...) { + result = 1; + } + p2pool::destroy_crypto_cache(); memory_tracking_stop(); diff --git a/src/p2pool.cpp b/src/p2pool.cpp index e1e03fa..c3cd102 100644 --- a/src/p2pool.cpp +++ b/src/p2pool.cpp @@ -61,13 +61,13 @@ p2pool::p2pool(int argc, char* argv[]) if (!m_params->m_wallet.valid()) { LOGERR(1, "Invalid wallet address. Try \"p2pool --help\"."); - panic(); + throw std::exception(); } bool is_v6; if (!resolve_host(m_params->m_host, is_v6)) { LOGERR(1, "resolve_host failed for " << m_params->m_host); - panic(); + throw std::exception(); } hash pub, sec, eph_public_key; @@ -76,7 +76,7 @@ p2pool::p2pool(int argc, char* argv[]) uint8_t view_tag; if (!m_params->m_wallet.get_eph_public_key(sec, 0, eph_public_key, view_tag)) { LOGERR(1, "Invalid wallet address: get_eph_public_key failed"); - panic(); + throw std::exception(); } const NetworkType type = m_params->m_wallet.type(); @@ -91,28 +91,28 @@ p2pool::p2pool(int argc, char* argv[]) int err = uv_async_init(uv_default_loop_checked(), &m_submitBlockAsync, on_submit_block); if (err) { LOGERR(1, "uv_async_init failed, error " << uv_err_name(err)); - panic(); + throw std::exception(); } m_submitBlockAsync.data = this; err = uv_async_init(uv_default_loop_checked(), &m_blockTemplateAsync, on_update_block_template); if (err) { LOGERR(1, "uv_async_init failed, error " << uv_err_name(err)); - panic(); + throw std::exception(); } m_blockTemplateAsync.data = this; err = uv_async_init(uv_default_loop_checked(), &m_stopAsync, on_stop); if (err) { LOGERR(1, "uv_async_init failed, error " << uv_err_name(err)); - panic(); + throw std::exception(); } m_stopAsync.data = this; err = uv_async_init(uv_default_loop_checked(), &m_restartZMQAsync, on_restart_zmq); if (err) { LOGERR(1, "uv_async_init failed, error " << uv_err_name(err)); - panic(); + throw std::exception(); } m_restartZMQAsync.data = this; @@ -128,7 +128,7 @@ p2pool::p2pool(int argc, char* argv[]) if (m_params->m_localStats && !m_api) { LOGERR(1, "--local-api and --stratum-api command line parameters can't be used without --data-api"); - panic(); + throw std::exception(); } m_sideChain = new SideChain(this, type, m_params->m_mini ? "mini" : nullptr); diff --git a/src/params.cpp b/src/params.cpp index 8ce4736..cd58d42 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -133,7 +133,7 @@ Params::Params(int argc, char* argv[]) if (!ok) { fprintf(stderr, "Unknown command line parameter %s\n\n", argv[i]); p2pool_usage(); - panic(); + throw std::exception(); } }