From c9fc77f2d120257c3e10b9d38b28a46510b1f36b Mon Sep 17 00:00:00 2001 From: csoler Date: Tue, 6 Dec 2011 23:00:42 +0000 Subject: [PATCH] removed calls to exit() in rsinit. Replaced them by proper return false git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4711 b45a01b8-16f6-495d-af2f-9b41ad6348cc --- libretroshare/src/retroshare/rsinit.h | 3 ++- libretroshare/src/rsserver/rsinit.cc | 35 +++++++++++++++------------ 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/libretroshare/src/retroshare/rsinit.h b/libretroshare/src/retroshare/rsinit.h index a6255155a..d0d004c97 100644 --- a/libretroshare/src/retroshare/rsinit.h +++ b/libretroshare/src/retroshare/rsinit.h @@ -31,6 +31,7 @@ #define RS_INIT_HAVE_ACCOUNT 1 // Initialize ok, have account // Initialize failed, result < 0 #define RS_INIT_AUTH_FAILED -1 // AuthGPG::InitAuth failed +#define RS_INIT_BASE_DIR_ERROR -2 // AuthGPG::InitAuth failed /**** @@ -134,7 +135,7 @@ class RsInit /* PreLogin */ static std::string getHomePath() ; - static void setupBaseDir(); + static bool setupBaseDir(); /* Account Details */ static bool get_configinit(const std::string& dir, std::string &id); diff --git a/libretroshare/src/rsserver/rsinit.cc b/libretroshare/src/rsserver/rsinit.cc index 3678d6845..fb6be7c7b 100644 --- a/libretroshare/src/rsserver/rsinit.cc +++ b/libretroshare/src/rsserver/rsinit.cc @@ -583,7 +583,9 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck AuthSSL::getAuthSSL() -> InitAuth(NULL, NULL, NULL); // first check config directories, and set bootstrap values. - setupBaseDir(); + if(!setupBaseDir()) + return RS_INIT_BASE_DIR_ERROR ; + get_configinit(RsInitConfig::basedir, RsInitConfig::preferedId); /* Initialize AuthGPG */ @@ -617,7 +619,7 @@ int RsInit::InitRetroShare(int argcIgnored, char **argvIgnored, bool strictCheck } if(!pgpNameFound){ std::cerr << "Invalid User name/GPG id/SSL id: not found in list" << std::endl; - exit(1); + return RS_INIT_AUTH_FAILED ; } } @@ -720,7 +722,7 @@ bool RsInit::getAccountDetails(std::string id, /**************************** Private Functions for InitRetroshare ********************/ -void RsInit::setupBaseDir() +bool RsInit::setupBaseDir() { // get the default configuration location. @@ -739,7 +741,7 @@ void RsInit::setupBaseDir() std::cerr << "load_check_basedir() Fatal Error --"; std::cerr << std::endl; std::cerr << "\tcannot determine $HOME dir" < &ids) if (!dirIt.isValid()) { std::cerr << "Cannot Open Base Dir - No Available Accounts" << std::endl; - exit(1); + return false ; } struct stat64 buf; @@ -1222,7 +1225,9 @@ bool RsInit::GenerateSSLCertificate(const std::string& gpg_id, const std::st std::string tmpdir = "TMPCFG"; std::string tmpbase = RsInitConfig::basedir + "/" + tmpdir + "/"; - RsInit::setupAccount(tmpbase); + + if(!RsInit::setupAccount(tmpbase)) + return false ; /* create directory structure */ @@ -1371,32 +1376,32 @@ bool RsInit::setupAccount(const std::string& accountdir) if (!RsDirUtil::checkCreateDirectory(accountdir)) { std::cerr << "Cannot Create BaseConfig Dir" << std::endl; - exit(1); + return false ; } if (!RsDirUtil::checkCreateDirectory(subdir1)) { std::cerr << "Cannot Create Config/Key Dir" << std::endl; - exit(1); + return false ; } if (!RsDirUtil::checkCreateDirectory(subdir2)) { std::cerr << "Cannot Create Config/Cert Dir" << std::endl; - exit(1); + return false ; } if (!RsDirUtil::checkCreateDirectory(subdir3)) { std::cerr << "Cannot Create Config/Cache Dir" << std::endl; - exit(1); + return false ; } if (!RsDirUtil::checkCreateDirectory(subdir4)) { std::cerr << "Cannot Create Config/Cache/local Dir" << std::endl; - exit(1); + return false ; } if (!RsDirUtil::checkCreateDirectory(subdir5)) { std::cerr << "Cannot Create Config/Cache/remote Dir" << std::endl; - exit(1); + return false ; } return true; @@ -1810,7 +1815,7 @@ int RsServer::StartupRetroShare() std::cerr << "main() - Fatal Error....." << std::endl; std::cerr << "Invalid Certificate configuration!" << std::endl; std::cerr << std::endl; - exit(1); + return false ; } std::string ownId = AuthSSL::getAuthSSL()->OwnId();