SKALE-4005 add unique exit codes

parent 75ee6f0d
...@@ -120,7 +120,7 @@ int CSRManagerServer::initCSRManagerServer() { ...@@ -120,7 +120,7 @@ int CSRManagerServer::initCSRManagerServer() {
if (!cs->StartListening()) { if (!cs->StartListening()) {
spdlog::info("CSR manager server could not start listening"); spdlog::info("CSR manager server could not start listening");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-1); exit(-1);
} else { } else {
spdlog::info("CSR manager server started on port {}", BASE_PORT + 2); spdlog::info("CSR manager server started on port {}", BASE_PORT + 2);
......
...@@ -11,11 +11,13 @@ public: ...@@ -11,11 +11,13 @@ public:
ec_success = 0, ec_success = 0,
ec_failure = 1, // same as EXIT_FAILURE in stdlib.h, generic failure in main() ec_failure = 1, // same as EXIT_FAILURE in stdlib.h, generic failure in main()
ec_termninated_by_signal = 196, ec_termninated_by_signal = 196,
ec_compute_snapshot_error = 197, // snapshot computation error ec_error_starting_server = 197, // error starting one of the http(s) servers
ec_rotation_complete = 0, // must be zero, exit requested after rotation complete ec_rotation_complete = 0, // must be zero, exit requested after rotation complete
ec_consensus_terminate_request = 198, // exit requested by consensus ec_error_creating_database = 198, // error initing LevelDB
ec_web3_request = 199, // programmatic shutdown via Web3 call, when enabled ec_error_initing_sek = 199, // error while initing or validating SEK
ec_state_root_mismatch = 200, // current state root is not equal to arrived from consensus ec_creating_certificate = 200, // error creating SSL certificate to initialize server
ec_initing_enclave = 201, // error starting secure enclave
ec_initing_user_space = 202, // error or exception while initializing user space
}; };
private: private:
......
...@@ -276,7 +276,7 @@ void LevelDB::initDataFolderAndDBs() { ...@@ -276,7 +276,7 @@ void LevelDB::initDataFolderAndDBs() {
if (getcwd(cwd, sizeof(cwd)) == NULL) { if (getcwd(cwd, sizeof(cwd)) == NULL) {
spdlog::error("could not get current workin directory"); spdlog::error("could not get current workin directory");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_creating_database);
exit(-2); exit(-2);
} }
...@@ -291,7 +291,7 @@ void LevelDB::initDataFolderAndDBs() { ...@@ -291,7 +291,7 @@ void LevelDB::initDataFolderAndDBs() {
} }
else{ else{
spdlog::error("Couldnt create creating sgx_data folder"); spdlog::error("Couldnt create creating sgx_data folder");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_creating_database);
exit(-3); exit(-3);
} }
} }
......
...@@ -91,7 +91,7 @@ void validate_SEK() { ...@@ -91,7 +91,7 @@ void validate_SEK() {
if (!hex2carray(test_key_ptr->c_str(), &len, encr_test_key.data(), if (!hex2carray(test_key_ptr->c_str(), &len, encr_test_key.data(),
BUF_LEN)) { BUF_LEN)) {
spdlog::error("Corrupt test key is LevelDB"); spdlog::error("Corrupt test key is LevelDB");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-4); exit(-4);
} }
...@@ -110,7 +110,7 @@ void validate_SEK() { ...@@ -110,7 +110,7 @@ void validate_SEK() {
spdlog::error("Invalid storage key. You need to recover using backup key"); spdlog::error("Invalid storage key. You need to recover using backup key");
spdlog::error("Set the correct backup key into sgx_datasgxwallet_backup_key.txt"); spdlog::error("Set the correct backup key into sgx_datasgxwallet_backup_key.txt");
spdlog::error("Then run sgxwallet using backup flag"); spdlog::error("Then run sgxwallet using backup flag");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-5); exit(-5);
} }
} }
...@@ -259,14 +259,14 @@ void enter_SEK() { ...@@ -259,14 +259,14 @@ void enter_SEK() {
shared_ptr <string> test_key_ptr = LevelDB::getLevelDb()->readString("TEST_KEY"); shared_ptr <string> test_key_ptr = LevelDB::getLevelDb()->readString("TEST_KEY");
if (test_key_ptr == nullptr) { if (test_key_ptr == nullptr) {
spdlog::error("Error: corrupt or empty LevelDB database"); spdlog::error("Error: corrupt or empty LevelDB database");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-7); exit(-7);
} }
if (!experimental::filesystem::is_regular_file(BACKUP_PATH)) { if (!experimental::filesystem::is_regular_file(BACKUP_PATH)) {
spdlog::error("File does not exist: " BACKUP_PATH); spdlog::error("File does not exist: " BACKUP_PATH);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-8); exit(-8);
} }
...@@ -283,7 +283,7 @@ void enter_SEK() { ...@@ -283,7 +283,7 @@ void enter_SEK() {
while (!checkHex(sek, 16)) { while (!checkHex(sek, 16)) {
spdlog::error("Invalid hex in key"); spdlog::error("Invalid hex in key");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-9); exit(-9);
} }
......
...@@ -116,7 +116,7 @@ int SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _chec ...@@ -116,7 +116,7 @@ int SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _chec
if (!server->StartListening()) { if (!server->StartListening()) {
spdlog::error("Info server could not start listening on port {}", BASE_PORT + 4); spdlog::error("Info server could not start listening on port {}", BASE_PORT + 4);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-10); exit(-10);
} else { } else {
spdlog::info("Info server started on port {}", BASE_PORT + 4); spdlog::info("Info server started on port {}", BASE_PORT + 4);
......
...@@ -173,7 +173,7 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) { ...@@ -173,7 +173,7 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) {
if (!server->StartListening()) { if (!server->StartListening()) {
spdlog::error("Registration server could not start listening on port {}", BASE_PORT + 1); spdlog::error("Registration server could not start listening on port {}", BASE_PORT + 1);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-10); exit(-10);
} else { } else {
spdlog::info("Registration server started on port {}", BASE_PORT + 1); spdlog::info("Registration server started on port {}", BASE_PORT + 1);
......
...@@ -142,7 +142,7 @@ void SGXWalletServer::createCertsIfNeeded() { ...@@ -142,7 +142,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog::info("ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED"); spdlog::info("ROOT CA CERTIFICATE IS SUCCESSFULLY GENERATED");
} else { } else {
spdlog::error("ROOT CA CERTIFICATE GENERATION FAILED"); spdlog::error("ROOT CA CERTIFICATE GENERATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-11); exit(-11);
} }
} }
...@@ -160,7 +160,7 @@ void SGXWalletServer::createCertsIfNeeded() { ...@@ -160,7 +160,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY GENERATED"); spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY GENERATED");
} else { } else {
spdlog::info("SERVER CERTIFICATE GENERATION FAILED"); spdlog::info("SERVER CERTIFICATE GENERATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-12); exit(-12);
} }
} }
...@@ -171,7 +171,7 @@ void SGXWalletServer::createCertsIfNeeded() { ...@@ -171,7 +171,7 @@ void SGXWalletServer::createCertsIfNeeded() {
spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY VERIFIED"); spdlog::info("SERVER CERTIFICATE IS SUCCESSFULLY VERIFIED");
} else { } else {
spdlog::info("SERVER CERTIFICATE VERIFICATION FAILED"); spdlog::info("SERVER CERTIFICATE VERIFICATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-12); exit(-12);
} }
} }
...@@ -182,10 +182,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -182,10 +182,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
spdlog::info("Entering {}", __FUNCTION__); spdlog::info("Entering {}", __FUNCTION__);
spdlog::info("Initing server, number of threads: {}", NUM_THREADS); spdlog::info("Initing server, number of threads: {}", NUM_THREADS);
string certPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.crt"; string certPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.crt";
string keyPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.key"; string keyPath = string(SGXDATA_FOLDER) + "cert_data/SGXServerCert.key";
string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem"; string rootCAPath = string(SGXDATA_FOLDER) + "cert_data/rootCA.pem";
...@@ -201,7 +197,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -201,7 +197,7 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
if (!server->StartListening()) { if (!server->StartListening()) {
spdlog::error("SGX Server could not start listening"); spdlog::error("SGX Server could not start listening");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-13); exit(-13);
} else { } else {
spdlog::info("SGX Server started on port {}", BASE_PORT); spdlog::info("SGX Server started on port {}", BASE_PORT);
...@@ -221,7 +217,7 @@ int SGXWalletServer::initHttpServer() { //without ssl ...@@ -221,7 +217,7 @@ int SGXWalletServer::initHttpServer() { //without ssl
JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0) JSONRPC_SERVER_V2); // hybrid server (json-rpc 1.0 & 2.0)
if (!server->StartListening()) { if (!server->StartListening()) {
spdlog::error("Server could not start listening"); spdlog::error("Server could not start listening");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-14); exit(-14);
} }
return 0; return 0;
......
...@@ -71,7 +71,7 @@ void systemHealthCheck() { ...@@ -71,7 +71,7 @@ void systemHealthCheck() {
ulimit = exec("/bin/bash -c \"ulimit -n\""); ulimit = exec("/bin/bash -c \"ulimit -n\"");
} catch (...) { } catch (...) {
spdlog::error("Execution of '/bin/bash -c ulimit -n' failed"); spdlog::error("Execution of '/bin/bash -c ulimit -n' failed");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-15); exit(-15);
} }
int noFiles = strtol(ulimit.c_str(), NULL, 10); int noFiles = strtol(ulimit.c_str(), NULL, 10);
...@@ -86,7 +86,7 @@ void systemHealthCheck() { ...@@ -86,7 +86,7 @@ void systemHealthCheck() {
"and setting 'DefaultLimitNOFILE=65535'\n" "and setting 'DefaultLimitNOFILE=65535'\n"
"After that, restart sgxwallet"; "After that, restart sgxwallet";
spdlog::error(errStr); spdlog::error(errStr);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-16); exit(-16);
} }
} }
...@@ -119,7 +119,7 @@ uint64_t initEnclave() { ...@@ -119,7 +119,7 @@ uint64_t initEnclave() {
support = get_sgx_support(); support = get_sgx_support();
if (!SGX_OK(support)) { if (!SGX_OK(support)) {
sgx_support_perror(support); sgx_support_perror(support);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_enclave);
exit(-17); exit(-17);
} }
#endif #endif
...@@ -151,7 +151,7 @@ uint64_t initEnclave() { ...@@ -151,7 +151,7 @@ uint64_t initEnclave() {
} else { } else {
spdlog::error("sgx_create_enclave_search failed {} {}", ENCLAVE_NAME, status); spdlog::error("sgx_create_enclave_search failed {} {}", ENCLAVE_NAME, status);
} }
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_enclave);
exit(-21); exit(-21);
} }
...@@ -227,18 +227,18 @@ void initAll(uint32_t _logLevel, bool _checkCert, ...@@ -227,18 +227,18 @@ void initAll(uint32_t _logLevel, bool _checkCert,
sgxServerInited = true; sgxServerInited = true;
} catch (SGXException &_e) { } catch (SGXException &_e) {
spdlog::error(_e.getMessage()); spdlog::error(_e.getMessage());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-18); exit(-18);
} catch (exception &_e) { } catch (exception &_e) {
spdlog::error(_e.what()); spdlog::error(_e.what());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-19); exit(-19);
} }
catch (...) { catch (...) {
exception_ptr p = current_exception(); exception_ptr p = current_exception();
printf("Exception %s \n", p.__cxa_exception_type()->name()); printf("Exception %s \n", p.__cxa_exception_type()->name());
spdlog::error("Unknown exception"); spdlog::error("Unknown exception");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-22); exit(-22);
} }
}; };
......
...@@ -42,12 +42,6 @@ ...@@ -42,12 +42,6 @@
#include "sgxwallet.h" #include "sgxwallet.h"
void SGXWallet::usage() {
cerr << "usage: sgxwallet\n";
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(-21);
}
void SGXWallet::printUsage() { void SGXWallet::printUsage() {
cerr << "\nAvailable flags:\n"; cerr << "\nAvailable flags:\n";
cerr << "\nDebug flags:\n\n"; cerr << "\nDebug flags:\n\n";
...@@ -211,16 +205,14 @@ int main(int argc, char *argv[]) { ...@@ -211,16 +205,14 @@ int main(int argc, char *argv[]) {
while (true) { while ( !ExitHandler::shouldExit() ) {
sleep(10); sleep(10);
if ( ExitHandler::shouldExit() ) { }
ExitHandler::exit_code_t exitCode = ExitHandler::requestedExitCode(); ExitHandler::exit_code_t exitCode = ExitHandler::requestedExitCode();
int signal = ExitHandler::getSignal();
spdlog::info("Will exit with exit code {}", exitCode); spdlog::info("Will exit with exit code {}", exitCode);
exitAll(); exitAll();
spdlog::info("Exiting with exit code {}", exitCode); spdlog::info("Exiting with exit code {} and signal", exitCode, signal);
return exitCode; return exitCode;
}
}
return 0;
} }
...@@ -26,7 +26,6 @@ class SGXWallet { ...@@ -26,7 +26,6 @@ class SGXWallet {
public: public:
static void usage();
static void printUsage(); static void printUsage();
static void serializeKeys( const vector<string>& _ecdsaKeyNames, static void serializeKeys( const vector<string>& _ecdsaKeyNames,
......
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