diff options
author | Marc Laukien <marc@zeroc.com> | 2002-04-16 23:45:16 +0000 |
---|---|---|
committer | Marc Laukien <marc@zeroc.com> | 2002-04-16 23:45:16 +0000 |
commit | cb721b45d761ccb7fa3bb873e3d567dd665b1f9f (patch) | |
tree | 75bd19e8d32751ff178093f47b4ce87e83d4b6d0 /cpp/src | |
parent | align with C++ - fixes for the thread pool (diff) | |
download | ice-cb721b45d761ccb7fa3bb873e3d567dd665b1f9f.tar.bz2 ice-cb721b45d761ccb7fa3bb873e3d567dd665b1f9f.tar.xz ice-cb721b45d761ccb7fa3bb873e3d567dd665b1f9f.zip |
IcePatch improvements; Ice.PrintAdapterReady timing fix
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 62 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.cpp | 16 | ||||
-rw-r--r-- | cpp/src/Ice/ObjectAdapterI.h | 1 | ||||
-rw-r--r-- | cpp/src/IcePatch/.depend | 4 | ||||
-rw-r--r-- | cpp/src/IcePatch/Client.cpp | 14 | ||||
-rw-r--r-- | cpp/src/IcePatch/FileLocator.cpp | 7 | ||||
-rw-r--r-- | cpp/src/IcePatch/IcePatchI.cpp | 113 | ||||
-rw-r--r-- | cpp/src/IcePatch/IcePatchI.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePatch/Server.cpp | 123 | ||||
-rw-r--r-- | cpp/src/IcePatch/Util.cpp | 22 | ||||
-rw-r--r-- | cpp/src/IceStorm/Server.cpp | 5 |
11 files changed, 222 insertions, 147 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index d883f3dbb0f..abf3a010d1f 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -33,6 +33,8 @@ # include <csignal> # include <syslog.h> # include <sys/time.h> +# include <pwd.h> +# include <sys/types.h> #else # include <sys/timeb.h> #endif @@ -187,22 +189,12 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope if (++_globalStateCounter == 1) // Only on first call { - // Must be done before "Ice.Daemon" is checked - if (atoi(_properties->getProperty("Ice.PrintProcessId").c_str()) > 0) - { -#ifdef _WIN32 - cout << _getpid() << endl; -#else - cout << getpid() << endl; -#endif - } - #ifndef _WIN32 if (atoi(_properties->getProperty("Ice.Daemon").c_str()) > 0) { int noclose = atoi(_properties->getProperty("Ice.DaemonNoClose").c_str()); int nochdir = atoi(_properties->getProperty("Ice.DaemonNoChdir").c_str()); - + if (daemon(nochdir, noclose) == -1) { --_globalStateCounter; @@ -212,9 +204,39 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope throw ex; } } -#endif -#ifndef _WIN32 + 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; + } + + if (setgid(pw->pw_gid) == -1) + { + --_globalStateCounter; + _globalStateMutex->unlock(); + SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + + if (setuid(pw->pw_uid) == -1) + { + --_globalStateCounter; + _globalStateMutex->unlock(); + SystemException ex(__FILE__, __LINE__); + ex.error = getSystemErrno(); + throw ex; + } + } + if (atoi(_properties->getProperty("Ice.UseSyslog").c_str()) > 0) { _identForOpenlog = _properties->getProperty("Ice.ProgramName"); @@ -226,6 +248,20 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, const Prope } #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 (atoi(_properties->getProperty("Ice.PrintProcessId").c_str()) > 0) + { +#ifdef _WIN32 + cout << _getpid() << endl; +#else + cout << getpid() << endl; +#endif + } + #ifdef _WIN32 WORD version = MAKEWORD(1, 1); WSADATA data; diff --git a/cpp/src/Ice/ObjectAdapterI.cpp b/cpp/src/Ice/ObjectAdapterI.cpp index 0ec2ddfe363..789e60d1c18 100644 --- a/cpp/src/Ice/ObjectAdapterI.cpp +++ b/cpp/src/Ice/ObjectAdapterI.cpp @@ -56,6 +56,16 @@ Ice::ObjectAdapterI::activate() for_each(_incomingConnectionFactories.begin(), _incomingConnectionFactories.end(), Ice::voidMemFun(&IncomingConnectionFactory::activate)); + + if (!_printAdapterReadyDone) + { + if (atoi(_instance->properties()->getProperty("Ice.PrintAdapterReady").c_str()) > 0) + { + cout << _name << " ready" << endl; + } + + _printAdapterReadyDone = true; + } } void @@ -363,6 +373,7 @@ Ice::ObjectAdapterI::getIncomingConnections() const Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const string& name, const string& endpts) : _instance(instance), _deactivated(false), + _printAdapterReadyDone(false), _name(name), _activeServantMapHint(_activeServantMap.end()), _locatorMapHint(_locatorMap.end()) @@ -432,11 +443,6 @@ Ice::ObjectAdapterI::ObjectAdapterI(const InstancePtr& instance, const string& n throw EndpointParseException(__FILE__, __LINE__); } */ - - if (atoi(_instance->properties()->getProperty("Ice.PrintAdapterReady").c_str()) > 0) - { - cout << _name << " ready" << endl; - } } Ice::ObjectAdapterI::~ObjectAdapterI() diff --git a/cpp/src/Ice/ObjectAdapterI.h b/cpp/src/Ice/ObjectAdapterI.h index f8f1b108d98..82598bd3062 100644 --- a/cpp/src/Ice/ObjectAdapterI.h +++ b/cpp/src/Ice/ObjectAdapterI.h @@ -70,6 +70,7 @@ private: ::IceInternal::InstancePtr _instance; bool _deactivated; + bool _printAdapterReadyDone; std::string _name; ObjectDict _activeServantMap; ObjectDict::iterator _activeServantMapHint; diff --git a/cpp/src/IcePatch/.depend b/cpp/src/IcePatch/.depend index 267185c90d9..6de72b08a9f 100644 --- a/cpp/src/IcePatch/.depend +++ b/cpp/src/IcePatch/.depend @@ -3,8 +3,8 @@ FileDescFactory.o: FileDescFactory.cpp ../../include/IcePatch/FileDescFactory.h Util.o: Util.cpp ../../include/IcePatch/Util.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/IcePatch.h Client.o: Client.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/FileDescFactory.h ../../include/IcePatch/IcePatch.h ../../include/IcePatch/Util.h Server.o: Server.cpp ../../include/Ice/Application.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../IcePatch/FileLocator.h ../../include/IcePatch/IcePatch.h ../../include/IcePatch/Util.h -IcePatchI.o: IcePatchI.cpp ../IcePatch/IcePatchI.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/IcePatch.h ../../include/IcePatch/Util.h -FileLocator.o: FileLocator.cpp ../IcePatch/FileLocator.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/IcePatch.h ../../include/IcePatch/Util.h ../IcePatch/IcePatchI.h +IcePatchI.o: IcePatchI.cpp ../IcePatch/IcePatchI.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IceUtil/RWRecMutex.h ../../include/IcePatch/IcePatch.h ../../include/IcePatch/Util.h +FileLocator.o: FileLocator.cpp ../IcePatch/FileLocator.h ../../include/Ice/Ice.h ../../include/Ice/Initialize.h ../../include/Ice/CommunicatorF.h ../../include/Ice/ProxyF.h ../../include/Ice/ProxyHandle.h ../../include/IceUtil/Handle.h ../../include/IceUtil/Exception.h ../../include/IceUtil/Config.h ../../include/Ice/Config.h ../../include/Ice/ObjectF.h ../../include/Ice/Handle.h ../../include/Ice/LocalObjectF.h ../../include/Ice/Exception.h ../../include/Ice/LocalException.h ../../include/Ice/ObjectFactoryF.h ../../include/Ice/LocalObject.h ../../include/IceUtil/Shared.h ../../include/Ice/StreamF.h ../../include/Ice/PropertiesF.h ../../include/Ice/InstanceF.h ../../include/Ice/Properties.h ../../include/Ice/BuiltinSequences.h ../../include/Ice/Logger.h ../../include/Ice/LoggerUtil.h ../../include/Ice/LoggerF.h ../../include/Ice/Communicator.h ../../include/Ice/Proxy.h ../../include/IceUtil/Mutex.h ../../include/IceUtil/Lock.h ../../include/Ice/ProxyFactoryF.h ../../include/Ice/ConnectionF.h ../../include/Ice/EndpointF.h ../../include/Ice/ObjectAdapterF.h ../../include/Ice/ReferenceF.h ../../include/Ice/Current.h ../../include/Ice/Identity.h ../../include/Ice/Object.h ../../include/Ice/Outgoing.h ../../include/IceUtil/Monitor.h ../../include/IceUtil/Cond.h ../../include/Ice/BasicStream.h ../../include/Ice/Buffer.h ../../include/Ice/Incoming.h ../../include/Ice/Direct.h ../../include/Ice/ServantLocatorF.h ../../include/Ice/UserExceptionFactoryF.h ../../include/Ice/RouterF.h ../../include/Ice/SystemF.h ../../include/Ice/SslExtensionF.h ../../include/Ice/ObjectFactory.h ../../include/Ice/UserExceptionFactory.h ../../include/Ice/ObjectAdapter.h ../../include/Ice/ServantLocator.h ../../include/Ice/IdentityUtil.h ../../include/IcePatch/IcePatch.h ../../include/IcePatch/Util.h ../IcePatch/IcePatchI.h ../../include/IceUtil/RWRecMutex.h blocksort.o: blocksort.c bzlib_private.h bzlib.h huffman.o: huffman.c bzlib_private.h bzlib.h crctable.o: crctable.c bzlib_private.h bzlib.h diff --git a/cpp/src/IcePatch/Client.cpp b/cpp/src/IcePatch/Client.cpp index f5ea8c0602c..ac3d894ce03 100644 --- a/cpp/src/IcePatch/Client.cpp +++ b/cpp/src/IcePatch/Client.cpp @@ -89,7 +89,14 @@ IcePatch::Client::run(int argc, char* argv[]) string directory = properties->getProperty(directoryProperty); if (!directory.empty()) { - changeDirectory(directory); +#ifdef _WIN32 + if (_chdir(directory.c_str()) == -1) +#else + if (chdir(directory.c_str()) == -1) +#endif + { + cerr << appName() << ": cannot change to directory `" << directory << "': " << strerror(errno) << endl; + } } // @@ -175,11 +182,6 @@ public: void IcePatch::Client::patch(const FileDescSeq& fileDescSeq, const string& indent) { - if (fileDescSeq.empty()) - { - return; - } - for (unsigned int i = 0; i < fileDescSeq.size(); ++i) { string path; diff --git a/cpp/src/IcePatch/FileLocator.cpp b/cpp/src/IcePatch/FileLocator.cpp index cdd001cd84d..bcf0a46cab7 100644 --- a/cpp/src/IcePatch/FileLocator.cpp +++ b/cpp/src/IcePatch/FileLocator.cpp @@ -30,7 +30,7 @@ IcePatch::FileLocator::locate(const ObjectAdapterPtr& adapter, const Current& cu // string path = identityToPath(current.identity); - if (path.empty()) + if (path.empty()) // Empty paths are not permissible. { return 0; } @@ -50,6 +50,11 @@ IcePatch::FileLocator::locate(const ObjectAdapterPtr& adapter, const Current& cu return 0; } + if (ignoreSuffix(path)) // Some suffixes are reserved. + { + return 0; + } + FileInfo info; try { diff --git a/cpp/src/IcePatch/IcePatchI.cpp b/cpp/src/IcePatch/IcePatchI.cpp index 54f33440c71..1efd45d8264 100644 --- a/cpp/src/IcePatch/IcePatchI.cpp +++ b/cpp/src/IcePatch/IcePatchI.cpp @@ -15,6 +15,8 @@ using namespace std; using namespace Ice; using namespace IcePatch; +IceUtil::RWRecMutex IcePatch::FileI::_globalMutex; + IcePatch::FileI::FileI(const ObjectAdapterPtr& adapter) : _adapter(adapter) { @@ -28,6 +30,8 @@ IcePatch::DirectoryI::DirectoryI(const ObjectAdapterPtr& adapter) : FileDescPtr IcePatch::DirectoryI::describe(const Ice::Current& current) { + // No lock necessary. + string path = identityToPath(current.identity); DirectoryDescPtr desc = new DirectoryDesc; desc->directory = DirectoryPrx::uncheckedCast(_adapter->createProxy(current.identity)); return desc; @@ -36,30 +40,47 @@ IcePatch::DirectoryI::describe(const Ice::Current& current) FileDescSeq IcePatch::DirectoryI::getContents(const Ice::Current& current) { - StringSeq paths = readDirectory(identityToPath(current.identity)); + //IceUtil::RWRecMutex::RLock sync(_globalMutex); // TODO: RLock as soon as lock promotion works. + string path = identityToPath(current.identity); + StringSeq paths = readDirectory(path); FileDescSeq result; result.reserve(paths.size()); - StringSeq::const_iterator p; - for (p = paths.begin(); p != paths.end(); ++p) + for (StringSeq::const_iterator p = paths.begin(); p != paths.end(); ++p) { if (ignoreSuffix(*p)) { - continue; - } - - FilePrx file = FilePrx::uncheckedCast(_adapter->createProxy(pathToIdentity(*p))); - try - { - result.push_back(file->describe()); + pair<StringSeq::const_iterator, StringSeq::const_iterator> r = + equal_range(paths.begin(), paths.end(), removeSuffix(*p)); + if (r.first == r.second) + { + IceUtil::RWRecMutex::WLock sync(_globalMutex); + StringSeq paths2 = readDirectory(path); + pair<StringSeq::const_iterator, StringSeq::const_iterator> r2 = + equal_range(paths2.begin(), paths2.end(), removeSuffix(*p)); + if (r2.first == r2.second) + { + cout << "removing orphaned file `" << *p << "'... " << flush; + removeRecursive(*p); + cout << "ok" << endl; + } + } } - catch (const ObjectNotExistException&) + else { - // - // Ignore. This can for example happen if the file - // locator cannot call stat() on the file. - // + FilePrx file = FilePrx::uncheckedCast(_adapter->createProxy(pathToIdentity(*p))); + try + { + result.push_back(file->describe()); + } + catch (const ObjectNotExistException&) + { + // + // Ignore. This can for example happen if the file + // locator cannot call stat() on the file. + // + } } } @@ -74,20 +95,76 @@ IcePatch::RegularI::RegularI(const ObjectAdapterPtr& adapter) : FileDescPtr IcePatch::RegularI::describe(const Ice::Current& current) { + //IceUtil::RWRecMutex::RLock sync(_globalMutex); // TODO: RLock as soon as lock promotion works. + string path = identityToPath(current.identity); + + FileInfo info = getFileInfo(path, true); + FileInfo infoMD5 = getFileInfo(path + ".md5", false); + if (infoMD5.type != FileTypeRegular || infoMD5.time < info.time) + { + IceUtil::RWRecMutex::WLock sync(_globalMutex); + infoMD5 = getFileInfo(path + ".md5", false); + if (infoMD5.type != FileTypeRegular || infoMD5.time < info.time) + { + cout << "creating .md5 file for `" << path << "'... " << flush; + createMD5(path); + cout << "ok" << endl; + } + } + RegularDescPtr desc = new RegularDesc; desc->regular = RegularPrx::uncheckedCast(_adapter->createProxy(current.identity)); - desc->md5 = getMD5(identityToPath(current.identity)); + desc->md5 = getMD5(path); return desc; } Int IcePatch::RegularI::getBZ2Size(const Ice::Current& current) { - return getFileInfo(identityToPath(current.identity) + ".bz2", true).size; + //IceUtil::RWRecMutex::RLock sync(_globalMutex); + string path = identityToPath(current.identity); + + FileInfo info = getFileInfo(path, true); + FileInfo infoBZ2 = getFileInfo(path + ".bz2", false); + if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) + { + IceUtil::RWRecMutex::WLock sync(_globalMutex); + infoBZ2 = getFileInfo(path + ".bz2", false); + if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) + { + cout << "creating .bz2 file for `" << path << "'... " << flush; + createBZ2(path); + cout << "ok" << endl; + + // Get the .bz2 file info again, so that we can return the + // size below. This time the .bz2 file must exist, + // otherwise an exception is raised. + infoBZ2 = getFileInfo(path + ".bz2", true); + } + } + + return infoBZ2.size; } ByteSeq IcePatch::RegularI::getBZ2(Ice::Int pos, Ice::Int num, const Ice::Current& current) { - return IcePatch::getBZ2(identityToPath(current.identity), pos, num); + //IceUtil::RWRecMutex::RLock sync(_globalMutex); // TODO: RLock as soon as lock promotion works. + string path = identityToPath(current.identity); + + FileInfo info = getFileInfo(path, true); + FileInfo infoBZ2 = getFileInfo(path + ".bz2", false); + if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) + { + IceUtil::RWRecMutex::WLock sync(_globalMutex); + infoBZ2 = getFileInfo(path + ".bz2", false); + if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) + { + cout << "creating .bz2 file for `" << path << "'... " << flush; + createBZ2(path); + cout << "ok" << endl; + } + } + + return IcePatch::getBZ2(path, pos, num); } diff --git a/cpp/src/IcePatch/IcePatchI.h b/cpp/src/IcePatch/IcePatchI.h index 3ad907355c2..a395c84cbaf 100644 --- a/cpp/src/IcePatch/IcePatchI.h +++ b/cpp/src/IcePatch/IcePatchI.h @@ -12,6 +12,7 @@ #define ICE_PATCH_ICE_PATCH_I_H #include <Ice/Ice.h> +#include <IceUtil/RWRecMutex.h> #include <IcePatch/IcePatch.h> namespace IcePatch @@ -26,6 +27,7 @@ public: protected: Ice::ObjectAdapterPtr _adapter; + static IceUtil::RWRecMutex _globalMutex; }; class DirectoryI : virtual public Directory, diff --git a/cpp/src/IcePatch/Server.cpp b/cpp/src/IcePatch/Server.cpp index fadbf596b95..3f90275cfa4 100644 --- a/cpp/src/IcePatch/Server.cpp +++ b/cpp/src/IcePatch/Server.cpp @@ -26,8 +26,7 @@ public: void usage(); virtual int run(int, char*[]); - static void removeOrphanedRecursive(const string&); - static void updateRecursive(const string&); + static void cleanup(const FileDescSeq&); }; }; @@ -88,28 +87,41 @@ IcePatch::Server::run(int argc, char* argv[]) string directory = properties->getProperty(directoryProperty); if (!directory.empty()) { - changeDirectory(directory); +#ifdef _WIN32 + if (_chdir(directory.c_str()) == -1) +#else + if (chdir(directory.c_str()) == -1) +#endif + { + cerr << appName() << ": cannot change to directory `" << directory << "': " << strerror(errno) << endl; + } } - // - // Remove orphaned MD5 and BZ2 files. - // Create MD5 and BZ2 files. - // - removeOrphanedRecursive("."); - updateRecursive("."); - // // Create and initialize the object adapter and the file locator. // ObjectAdapterPtr adapter = communicator()->createObjectAdapterFromProperty("IcePatch", endpointsProperty); ServantLocatorPtr fileLocator = new FileLocator(adapter); adapter->addServantLocator(fileLocator, "IcePatch"); - adapter->activate(); - // - // We're done, let's wait for shutdown. - // - communicator()->waitForShutdown(); + // + // Do cleanup. + // + Identity identity = pathToIdentity("."); + ObjectPrx topObj = communicator()->stringToProxy(identityToString(identity) + ':' + endpoints); + FilePrx top = FilePrx::checkedCast(topObj); + assert(top); + DirectoryDescPtr topDesc = DirectoryDescPtr::dynamicCast(top->describe()); + assert(topDesc); + cleanup(topDesc->directory->getContents()); + + // + // Everything ok, let's go. + // + shutdownOnInterrupt(); + adapter->activate(); + communicator()->waitForShutdown(); + ignoreInterrupt(); } catch (const FileAccessException& ex) { @@ -121,77 +133,28 @@ IcePatch::Server::run(int argc, char* argv[]) } void -IcePatch::Server::removeOrphanedRecursive(const string& path) -{ - assert(getFileInfo(path, true).type == FileTypeDirectory); - - StringSeq paths = readDirectory(path); - StringSeq::const_iterator p; - for (p = paths.begin(); p != paths.end(); ++p) - { - if (ignoreSuffix(*p)) - { - pair<StringSeq::const_iterator, StringSeq::const_iterator> r = - equal_range(paths.begin(), paths.end(), removeSuffix(*p)); - if (r.first == r.second) - { - cout << "removing orphaned file `" << *p << "'... " << flush; - removeRecursive(*p); - cout << "ok" << endl; - } - } - else - { - if (getFileInfo(*p, true).type == FileTypeDirectory) - { - removeOrphanedRecursive(*p); - } - } - } - - if (readDirectory(path).empty()) - { - cout << "removing empty directory `" << *p << "'... " << flush; - removeRecursive(path); - cout << "ok" << endl; - } -} - -void -IcePatch::Server::updateRecursive(const string& path) +IcePatch::Server::cleanup(const FileDescSeq& fileDescSeq) { - if (ignoreSuffix(path)) + for (FileDescSeq::const_iterator p = fileDescSeq.begin(); p != fileDescSeq.end(); ++p) { - return; - } - - FileInfo info = getFileInfo(path, true); - - if (info.type == FileTypeDirectory) - { - StringSeq paths = readDirectory(path); - StringSeq::const_iterator p; - for (p = paths.begin(); p != paths.end(); ++p) + DirectoryDescPtr directoryDesc = DirectoryDescPtr::dynamicCast(*p); + if (directoryDesc) { - updateRecursive(*p); + // + // Force .md5 files to be created and orphaned files to be + // removed. + // + cleanup(directoryDesc->directory->getContents()); } - } - else if (info.type == FileTypeRegular) - { - FileInfo infoMD5 = getFileInfo(path + ".md5", false); - if (infoMD5.type != FileTypeRegular || infoMD5.time < info.time) + else { - cout << "creating .md5 file for `" << path << "'... " << flush; - createMD5(path); - cout << "ok" << endl; - } + RegularDescPtr regularDesc = RegularDescPtr::dynamicCast(*p); + assert(regularDesc); - FileInfo infoBZ2 = getFileInfo(path + ".bz2", false); - if (infoBZ2.type != FileTypeRegular || infoBZ2.time < info.time) - { - cout << "creating .bz2 file for `" << path << "'... " << flush; - createBZ2(path); - cout << "ok" << endl; + // + // Force .bz2 files to be created. + // + regularDesc->regular->getBZ2Size(); } } } diff --git a/cpp/src/IcePatch/Util.cpp b/cpp/src/IcePatch/Util.cpp index 473b36ed53d..4146a2b8345 100644 --- a/cpp/src/IcePatch/Util.cpp +++ b/cpp/src/IcePatch/Util.cpp @@ -176,21 +176,6 @@ IcePatch::removeRecursive(const string& path) } } -void -IcePatch::changeDirectory(const string& path) -{ -#ifdef _WIN32 - if (_chdir(path.c_str()) == -1) -#else - if (chdir(path.c_str()) == -1) -#endif - { - FileAccessException ex; - ex.reason = "cannot change to directory `" + path + "': " + strerror(errno); - throw ex; - } -} - StringSeq IcePatch::readDirectory(const string& path) { @@ -316,12 +301,10 @@ IcePatch::getMD5(const string& path) void IcePatch::createMD5(const string& path) { - FileInfo info = getFileInfo(path, true); - assert(info.type == FileTypeRegular); - // // Read the original file. // + FileInfo info = getFileInfo(path, true); ifstream file(path.c_str(), ios::binary); if (!file) { @@ -425,9 +408,6 @@ IcePatch::getBZ2(const string& path, Int pos, Int num) void IcePatch::createBZ2(const string& path) { - FileInfo info = getFileInfo(path, true); - assert(info.type == FileTypeRegular); - // // Read the original file in blocks and write a temporary BZ2 // file. diff --git a/cpp/src/IceStorm/Server.cpp b/cpp/src/IceStorm/Server.cpp index 92d4d015acb..17e1ef3d1de 100644 --- a/cpp/src/IceStorm/Server.cpp +++ b/cpp/src/IceStorm/Server.cpp @@ -96,9 +96,12 @@ IceStorm::Server::runFreeze(int argc, char* argv[], const Freeze::DBEnvironmentP "IceStorm.TopicManager.Endpoints"); TopicManagerIPtr manager = new TopicManagerI(communicator(), adapter, traceLevels, dbEnv, dbTopicManager); adapter->add(manager, stringToIdentity("TopicManager")); - adapter->activate(); + // + // Everything ok, let's go. + // shutdownOnInterrupt(); + adapter->activate(); communicator()->waitForShutdown(); ignoreInterrupt(); |