SKALE-4005 add unique exit codes

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