SKALE-4005 add exit code for zmq

parent 0ee16cca
...@@ -121,7 +121,6 @@ int CSRManagerServer::initCSRManagerServer() { ...@@ -121,7 +121,6 @@ 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_error_starting_server); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
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);
} }
......
...@@ -18,6 +18,7 @@ public: ...@@ -18,6 +18,7 @@ public:
ec_creating_certificate = 200, // error creating SSL certificate to initialize server ec_creating_certificate = 200, // error creating SSL certificate to initialize server
ec_initing_enclave = 201, // error starting secure enclave ec_initing_enclave = 201, // error starting secure enclave
ec_initing_user_space = 202, // error or exception while initializing user space ec_initing_user_space = 202, // error or exception while initializing user space
ec_cannot_start_zeromq = 203, // error starting ZMQ server
}; };
private: private:
......
...@@ -277,7 +277,6 @@ void LevelDB::initDataFolderAndDBs() { ...@@ -277,7 +277,6 @@ 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_error_creating_database); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_creating_database);
exit(-2);
} }
sgx_data_folder = string(cwd) + "/" + SGXDATA_FOLDER; sgx_data_folder = string(cwd) + "/" + SGXDATA_FOLDER;
...@@ -292,7 +291,6 @@ void LevelDB::initDataFolderAndDBs() { ...@@ -292,7 +291,6 @@ 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_error_creating_database); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_creating_database);
exit(-3);
} }
} }
......
...@@ -92,7 +92,6 @@ void validate_SEK() { ...@@ -92,7 +92,6 @@ void validate_SEK() {
BUF_LEN)) { BUF_LEN)) {
spdlog::error("Corrupt test key is LevelDB"); spdlog::error("Corrupt test key is LevelDB");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-4);
} }
sgx_status_t status = SGX_SUCCESS; sgx_status_t status = SGX_SUCCESS;
...@@ -111,7 +110,6 @@ void validate_SEK() { ...@@ -111,7 +110,6 @@ void validate_SEK() {
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_error_initing_sek); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-5);
} }
} }
...@@ -208,19 +206,6 @@ void gen_SEK() { ...@@ -208,19 +206,6 @@ void gen_SEK() {
} }
//static std::atomic<int> isSgxWalletExiting(0);
//void safeExit() {
// // this is to make sure exit is only called once if called from multiple threads
// auto previousValue = isSgxWalletExiting.exchange(1);
// if (previousValue != 1)
// exit(-6);
//}
void setSEK(shared_ptr <string> hex_encrypted_SEK) { void setSEK(shared_ptr <string> hex_encrypted_SEK) {
CHECK_STATE(hex_encrypted_SEK); CHECK_STATE(hex_encrypted_SEK);
...@@ -260,14 +245,12 @@ void enter_SEK() { ...@@ -260,14 +245,12 @@ void enter_SEK() {
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_error_initing_sek); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
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_error_initing_sek); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-8);
} }
ifstream sek_file(BACKUP_PATH); ifstream sek_file(BACKUP_PATH);
...@@ -284,7 +267,6 @@ void enter_SEK() { ...@@ -284,7 +267,6 @@ 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_error_initing_sek); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-9);
} }
auto encrypted_SEK = check_and_set_SEK(sek); auto encrypted_SEK = check_and_set_SEK(sek);
......
...@@ -47,8 +47,6 @@ EXTERNC void initSEK(); ...@@ -47,8 +47,6 @@ EXTERNC void initSEK();
EXTERNC void setSEK(); EXTERNC void setSEK();
//EXTERNC void safeExit();
......
...@@ -117,7 +117,6 @@ int SGXInfoServer::initInfoServer(uint32_t _logLevel, bool _autoSign, bool _chec ...@@ -117,7 +117,6 @@ 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_error_starting_server); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-10);
} else { } else {
spdlog::info("Info server started on port {}", BASE_PORT + 4); spdlog::info("Info server started on port {}", BASE_PORT + 4);
} }
......
...@@ -174,7 +174,6 @@ int SGXRegistrationServer::initRegistrationServer(bool _autoSign) { ...@@ -174,7 +174,6 @@ 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_error_starting_server); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-10);
} else { } else {
spdlog::info("Registration server started on port {}", BASE_PORT + 1); spdlog::info("Registration server started on port {}", BASE_PORT + 1);
} }
......
...@@ -143,7 +143,6 @@ void SGXWalletServer::createCertsIfNeeded() { ...@@ -143,7 +143,6 @@ void SGXWalletServer::createCertsIfNeeded() {
} else { } else {
spdlog::error("ROOT CA CERTIFICATE GENERATION FAILED"); spdlog::error("ROOT CA CERTIFICATE GENERATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-11);
} }
} }
...@@ -161,7 +160,6 @@ void SGXWalletServer::createCertsIfNeeded() { ...@@ -161,7 +160,6 @@ void SGXWalletServer::createCertsIfNeeded() {
} else { } else {
spdlog::info("SERVER CERTIFICATE GENERATION FAILED"); spdlog::info("SERVER CERTIFICATE GENERATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-12);
} }
} }
...@@ -172,7 +170,6 @@ void SGXWalletServer::createCertsIfNeeded() { ...@@ -172,7 +170,6 @@ void SGXWalletServer::createCertsIfNeeded() {
} else { } else {
spdlog::info("SERVER CERTIFICATE VERIFICATION FAILED"); spdlog::info("SERVER CERTIFICATE VERIFICATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-12);
} }
} }
...@@ -198,7 +195,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) { ...@@ -198,7 +195,6 @@ 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_error_starting_server); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-13);
} else { } else {
spdlog::info("SGX Server started on port {}", BASE_PORT); spdlog::info("SGX Server started on port {}", BASE_PORT);
} }
...@@ -218,8 +214,8 @@ int SGXWalletServer::initHttpServer() { //without ssl ...@@ -218,8 +214,8 @@ int SGXWalletServer::initHttpServer() { //without ssl
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_error_starting_server); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-14);
} }
return 0; return 0;
} }
......
...@@ -72,7 +72,6 @@ void systemHealthCheck() { ...@@ -72,7 +72,6 @@ void systemHealthCheck() {
} 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_initing_user_space); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-15);
} }
int noFiles = strtol(ulimit.c_str(), NULL, 10); int noFiles = strtol(ulimit.c_str(), NULL, 10);
...@@ -87,13 +86,9 @@ void systemHealthCheck() { ...@@ -87,13 +86,9 @@ void systemHealthCheck() {
"After that, restart sgxwallet"; "After that, restart sgxwallet";
spdlog::error(errStr); spdlog::error(errStr);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-16);
} }
} }
void initUserSpace() { void initUserSpace() {
libff::inhibit_profiling_counters = true; libff::inhibit_profiling_counters = true;
...@@ -120,7 +115,6 @@ uint64_t initEnclave() { ...@@ -120,7 +115,6 @@ uint64_t initEnclave() {
if (!SGX_OK(support)) { if (!SGX_OK(support)) {
sgx_support_perror(support); sgx_support_perror(support);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_enclave); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_enclave);
exit(-17);
} }
#endif #endif
...@@ -152,7 +146,6 @@ uint64_t initEnclave() { ...@@ -152,7 +146,6 @@ uint64_t initEnclave() {
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_initing_enclave); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_enclave);
exit(-21);
} }
spdlog::info("Enclave created and started successfully"); spdlog::info("Enclave created and started successfully");
...@@ -228,18 +221,15 @@ void initAll(uint32_t _logLevel, bool _checkCert, ...@@ -228,18 +221,15 @@ void initAll(uint32_t _logLevel, bool _checkCert,
} catch (SGXException &_e) { } catch (SGXException &_e) {
spdlog::error(_e.getMessage()); spdlog::error(_e.getMessage());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-18);
} catch (exception &_e) { } catch (exception &_e) {
spdlog::error(_e.what()); spdlog::error(_e.what());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
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_initing_user_space); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-22);
} }
}; };
......
...@@ -79,8 +79,7 @@ void ZMQServer::run() { ...@@ -79,8 +79,7 @@ void ZMQServer::run() {
frontend->bind("tcp://*:" + to_string(port)); frontend->bind("tcp://*:" + to_string(port));
} catch (...) { } catch (...) {
spdlog::error("Server task could not bind to port:{}", port); spdlog::error("Server task could not bind to port:{}", port);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
exit(ZMQ_COULD_NOT_BIND_FRONT_END);
} }
spdlog::info("Bound port ..."); spdlog::info("Bound port ...");
...@@ -90,8 +89,7 @@ void ZMQServer::run() { ...@@ -90,8 +89,7 @@ void ZMQServer::run() {
backend->bind("inproc://backend"); backend->bind("inproc://backend");
} catch (exception &e) { } catch (exception &e) {
spdlog::error("Could not bind to zmq backend: {}", e.what()); spdlog::error("Could not bind to zmq backend: {}", e.what());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
exit(ZMQ_COULD_NOT_BIND_BACK_END);
} }
...@@ -106,8 +104,7 @@ void ZMQServer::run() { ...@@ -106,8 +104,7 @@ void ZMQServer::run() {
} }
} catch (std::exception &e) { } catch (std::exception &e) {
spdlog::error("Could not create zmq server workers:{} ", e.what()); spdlog::error("Could not create zmq server workers:{} ", e.what());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
exit(ZMQ_COULD_NOT_CREATE_WORKERS);
}; };
...@@ -127,8 +124,7 @@ void ZMQServer::run() { ...@@ -127,8 +124,7 @@ void ZMQServer::run() {
return; return;
} }
spdlog::info("Error, exiting zmq server ..."); spdlog::info("Error, exiting zmq server ...");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
exit(ZMQ_COULD_NOT_CREATE_PROXY);
} }
} }
......
...@@ -100,7 +100,6 @@ int main(int argc, char *argv[]) { ...@@ -100,7 +100,6 @@ int main(int argc, char *argv[]) {
if (argc > 1 && strlen(argv[1]) == 1) { if (argc > 1 && strlen(argv[1]) == 1) {
SGXWallet::printUsage(); SGXWallet::printUsage();
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(-22);
} }
while ((opt = getopt(argc, argv, "cshd0abyvVnT")) != -1) { while ((opt = getopt(argc, argv, "cshd0abyvVnT")) != -1) {
...@@ -108,7 +107,6 @@ int main(int argc, char *argv[]) { ...@@ -108,7 +107,6 @@ int main(int argc, char *argv[]) {
case 'h': case 'h':
SGXWallet::printUsage(); SGXWallet::printUsage();
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(-24);
case 'c': case 'c':
checkClientCertOption = false; checkClientCertOption = false;
break; break;
...@@ -146,7 +144,6 @@ int main(int argc, char *argv[]) { ...@@ -146,7 +144,6 @@ int main(int argc, char *argv[]) {
default: default:
SGXWallet::printUsage(); SGXWallet::printUsage();
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure); ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(-23);
break; break;
} }
} }
......
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