diff options
Diffstat (limited to 'cpp/src')
-rw-r--r-- | cpp/src/Ice/Instance.cpp | 4 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerI.cpp | 20 | ||||
-rw-r--r-- | cpp/src/Ice/LoggerI.h | 6 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.cpp | 40 | ||||
-rw-r--r-- | cpp/src/IceBox/ServiceManagerI.h | 2 | ||||
-rw-r--r-- | cpp/src/IcePack/ActivatorI.cpp | 36 | ||||
-rw-r--r-- | cpp/src/IcePack/AdapterManagerI.cpp | 2 | ||||
-rw-r--r-- | cpp/src/IceStorm/Service.cpp | 27 |
8 files changed, 80 insertions, 57 deletions
diff --git a/cpp/src/Ice/Instance.cpp b/cpp/src/Ice/Instance.cpp index 7244e8f7ea5..9f9557b6d4d 100644 --- a/cpp/src/Ice/Instance.cpp +++ b/cpp/src/Ice/Instance.cpp @@ -305,10 +305,10 @@ IceInternal::Instance::Instance(const CommunicatorPtr& communicator, int& argc, } else { - _logger = new LoggerI; + _logger = new LoggerI(_properties->getProperty("Ice.ProgramName")); } #else - _logger = new LoggerI; + _logger = new LoggerI(_properties->getProperty("Ice.ProgramName")); #endif _traceLevels = new TraceLevels(_properties); diff --git a/cpp/src/Ice/LoggerI.cpp b/cpp/src/Ice/LoggerI.cpp index e5b8b453da5..720cd4d58a2 100644 --- a/cpp/src/Ice/LoggerI.cpp +++ b/cpp/src/Ice/LoggerI.cpp @@ -14,6 +14,19 @@ using namespace std; using namespace Ice; using namespace IceInternal; +Ice::LoggerI::LoggerI(const string& prefix) +{ + if(!prefix.empty()) + { + _prefix = prefix + ": "; + + // + // A prefix filled with spaces and as long as the prefix. + // + _emptyPrefix.append(_prefix.length(), ' '); + } +} + void Ice::LoggerI::trace(const string& category, const string& message) { @@ -23,21 +36,22 @@ Ice::LoggerI::trace(const string& category, const string& message) while((idx = s.find("\n", idx)) != string::npos) { s.insert(idx + 1, " "); + s.insert(idx + 1, _emptyPrefix); ++idx; } - cerr << s << endl; + cerr << _prefix << s << endl; } void Ice::LoggerI::warning(const string& message) { IceUtil::Mutex::Lock sync(*this); - cerr << "warning: " << message << endl; + cerr << _prefix << "warning: " << message << endl; } void Ice::LoggerI::error(const string& message) { IceUtil::Mutex::Lock sync(*this); - cerr << "error: " << message << endl; + cerr << _prefix << "error: " << message << endl; } diff --git a/cpp/src/Ice/LoggerI.h b/cpp/src/Ice/LoggerI.h index ff7d2c33e29..f7706247af5 100644 --- a/cpp/src/Ice/LoggerI.h +++ b/cpp/src/Ice/LoggerI.h @@ -20,10 +20,16 @@ namespace Ice class LoggerI : public Logger, public ::IceUtil::Mutex { public: + LoggerI(const std::string&); virtual void trace(const std::string&, const std::string&); virtual void warning(const std::string&); virtual void error(const std::string&); + +private: + + std::string _prefix; + std::string _emptyPrefix; }; } diff --git a/cpp/src/IceBox/ServiceManagerI.cpp b/cpp/src/IceBox/ServiceManagerI.cpp index c8ef663aba8..12c67a7d124 100644 --- a/cpp/src/IceBox/ServiceManagerI.cpp +++ b/cpp/src/IceBox/ServiceManagerI.cpp @@ -81,7 +81,7 @@ IceBox::ServiceManagerI::run() adapter->add(obj, stringToIdentity(identity)); // - // Load and initialize the services defined in the property set + // Load and start the services defined in the property set // with the prefix "IceBox.Service.". These properties should // have the following format: // @@ -126,29 +126,7 @@ IceBox::ServiceManagerI::run() } } - init(name, entryPoint, args); - } - - // - // Invoke start() on the services. - // - map<string,ServiceInfo>::const_iterator r; - for(r = _services.begin(); r != _services.end(); ++r) - { - try - { - r->second.service->start(); - } - catch(const FailureException&) - { - throw; - } - catch(const Exception& ex) - { - FailureException e; - e.reason = "ServiceManager: exception in start for service " + r->first + ": " + ex.ice_name(); - throw e; - } + start(name, entryPoint, args); } // @@ -201,10 +179,10 @@ IceBox::ServiceManagerI::run() } void -IceBox::ServiceManagerI::init(const string& service, const string& entryPoint, const StringSeq& args) +IceBox::ServiceManagerI::start(const string& service, const string& entryPoint, const StringSeq& args) { // - // We need to create a property set to pass to init(). + // We need to create a property set to pass to start(). // The property set is populated from a number of sources. // The precedence order (from lowest to highest) is: // @@ -283,7 +261,7 @@ IceBox::ServiceManagerI::init(const string& service, const string& entryPoint, c } // - // Invoke Service::init(). + // Invoke Service::start(). // try { @@ -293,7 +271,7 @@ IceBox::ServiceManagerI::init(const string& service, const string& entryPoint, c // // IceBox::Service // - s->init(service, _server->communicator(), serviceProperties, serviceArgs); + s->start(service, _server->communicator(), serviceProperties, serviceArgs); } else { @@ -323,7 +301,7 @@ IceBox::ServiceManagerI::init(const string& service, const string& entryPoint, c } _dbEnvs[info.dbEnvName] = dbInfo; - fs->init(service, _server->communicator(), serviceProperties, serviceArgs, dbInfo.dbEnv); + fs->start(service, _server->communicator(), serviceProperties, serviceArgs, dbInfo.dbEnv); } info.library = library; _services[service] = info; @@ -331,7 +309,7 @@ IceBox::ServiceManagerI::init(const string& service, const string& entryPoint, c catch(const Freeze::DBException& ex) { FailureException e; - e.reason = "ServiceManager: database exception while initializing service " + service + ": " + ex.ice_name() + + e.reason = "ServiceManager: database exception while starting service " + service + ": " + ex.ice_name() + "\n" + ex.message; throw e; } @@ -342,7 +320,7 @@ IceBox::ServiceManagerI::init(const string& service, const string& entryPoint, c catch(const Exception& ex) { FailureException e; - e.reason = "ServiceManager: exception while initializing service " + service + ": " + ex.ice_name(); + e.reason = "ServiceManager: exception while starting service " + service + ": " + ex.ice_name(); throw e; } } diff --git a/cpp/src/IceBox/ServiceManagerI.h b/cpp/src/IceBox/ServiceManagerI.h index 4bf925f4c33..ac6cc047519 100644 --- a/cpp/src/IceBox/ServiceManagerI.h +++ b/cpp/src/IceBox/ServiceManagerI.h @@ -42,7 +42,7 @@ public: private: - void init(const std::string&, const std::string&, const ::Ice::StringSeq&); + void start(const std::string&, const std::string&, const ::Ice::StringSeq&); void stop(const std::string&); void stopAll(); diff --git a/cpp/src/IcePack/ActivatorI.cpp b/cpp/src/IcePack/ActivatorI.cpp index 5db518594b2..0260d459550 100644 --- a/cpp/src/IcePack/ActivatorI.cpp +++ b/cpp/src/IcePack/ActivatorI.cpp @@ -136,7 +136,7 @@ IcePack::ActivatorI::activate(const ServerPrx& server, const ::Ice::Current&) if(pid == 0) // Child process. { // - // Close all filedescriptors, except for standard input, + // Close all file descriptors, except for standard input, // standard output, standard error output, and the write side // of the newly created pipe. // @@ -150,6 +150,34 @@ IcePack::ActivatorI::activate(const ServerPrx& server, const ::Ice::Current&) } // + // Redirect the standard error output to the write side of the + // pipe. + // + // TODO: This doesn't work well if the server doesn't control + // when and how the output is flushed. This can result for + // example in printing on character by line... The standard + // Ice logger could be changed to flush the stream and not use + // automatic flushing. + // +// if(fds[1] != STDERR_FILENO) +// { +// if(dup2(fds[1], STDERR_FILENO) != STDERR_FILENO) +// { +// // +// // Send any errors to the parent process, using the write +// // end of the pipe. +// // +// SystemException ex(__FILE__, __LINE__); +// ex.error = getSystemErrno(); +// ostringstream s; +// s << "can't redirect stderr to the pipe output"; +// write(fds[1], s.str().c_str(), s.str().length()); +// close(fds[1]); +// exit(EXIT_FAILURE); +// } +// } + + // // Change working directory. // string pwd = desc.pwd; @@ -184,7 +212,7 @@ IcePack::ActivatorI::activate(const ServerPrx& server, const ::Ice::Current&) // // Compute arguments. // - int argc = desc.args.size() + _defaultArgs.size() + 2; + int argc = desc.args.size() + _defaultArgs.size() + 3; char** argv = static_cast<char**>(malloc(argc * sizeof(char*))); argv[0] = strdup(path.c_str()); unsigned int i = 0; @@ -197,6 +225,10 @@ IcePack::ActivatorI::activate(const ServerPrx& server, const ::Ice::Current&) { argv[i + 1] = strdup(q->c_str()); } + + string serverName = "--Ice.ProgramName=" + desc.name; + argv[argc - 2] = strdup(serverName.c_str()); + argv[argc - 1] = 0; if(execvp(argv[0], argv) == -1) diff --git a/cpp/src/IcePack/AdapterManagerI.cpp b/cpp/src/IcePack/AdapterManagerI.cpp index cf94d5f5ea8..4eebb8a2a75 100644 --- a/cpp/src/IcePack/AdapterManagerI.cpp +++ b/cpp/src/IcePack/AdapterManagerI.cpp @@ -114,7 +114,7 @@ IcePack::AdapterManagerI::AdapterManagerI(const ObjectAdapterPtr& adapter) : _adapter(adapter) { Ice::PropertiesPtr properties = adapter->getCommunicator()->getProperties(); - _waitTime = properties->getPropertyAsIntWithDefault("IcePack.Activation.WaitTime", 10); + _waitTime = properties->getPropertyAsIntWithDefault("IcePack.Activation.WaitTime", 60); } AdapterPrx diff --git a/cpp/src/IceStorm/Service.cpp b/cpp/src/IceStorm/Service.cpp index 7effd2f9cfa..b97a01730a3 100644 --- a/cpp/src/IceStorm/Service.cpp +++ b/cpp/src/IceStorm/Service.cpp @@ -26,13 +26,11 @@ public: Service(); virtual ~Service(); - virtual void init(const ::std::string&, - const ::Ice::CommunicatorPtr&, - const ::Ice::PropertiesPtr&, - const ::Ice::StringSeq&, - const ::Freeze::DBEnvironmentPtr&); - - virtual void start(); + virtual void start(const ::std::string&, + const ::Ice::CommunicatorPtr&, + const ::Ice::PropertiesPtr&, + const ::Ice::StringSeq&, + const ::Freeze::DBEnvironmentPtr&); virtual void stop(); @@ -67,11 +65,11 @@ IceStorm::Service::~Service() } void -IceStorm::Service::init(const string& name, - const ::Ice::CommunicatorPtr& communicator, - const ::Ice::PropertiesPtr& properties, - const ::Ice::StringSeq& args, - const ::Freeze::DBEnvironmentPtr& dbEnv) +IceStorm::Service::start(const string& name, + const ::Ice::CommunicatorPtr& communicator, + const ::Ice::PropertiesPtr& properties, + const ::Ice::StringSeq& args, + const ::Freeze::DBEnvironmentPtr& dbEnv) { Freeze::DBPtr dbTopicManager = dbEnv->openDB("topicmanager", true); @@ -84,11 +82,6 @@ IceStorm::Service::init(const string& name, } void -IceStorm::Service::start() -{ -} - -void IceStorm::Service::stop() { _adapter->deactivate(); |