SKALE-4005 add exit code for zmq

parent 0ee16cca
......@@ -121,7 +121,6 @@ int CSRManagerServer::initCSRManagerServer() {
if (!cs->StartListening()) {
spdlog::info("CSR manager server could not start listening");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-1);
} else {
spdlog::info("CSR manager server started on port {}", BASE_PORT + 2);
}
......
......@@ -18,6 +18,7 @@ public:
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
ec_cannot_start_zeromq = 203, // error starting ZMQ server
};
private:
......
......@@ -277,7 +277,6 @@ void LevelDB::initDataFolderAndDBs() {
if (getcwd(cwd, sizeof(cwd)) == NULL) {
spdlog::error("could not get current workin directory");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_creating_database);
exit(-2);
}
sgx_data_folder = string(cwd) + "/" + SGXDATA_FOLDER;
......@@ -292,7 +291,6 @@ void LevelDB::initDataFolderAndDBs() {
else{
spdlog::error("Couldnt create creating sgx_data folder");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_creating_database);
exit(-3);
}
}
......
......@@ -92,7 +92,6 @@ void validate_SEK() {
BUF_LEN)) {
spdlog::error("Corrupt test key is LevelDB");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-4);
}
sgx_status_t status = SGX_SUCCESS;
......@@ -111,7 +110,6 @@ void validate_SEK() {
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_error_initing_sek);
exit(-5);
}
}
......@@ -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) {
CHECK_STATE(hex_encrypted_SEK);
......@@ -260,14 +245,12 @@ void enter_SEK() {
if (test_key_ptr == nullptr) {
spdlog::error("Error: corrupt or empty LevelDB database");
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_error_initing_sek);
exit(-8);
}
ifstream sek_file(BACKUP_PATH);
......@@ -284,7 +267,6 @@ void enter_SEK() {
while (!checkHex(sek, 16)) {
spdlog::error("Invalid hex in key");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_initing_sek);
exit(-9);
}
auto encrypted_SEK = check_and_set_SEK(sek);
......
......@@ -47,8 +47,6 @@ EXTERNC void initSEK();
EXTERNC void setSEK();
//EXTERNC void safeExit();
......
......@@ -117,7 +117,6 @@ 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_error_starting_server);
exit(-10);
} else {
spdlog::info("Info server started on port {}", BASE_PORT + 4);
}
......
......@@ -174,7 +174,6 @@ 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_error_starting_server);
exit(-10);
} else {
spdlog::info("Registration server started on port {}", BASE_PORT + 1);
}
......
......@@ -143,7 +143,6 @@ void SGXWalletServer::createCertsIfNeeded() {
} else {
spdlog::error("ROOT CA CERTIFICATE GENERATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-11);
}
}
......@@ -161,7 +160,6 @@ void SGXWalletServer::createCertsIfNeeded() {
} else {
spdlog::info("SERVER CERTIFICATE GENERATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-12);
}
}
......@@ -172,7 +170,6 @@ void SGXWalletServer::createCertsIfNeeded() {
} else {
spdlog::info("SERVER CERTIFICATE VERIFICATION FAILED");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_creating_certificate);
exit(-12);
}
}
......@@ -198,7 +195,6 @@ int SGXWalletServer::initHttpsServer(bool _checkCerts) {
if (!server->StartListening()) {
spdlog::error("SGX Server could not start listening");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-13);
} else {
spdlog::info("SGX Server started on port {}", BASE_PORT);
}
......@@ -218,8 +214,8 @@ int SGXWalletServer::initHttpServer() { //without ssl
if (!server->StartListening()) {
spdlog::error("Server could not start listening");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_error_starting_server);
exit(-14);
}
return 0;
}
......
......@@ -72,7 +72,6 @@ void systemHealthCheck() {
} catch (...) {
spdlog::error("Execution of '/bin/bash -c ulimit -n' failed");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-15);
}
int noFiles = strtol(ulimit.c_str(), NULL, 10);
......@@ -87,13 +86,9 @@ void systemHealthCheck() {
"After that, restart sgxwallet";
spdlog::error(errStr);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-16);
}
}
void initUserSpace() {
libff::inhibit_profiling_counters = true;
......@@ -120,7 +115,6 @@ uint64_t initEnclave() {
if (!SGX_OK(support)) {
sgx_support_perror(support);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_enclave);
exit(-17);
}
#endif
......@@ -152,7 +146,6 @@ uint64_t initEnclave() {
spdlog::error("sgx_create_enclave_search failed {} {}", ENCLAVE_NAME, status);
}
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_enclave);
exit(-21);
}
spdlog::info("Enclave created and started successfully");
......@@ -228,18 +221,15 @@ void initAll(uint32_t _logLevel, bool _checkCert,
} catch (SGXException &_e) {
spdlog::error(_e.getMessage());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_initing_user_space);
exit(-18);
} catch (exception &_e) {
spdlog::error(_e.what());
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_initing_user_space);
exit(-22);
}
};
......
......@@ -79,8 +79,7 @@ void ZMQServer::run() {
frontend->bind("tcp://*:" + to_string(port));
} catch (...) {
spdlog::error("Server task could not bind to port:{}", port);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(ZMQ_COULD_NOT_BIND_FRONT_END);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
}
spdlog::info("Bound port ...");
......@@ -90,8 +89,7 @@ void ZMQServer::run() {
backend->bind("inproc://backend");
} catch (exception &e) {
spdlog::error("Could not bind to zmq backend: {}", e.what());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(ZMQ_COULD_NOT_BIND_BACK_END);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
}
......@@ -106,8 +104,7 @@ void ZMQServer::run() {
}
} catch (std::exception &e) {
spdlog::error("Could not create zmq server workers:{} ", e.what());
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(ZMQ_COULD_NOT_CREATE_WORKERS);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
};
......@@ -127,8 +124,7 @@ void ZMQServer::run() {
return;
}
spdlog::info("Error, exiting zmq server ...");
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(ZMQ_COULD_NOT_CREATE_PROXY);
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_cannot_start_zeromq);
}
}
......
......@@ -100,7 +100,6 @@ int main(int argc, char *argv[]) {
if (argc > 1 && strlen(argv[1]) == 1) {
SGXWallet::printUsage();
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(-22);
}
while ((opt = getopt(argc, argv, "cshd0abyvVnT")) != -1) {
......@@ -108,7 +107,6 @@ int main(int argc, char *argv[]) {
case 'h':
SGXWallet::printUsage();
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(-24);
case 'c':
checkClientCertOption = false;
break;
......@@ -146,7 +144,6 @@ int main(int argc, char *argv[]) {
default:
SGXWallet::printUsage();
ExitHandler::exitHandler(SIGTERM, ExitHandler::ec_failure);
exit(-23);
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