diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 218 | ||||
-rw-r--r-- | cpp/src/IcePatch/Client.cpp | 15 |
2 files changed, 117 insertions, 116 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index cd804e09ed7..621ab8a889a 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -185,120 +185,84 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope _communicator(communicator), _properties(properties) { - _globalStateMutex->lock(); + IceUtil::Mutex::Lock sync(*_globalStateMutex); + ++_globalStateCounter; - if (++_globalStateCounter == 1) // Only on first call + try { -#ifndef _WIN32 - if (_properties->getPropertyAsInt("Ice.Daemon") > 0) - { - int noclose = _properties->getPropertyAsInt("Ice.DaemonNoClose"); - int nochdir = _properties->getPropertyAsInt("Ice.DaemonNoChdir"); - - if (daemon(nochdir, noclose) == -1) - { - --_globalStateCounter; - _globalStateMutex->unlock(); - SystemException ex(__FILE__, __LINE__); - ex.error = getSystemErrno(); - throw ex; - } - } - - string newUser = _properties->getProperty("Ice.ChangeUser"); - if (!newUser.empty()) - { - struct passwd* pw = getpwnam(newUser.c_str()); - if (!pw) - { - --_globalStateCounter; - _globalStateMutex->unlock(); - SystemException ex(__FILE__, __LINE__); - ex.error = getSystemErrno(); - throw ex; - } + __setNoDelete(true); - if (setgid(pw->pw_gid) == -1) + if (_globalStateCounter == 1) // Only on first call + { +#ifdef _WIN32 + WORD version = MAKEWORD(1, 1); + WSADATA data; + if (WSAStartup(version, &data) != 0) { - --_globalStateCounter; _globalStateMutex->unlock(); - SystemException ex(__FILE__, __LINE__); - ex.error = getSystemErrno(); + SocketException ex(__FILE__, __LINE__); + ex.error = getSocketErrno(); throw ex; } - - if (setuid(pw->pw_uid) == -1) - { - --_globalStateCounter; - _globalStateMutex->unlock(); - SystemException ex(__FILE__, __LINE__); - ex.error = getSystemErrno(); - throw ex; - } - } - - if (_properties->getPropertyAsInt("Ice.UseSyslog") > 0) - { - _identForOpenlog = _properties->getProperty("Ice.ProgramName"); - if (_identForOpenlog.empty()) - { - _identForOpenlog = "<Unknown Ice Program>"; - } - openlog(_identForOpenlog.c_str(), LOG_PID, LOG_USER); - } -#endif - - // - // Must be done after daemon() is called, since daemon() - // forks. Does not work together with Ice.Daemon if - // Ice.DaemonNoClose is not set. - // - if (_properties->getPropertyAsInt("Ice.PrintProcessId") > 0) - { -#ifdef _WIN32 - cout << _getpid() << endl; -#else - cout << getpid() << endl; -#endif - } - -#ifdef _WIN32 - WORD version = MAKEWORD(1, 1); - WSADATA data; - if (WSAStartup(version, &data) != 0) - { - _globalStateMutex->unlock(); - SocketException ex(__FILE__, __LINE__); - ex.error = getSocketErrno(); - throw ex; - } #endif - + #ifndef _WIN32 - struct sigaction action; - action.sa_handler = SIG_IGN; - sigemptyset(&action.sa_mask); - action.sa_flags = 0; - sigaction(SIGPIPE, &action, 0); + struct sigaction action; + action.sa_handler = SIG_IGN; + sigemptyset(&action.sa_mask); + action.sa_flags = 0; + sigaction(SIGPIPE, &action, 0); #endif - + #ifdef _WIN32 - struct _timeb tb; - _ftime(&tb); - srand(tb.millitm); + struct _timeb tb; + _ftime(&tb); + srand(tb.millitm); #else - timeval tv; - gettimeofday(&tv, 0); - srand(tv.tv_usec); + timeval tv; + gettimeofday(&tv, 0); + srand(tv.tv_usec); #endif - } - - _globalStateMutex->unlock(); +#ifndef _WIN32 + string newUser = _properties->getProperty("Ice.ChangeUser"); + if (!newUser.empty()) + { + struct passwd* pw = getpwnam(newUser.c_str()); + if (!pw) + { + SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + + if (setgid(pw->pw_gid) == -1) + { + SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + + if (setuid(pw->pw_uid) == -1) + { + SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + } + + if (_properties->getPropertyAsInt("Ice.UseSyslog") > 0) + { + _identForOpenlog = _properties->getProperty("Ice.ProgramName"); + if (_identForOpenlog.empty()) + { + _identForOpenlog = "<Unknown Ice Program>"; + } + openlog(_identForOpenlog.c_str(), LOG_PID, LOG_USER); + } +#endif + } - try - { - __setNoDelete(true); #ifndef _WIN32 if (_properties->getPropertyAsInt("Ice.UseSyslog") > 0) { @@ -311,38 +275,82 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope #else _logger = new LoggerI; #endif + _traceLevels = new TraceLevels(_properties); + _defaultProtocol = _properties->getPropertyWithDefault("Ice.DefaultProtocol", "tcp"); _defaultHost = _properties->getProperty("Ice.DefaultHost"); if (_defaultHost.empty()) { _defaultHost = getLocalHost(true); } + _routerManager = new RouterManager; + _referenceFactory = new ReferenceFactory(this); + _proxyFactory = new ProxyFactory(this); string router = _properties->getProperty("Ice.DefaultRouter"); if (!router.empty()) { _referenceFactory->setDefaultRouter(RouterPrx::uncheckedCast(_proxyFactory->stringToProxy(router))); } + _outgoingConnectionFactory = new OutgoingConnectionFactory(this); + _servantFactoryManager = new ObjectFactoryManager(); + _userExceptionFactoryManager = new UserExceptionFactoryManager(); - _objectAdapterFactory = new ObjectAdapterFactory(this); - _threadPool = new ThreadPool(this); - __setNoDelete(false); - // Get our instance of the SSL System + _objectAdapterFactory = new ObjectAdapterFactory(this); + _sslSystem = IceSSL::Factory::getSystem(this); - - // Get the SSL system to configure itself _sslSystem->configure(); + + // + // daemon() must be called after the SSL system has been + // configured, since SSL might want to read a passphrase from + // standard input. + // + if (_properties->getPropertyAsInt("Ice.Daemon") > 0) + { + int noclose = _properties->getPropertyAsInt("Ice.DaemonNoClose"); + int nochdir = _properties->getPropertyAsInt("Ice.DaemonNoChdir"); + + if (daemon(nochdir, noclose) == -1) + { + SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + } + + // + // Must be done after daemon() is called, since daemon() + // forks. Does not work together with Ice.Daemon if + // Ice.DaemonNoClose is not set. + // + if (_properties->getPropertyAsInt("Ice.PrintProcessId") > 0) + { +#ifdef _WIN32 + cout << _getpid() << endl; +#else + cout << getpid() << endl; +#endif + } + + // + // Thread pool initialization must be done after daemon() is + // called, since daemon() forks. + // + _threadPool = new ThreadPool(this); + __setNoDelete(false); } catch(...) { destroy(); __setNoDelete(false); + --_globalStateCounter; throw; } } diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp index 3fb8b6d4d5f..7702792361e 100644 --- a/cpp/src/IcePatch/Client.cpp +++ b/cpp/src/IcePatch/Client.cpp @@ -126,9 +126,7 @@ IcePatch::Client::run(int argc, char* argv[]) } string clientConfig = properties->getProperty("Ice.SSL.Client.Config"); - string serverConfig = properties->getProperty("Ice.SSL.Server.Config"); - - if (!clientConfig.empty() && !serverConfig.empty()) + if (!clientConfig.empty()) { string privateKeyBase64 = IceUtil::Base64::encode(privateKey); string publicKeyBase64 = IceUtil::Base64::encode(publicKey); @@ -137,14 +135,9 @@ IcePatch::Client::run(int argc, char* argv[]) IceSSL::SystemPtr sslSystem = communicator()->getSslSystem(); IceSSL::SslExtensionPtr sslExtension = communicator()->getSslExtension(); - // Configure Server, client is already configured. - sslSystem->configure(IceSSL::Server); - sslSystem->setCertificateVerifier(IceSSL::ClientServer, - sslExtension->getSingleCertVerifier(routerCert)); - - // Set the keys overrides. - sslSystem->setRSAKeysBase64(IceSSL::ClientServer, privateKeyBase64, publicKeyBase64); - sslSystem->addTrustedCertificateBase64(IceSSL::ClientServer, routerCertString); + sslSystem->setCertificateVerifier(IceSSL::Client, sslExtension->getSingleCertVerifier(routerCert)); + sslSystem->setRSAKeysBase64(IceSSL::Client, privateKeyBase64, publicKeyBase64); + sslSystem->addTrustedCertificateBase64(IceSSL::Client, routerCertString); } communicator()->setDefaultRouter(router); |