diff options
author | iliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2008-04-09 03:08:22 +0000 |
---|---|---|
committer | iliyan <iliyan@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2008-04-09 03:08:22 +0000 |
commit | 62760474cc7fa10f18a94433e730bcefe210b1e8 (patch) | |
tree | ecb4196077c628785626aeb29da46f580ebc0148 | |
parent | 11a64b4a99aa69891e1732080e00ac0751b1510e (diff) | |
download | ATCD-62760474cc7fa10f18a94433e730bcefe210b1e8.tar.gz |
ChangeLogTag: Wed Apr 9 02:43:37 UTC 2008 Iliyan Jeliazkov <iliyan@ociweb.com>
-rw-r--r-- | ACE/ChangeLog | 17 | ||||
-rw-r--r-- | ACE/ace/Dynamic_Service.inl | 4 | ||||
-rw-r--r-- | ACE/ace/OS_NS_unistd.cpp | 8 | ||||
-rw-r--r-- | ACE/ace/Service_Config.cpp | 36 | ||||
-rw-r--r-- | ACE/ace/Service_Config.h | 10 | ||||
-rw-r--r-- | ACE/ace/Service_Gestalt.cpp | 248 | ||||
-rw-r--r-- | ACE/ace/Service_Gestalt.h | 5 | ||||
-rw-r--r-- | ACE/ace/Service_Gestalt.inl | 16 | ||||
-rw-r--r-- | ACE/ace/Service_Repository.cpp | 189 |
9 files changed, 290 insertions, 243 deletions
diff --git a/ACE/ChangeLog b/ACE/ChangeLog index 4c861c3487f..6310449cce1 100644 --- a/ACE/ChangeLog +++ b/ACE/ChangeLog @@ -1,3 +1,20 @@ +Wed Apr 9 02:43:37 UTC 2008 Iliyan Jeliazkov <iliyan@ociweb.com> + + * ace/Dynamic_Service.inl (instance): + Adjusting interface to take a smart pointer. + + * ace/OS_NS_unistd.cpp (argv_to_string): + Adding interpretation for tabs and new line characters as + characters to trigger quoting. + + * ace/Service_Config.h: + * ace/Service_Config.cpp: + * ace/Service_Gestalt.h: + * ace/Service_Gestalt.inl: + * ace/Service_Gestalt.cpp: + * ace/Service_Repository.cpp: + Reformatting, updating comments and logging. + Wed Apr 9 01:21:42 UTC 2008 Douglas C. Schmidt <schmidt@dre.vanderbilt.edu> * ace/Condition_T.cpp (wait): Fixed a bug where the mutex diff --git a/ACE/ace/Dynamic_Service.inl b/ACE/ace/Dynamic_Service.inl index 48978c595ed..40c4a6bbe0a 100644 --- a/ACE/ace/Dynamic_Service.inl +++ b/ACE/ace/Dynamic_Service.inl @@ -20,14 +20,14 @@ ACE_Dynamic_Service<TYPE>::instance (const ACE_ANTI_TCHAR *name, } template <class TYPE> ACE_INLINE TYPE * -ACE_Dynamic_Service<TYPE>::instance (const ACE_Service_Gestalt* repo, +ACE_Dynamic_Service<TYPE>::instance (const ACE_Service_Gestalt_Auto_Ptr repo, const ACE_ANTI_TCHAR *name) { return instance (repo, ACE_TEXT_CHAR_TO_TCHAR (name),false); } template <class TYPE> ACE_INLINE TYPE * -ACE_Dynamic_Service<TYPE>::instance (const ACE_Service_Gestalt* repo, +ACE_Dynamic_Service<TYPE>::instance (const ACE_Service_Gestalt_Auto_Ptr repo, const ACE_ANTI_TCHAR *name, bool no_global) { diff --git a/ACE/ace/OS_NS_unistd.cpp b/ACE/ace/OS_NS_unistd.cpp index 1535a2f6612..88c0e262ffc 100644 --- a/ACE/ace/OS_NS_unistd.cpp +++ b/ACE/ace/OS_NS_unistd.cpp @@ -99,8 +99,14 @@ ACE_OS::argv_to_string (int argc, } } #endif /* ACE_LACKS_ENV */ + // If must quote, we only do it if the arg contains spaces, or + // is empty. Perhaps a check for other c | ord(c) <= 32 is in + // order? if (quote_args - && ACE_OS::strchr (argv_p[i], ACE_TEXT (' ')) != 0) + && (ACE_OS::strchr (argv_p[i], ACE_TEXT (' ')) != 0 + || ACE_OS::strchr (argv_p[i], ACE_TEXT ('\t')) != 0 + || ACE_OS::strchr (argv_p[i], ACE_TEXT ('\n')) != 0 + || *argv_p[i] == 0)) { if (argv_p == argv) { diff --git a/ACE/ace/Service_Config.cpp b/ACE/ace/Service_Config.cpp index cb807a80e8c..1eda39f8a8b 100644 --- a/ACE/ace/Service_Config.cpp +++ b/ACE/ace/Service_Config.cpp @@ -158,10 +158,12 @@ ACE_Service_Config::parse_args_i (int argc, ACE_TCHAR *argv[]) // Collect any argumets that were left for (int c = getopt.opt_ind (); c < argc; ++c) - superargv.add (argv[c-1], true); + superargv.add (argv[c-1], true); - return this->parse_args_i (superargv.argc (), - superargv.argv ()); + bool ignore_default_svc_conf_file = false; + return instance_->parse_args_i (superargv.argc (), + superargv.argv (), + ignore_default_svc_conf_file); } /* parse_args_i () */ @@ -190,10 +192,10 @@ ACE_Service_Config::open_i (const ACE_TCHAR program_name[], // forwarding to it, so we don't have to increment here. if (instance_->is_opened_ != 0) return instance_->open_i (program_name, - logger_key, - ignore_static_svcs, - ignore_default_svc_conf_file, - ignore_debug_flag); + logger_key, + ignore_static_svcs, + ignore_default_svc_conf_file, + ignore_debug_flag); // Check for things we need to do on a per-process basis and which // may not be safe, or wise to do an a per instance basis @@ -276,10 +278,10 @@ ACE_Service_Config::open_i (const ACE_TCHAR program_name[], return -1; return instance_->open_i (program_name, - logger_key, - ignore_static_svcs, - ignore_default_svc_conf_file, - ignore_debug_flag); + logger_key, + ignore_static_svcs, + ignore_default_svc_conf_file, + ignore_debug_flag); } /// Return the global configuration instance. Always returns the same @@ -335,17 +337,17 @@ ACE_Service_Config::ACE_Service_Config (bool ignore_static_svcs, int signum) { ACE_TRACE ("ACE_Service_Config::ACE_Service_Config"); - + // TODO: Need to find a more customizable way of instantiating the // gestalt but perhaps we should leave this out untill such // customizations are identified. ACE_Service_Gestalt* tmp = 0; ACE_NEW_NORETURN (tmp, ACE_Service_Gestalt (size, false, ignore_static_svcs)); - + this->instance_ = tmp; this->threadkey_.set (tmp); - + ACE_Service_Config::signum_ = signum; } @@ -353,17 +355,17 @@ ACE_Service_Config::ACE_Service_Config (const ACE_TCHAR program_name[], const ACE_TCHAR *logger_key) { ACE_TRACE ("ACE_Service_Config::ACE_Service_Config"); - + // TODO: Need to find a more customizable way of instantiating the // gestalt but perhaps we should leave this out untill such // customizations are identified. ACE_Service_Gestalt* tmp = 0; ACE_NEW_NORETURN (tmp, ACE_Service_Gestalt (ACE_Service_Repository::DEFAULT_SIZE, false)); - + this->instance_ = tmp; this->threadkey_.set (tmp); - + if (this->open (program_name, logger_key) == -1 && errno != ENOENT) { diff --git a/ACE/ace/Service_Config.h b/ACE/ace/Service_Config.h index b9c2c77e9dc..1ecfce042f8 100644 --- a/ACE/ace/Service_Config.h +++ b/ACE/ace/Service_Config.h @@ -263,8 +263,8 @@ protected: /// = Static interfaces -public: - /** + public: + /** * Returns the process-wide global singleton instance. It would * have been created and will be managed by the Object Manager. */ @@ -295,7 +295,7 @@ public: * * @deprecated Use current() instead. */ - static ACE_Service_Gestalt* instance (void); + static ACE_Service_Gestalt* instance (void); /** * Returns a process-wide global singleton instance in contrast with @@ -421,7 +421,7 @@ public: /// idiom for registering static services: /// /// ACE_Service_Config::static_svcs ()->insert (...); - static ACE_Service_Gestalt *static_svcs (void); + static ACE_Service_Gestalt* static_svcs (void); /// Insert a static service descriptor for processing on open_i(). The /// corresponding ACE_STATIC_SVC_* macros were chaged to use this method @@ -546,7 +546,7 @@ public: protected: - /// @deprecated + /// @deprecated /// Process service configuration requests that were provided on the /// command-line. Returns the number of errors that occurred. static int process_commandline_directives (void); diff --git a/ACE/ace/Service_Gestalt.cpp b/ACE/ace/Service_Gestalt.cpp index d1e1d72ebf4..6b10f129cb6 100644 --- a/ACE/ace/Service_Gestalt.cpp +++ b/ACE/ace/Service_Gestalt.cpp @@ -38,6 +38,7 @@ ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_Service_Type_Dynamic_Guard::ACE_Service_Type_Dynamic_Guard (ACE_Service_Repository &r, const ACE_TCHAR *name) : repo_ (r) + // Relocation starts where the next service will be inserted (if any) , repo_begin_ (r.current_size ()) , name_ (name) # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) @@ -60,29 +61,15 @@ ACE_Service_Type_Dynamic_Guard::ACE_Service_Type_Dynamic_Guard , repo_monitor_ (r.lock_) #endif { - ACE_ASSERT (this->name_ != 0); // No name? - ACE_NEW_NORETURN (this->dummy_, // Allocate the forward declaration ... - ACE_Service_Type (this->name_, // ... use the same name - 0, // ... inactive - ACE_DLL (), // ... bogus ACE_DLL - 0)); // ... no type_impl - - ACE_ASSERT (this->dummy_ != 0); // No memory? + if (ACE::debug ()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE (%P|%t) STDG::<ctor>, repo=%@") + ACE_TEXT(", name=%s - begining at [%d]\n"), + &this->repo_, + this->name_, + this->repo_begin_)); - if (ACE::debug ()) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) STDG::<ctor>, repo=%@ [%d], ") - ACE_TEXT ("name=%s, type=%@, impl=%@, object=%@, active=%d - inserting dummy forward\n"), - &this->repo_, this->repo_begin_, this->name_, this->dummy_, - this->dummy_->type (), - (this->dummy_->type () != 0) ? this->dummy_->type ()->object () : 0, - this->dummy_->active ())); - - // Note that the dummy_'s memory may be deallocated between invoking - // the ctor and dtor, if the expected ("real") dynamic service is - // inserted in the repository. See how this affects the destructor's - // behavior, below. - this->repo_.insert (this->dummy_); + ACE_ASSERT (this->name_ != 0); // No name? } @@ -99,81 +86,48 @@ ACE_Service_Type_Dynamic_Guard::~ACE_Service_Type_Dynamic_Guard (void) int const ret = this->repo_.find_i (this->name_, slot, &tmp, false); // We inserted it (as inactive), so we expect to find it, right? - if (ret < 0 && ret != -2) + if ((ret < 0 && ret != -2) || tmp == 0) { if (ACE::debug ()) ACE_ERROR ((LM_WARNING, - ACE_TEXT ("ACE (%P|%t) STDG::<dtor> - Failed (%d) to find %s\n"), - ret, this->name_)); + ACE_TEXT ("ACE (%P|%t) STDG::<dtor> - Failed (%d) to find %s -> %@\n"), + ret, this->name_, tmp)); return; } - if (tmp != 0 && tmp->type () != 0) + if (tmp->type () != 0) { // Something has registered a proper (non-forward-decl) service with // the same name as our dummy. if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) STDG::<dtor>, repo=%@, name=%s - updating [%d - %d]\n"), + ACE_TEXT ("ACE (%P|%t) STDG::<dtor>, repo=%@ [%d], ") + ACE_TEXT ("name=%s - updating dependents [%d - %d)\n"), &this->repo_, + slot, this->name_, this->repo_begin_, this->repo_.current_size ())); - // Relocate any static services. If any have been registered in - // the context of this guard, those really aren't static - // services because their code is in the DLL's code segment + // Relocate any services inserted since we were created. + // Any (static, i.e. DLL = 0) services registered in + // the context of this guard aren't really static because + // their code belongs in the DLL's code segment this->repo_.relocate_i (this->repo_begin_, this->repo_.current_size (), tmp->dll()); - // The ACE_Service_Gestalt::insert() modifies the memory for the - // original ACE_Service_Type instance. It deletes our dummy - // instance when replacing it with the actual implementation, so - // we are hereby simply giving up ownership. - this->dummy_ = 0; - if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE (%P|%t) STDG::<dtor>, repo=%@ [%d], ") - ACE_TEXT ("name=%s, type=%@, impl=%@, object=%@, active=%d - loaded\n"), - &this->repo_, this->repo_begin_, this->name_, tmp, tmp->type (), - (tmp->type () != 0) ? tmp->type ()->object () : 0, + ACE_TEXT ("name=%s - loaded (type=%@, impl=%@, object=%@, active=%d)\n"), + &this->repo_, + slot, + this->name_, + tmp, + tmp->type (), + tmp->type ()->object (), tmp->active ())); } - else - { - if (ACE::debug ()) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) STDG::<dtor>, repo=%@, ") - ACE_TEXT ("name=%s, type=%@, impl=%@, object=%@, active=%d - removing dummy forward\n"), - &this->repo_, this->name_, this->dummy_, this->dummy_->type (), - (this->dummy_->type () != 0) ? this->dummy_->type ()->object () : 0, - this->dummy_->active ())); - - // The (dummy) forward declaration is still there and is - // the same, which means that no actual declaration was - // provided inside the guarded scope. Therefore, the forward - // declaration is no longer necessary. - if (this->repo_.remove_i (this->name_, - const_cast< ACE_Service_Type**> (&this->dummy_)) == 0) - { - // If it is a dummy then deleting it while holding the repo lock is okay. There will be no - // call to service object's fini() and no possibility for deadlocks. - delete this->dummy_; - } - else - { - ACE_ERROR ((LM_WARNING, - ACE_TEXT ("ACE (%P|%t) STDG::<dtor>, repo=%@, name=%s, ") - ACE_TEXT ("type=%@, impl=%@, object=%@, active=%d - dummy remove failed\n"), - &this->repo_, this->name_, this->dummy_, this->dummy_->type (), - (this->dummy_->type () != 0) ? this->dummy_->type ()->object () : 0, - this->dummy_->active ())); - } - } - - // Clean up - this->dummy_ = 0; } @@ -218,6 +172,7 @@ ACE_Service_Gestalt::intrusive_remove_ref (ACE_Service_Gestalt* g) ACE_Service_Gestalt::~ACE_Service_Gestalt (void) { + if (this->svc_repo_is_owned_) delete this->repo_; @@ -266,6 +221,7 @@ ACE_Service_Gestalt::ACE_Service_Gestalt (size_t size, , repo_ (0) , static_svcs_ (0) , processed_static_svcs_ (0) + , refcnt_ (0) { (void)this->init_i (); @@ -301,6 +257,35 @@ ACE_Service_Gestalt::init_i (void) } } + if (init_svc_conf_file_queue () == -1) + return -1; + + if ( svc_conf_file_queue_->is_empty ()) + { + // Check if the default file exists before attempting to queue it + // for processing + FILE *fp = ACE_OS::fopen (ACE_DEFAULT_SVC_CONF, + ACE_TEXT ("r")); + bool skip_static_svcs = (fp == 0); + if (fp != 0) + ACE_OS::fclose (fp); + + if (!skip_static_svcs) { + // Load the default "svc.conf" entry here if there weren't + // overriding -f arguments in <parse_args>. + if (svc_conf_file_queue_->enqueue_tail + (ACE_TString (ACE_DEFAULT_SVC_CONF)) == -1) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%p\n"), + ACE_TEXT ("enqueuing ") + ACE_DEFAULT_SVC_CONF + ACE_TEXT(" file")), + -1); + } + } + } + return 0; } @@ -542,8 +527,8 @@ ACE_Service_Gestalt::initialize (const ACE_Service_Type_Factory *stf, #ifndef ACE_NLOGGING if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, looking up dynamic ") - ACE_TEXT ("service \'%s\' to initialize\n"), + ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s") + ACE_TEXT (" - looking up in the repo\n"), this->repo_, stf->name ())); #endif @@ -552,23 +537,19 @@ ACE_Service_Gestalt::initialize (const ACE_Service_Type_Factory *stf, int const retv = this->repo_->find (stf->name (), (const ACE_Service_Type **) &srp); - // If there is an active service already, it must first be removed, - // before it could be re-installed. - // IJ: This used to be the behavior, before allowing multiple - // independent service repositories. Should that still be required? + // If there is an active service already, remove it first + // before it can be re-installed. if (retv >= 0) { #ifndef ACE_NLOGGING if (ACE::debug ()) - ACE_ERROR_RETURN ((LM_WARNING, - ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,") - ACE_TEXT (" %s is already initialized.") - ACE_TEXT (" Remove before re-initializing.\n"), - this->repo_, - stf->name ()), - 0); + ACE_DEBUG ((LM_WARNING, + ACE_LIB_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,") + ACE_LIB_TEXT (" name=%s - removing a pre-existing namesake.\n"), + this->repo_, + stf->name ())); #endif - return 0; + this->repo_->remove (stf->name ()); } // If there is an inactive service by that name it may have been @@ -584,9 +565,9 @@ ACE_Service_Gestalt::initialize (const ACE_Service_Type_Factory *stf, if (retv == -2 && srp->type () == 0) ACE_ERROR_RETURN ((LM_WARNING, ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@,") - ACE_TEXT (" %s is forward-declared.") - ACE_TEXT (" Recursive initialization requests are") - ACE_TEXT (" not supported.\n"), + ACE_TEXT (" name=%s - forward-declared; ") + ACE_TEXT (" recursive initialization requests are") + ACE_TEXT (" ignored.\n"), this->repo_, stf->name ()), -1); @@ -640,19 +621,24 @@ ACE_Service_Gestalt::initialize (const ACE_Service_Type *sr, if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) SG::initialize - looking up dynamic ") - ACE_TEXT (" service %s to initialize, repo=%@\n"), - sr->name (), this->repo_)); + ACE_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s") + ACE_TEXT (" - looking up in the repo\n"), + this->repo_, + sr->name ())); ACE_Service_Type *srp = 0; if (this->repo_->find (sr->name (), (const ACE_Service_Type **) &srp) >= 0) - ACE_ERROR_RETURN ((LM_WARNING, - ACE_TEXT ("ACE (%P|%t) SG::initialize - \'%s\' ") - ACE_TEXT ("has already been installed. ") - ACE_TEXT ("Remove before reinstalling\n"), - sr->name ()), - 0); + { +#ifndef ACE_NLOGGING + ACE_DEBUG ((LM_WARNING, + ACE_LIB_TEXT ("ACE (%P|%t) SG::initialize - repo=%@, name=%s") + ACE_LIB_TEXT (" - removing a pre-existing namesake.\n"), + this->repo_, + sr->name ())); +#endif + this->repo_->remove (sr->name ()); + } return this->initialize_i (sr, parameters); @@ -677,8 +663,9 @@ ACE_Service_Gestalt::initialize_i (const ACE_Service_Type *sr, // Not using LM_ERROR here to avoid confusing the test harness if (ACE::debug ()) ACE_ERROR_RETURN ((LM_WARNING, - ACE_TEXT ("ACE (%P|%t) SG::initialize_i ") - ACE_TEXT ("failed for %s: %m\n"), + ACE_TEXT ("ACE (%P|%t) SG::initialize_i -") + ACE_TEXT (" repo=%@, name=%s - remove failed: %m\n"), + this->repo_, sr->name ()), -1); #endif @@ -691,8 +678,9 @@ ACE_Service_Gestalt::initialize_i (const ACE_Service_Type *sr, // Not using LM_ERROR here to avoid confusing the test harness if (ACE::debug ()) ACE_ERROR_RETURN ((LM_WARNING, - ACE_TEXT ("ACE (%P|%t) SG - repository insert ") - ACE_TEXT ("failed for %s: %m\n"), + ACE_TEXT ("ACE (%P|%t) SG::initialize_i -") + ACE_TEXT (" repo=%@, name=%s - insert failed: %m\n"), + this->repo_, sr->name ()), -1); #endif @@ -820,21 +808,6 @@ ACE_Service_Gestalt::process_directive_i (const ACE_Static_Svc_Descriptor &ssd, int ACE_Service_Gestalt::process_directives_i (ACE_Svc_Conf_Param *param) { - // AC 970827 Skip the heap check because yacc allocates a buffer - // here which will be reported as a memory leak for some reason. - ACE_NO_HEAP_CHECK - - // Were we called in the context of the current instance? - ACE_ASSERT (this == param->config); - - // Temporarily (for the duration of this call) make sure that *any* static - // service registrations will happen with this instance. Such registrations - // are possible as a side-effect of dynamically loading a DLL, which has - // other static services registered. Thus this instance will own both the - // DLL and those static services, which implies that their finalization - // will be performed in the correct order, i.e. prior to finalizing the DLL - ACE_Service_Config_Guard guard (this); - #ifndef ACE_NLOGGING if (ACE::debug ()) ACE_DEBUG ((LM_DEBUG, @@ -846,6 +819,22 @@ ACE_Service_Gestalt::process_directives_i (ACE_Svc_Conf_Param *param) : param->source.directive)); #endif + // AC 970827 Skip the heap check because yacc allocates a buffer + // here which will be reported as a memory leak for some reason. + ACE_NO_HEAP_CHECK + + // Were we called in the context of the current instance? + ACE_ASSERT (this == param->config); + + // Temporarily (for the duration of this call) make sure that *any* + // static service registrations will happen with this instance. Such + // registrations are possible as a side-effect of dynamically + // loading a DLL, which has other static services registered. Thus + // this instance will own both the DLL and those static services, + // which implies that their finalization will be performed in the + // correct order, i.e. prior to finalizing the DLL + ACE_Service_Config_Guard guard (this); + ::ace_yyparse (param); // This is a hack, better errors should be provided... @@ -1014,7 +1003,6 @@ ACE_Service_Gestalt::init_svc_conf_file_queue (void) ACE_NEW_RETURN (tmp, ACE_SVC_QUEUE, -1); - delete this->svc_conf_file_queue_; this->svc_conf_file_queue_ = tmp; } @@ -1147,11 +1135,14 @@ int ACE_Service_Gestalt::parse_args (int argc, ACE_TCHAR *argv[]) { ACE_TRACE ("ACE_Service_Gestalt::parse_args"); - return parse_args_i (argc, argv); + bool unused_ignore_default_svc_conf = true; + return parse_args_i (argc, argv, unused_ignore_default_svc_conf); } int -ACE_Service_Gestalt::parse_args_i (int argc, ACE_TCHAR *argv[]) +ACE_Service_Gestalt::parse_args_i (int argc, + ACE_TCHAR *argv[], + bool &ignore_default_svc_conf_file) { ACE_TRACE ("ACE_Service_Gestalt::parse_args_i"); //FUZZ: disable check_for_lack_ACE_OS @@ -1178,6 +1169,7 @@ ACE_Service_Gestalt::parse_args_i (int argc, ACE_TCHAR *argv[]) ACE_TEXT ("%p\n"), ACE_TEXT ("enqueue_tail")), -1); + ignore_default_svc_conf_file = true; break; case 'k': /* @@ -1229,21 +1221,21 @@ ACE_Service_Gestalt::process_directives (bool ignore_default_svc_conf_file) || this->svc_conf_file_queue_->is_empty ()) return 0; - ACE_TString *sptr = 0; + ACE_TString *sptr = 0; ACE_TString default_svc_conf (ACE_DEFAULT_SVC_CONF); - // Iterate through all the svc.conf files. - for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_conf_file_queue_); - iter.next (sptr) != 0; - iter.advance ()) - { + // Iterate through all the svc.conf files. + for (ACE_SVC_QUEUE_ITERATOR iter (*this->svc_conf_file_queue_); + iter.next (sptr) != 0; + iter.advance ()) + { if (*sptr == default_svc_conf && ignore_default_svc_conf_file) continue; int result = this->process_file (sptr->fast_rep ()); if (result < 0) return result; - } + } return 0; diff --git a/ACE/ace/Service_Gestalt.h b/ACE/ace/Service_Gestalt.h index 6c426d9a0d7..3c356de832f 100644 --- a/ACE/ace/Service_Gestalt.h +++ b/ACE/ace/Service_Gestalt.h @@ -320,7 +320,8 @@ protected: /** * */ - virtual int parse_args_i (int, ACE_TCHAR *argv[]); + virtual int parse_args_i (int, ACE_TCHAR *argv[], + bool& ignore_default_svc_conf_file); /** * Performs an open without parsing command-line arguments. The @@ -491,7 +492,7 @@ private: ACE_Service_Repository & repo_; size_t repo_begin_; ACE_TCHAR const * const name_; - ACE_Service_Type const * dummy_; + # if defined (ACE_MT_SAFE) && (ACE_MT_SAFE != 0) ACE_Guard< ACE_Recursive_Thread_Mutex > repo_monitor_; diff --git a/ACE/ace/Service_Gestalt.inl b/ACE/ace/Service_Gestalt.inl index 2f1c88e7db3..dd8d18dd4bf 100644 --- a/ACE/ace/Service_Gestalt.inl +++ b/ACE/ace/Service_Gestalt.inl @@ -35,17 +35,19 @@ ACE_Service_Gestalt::open (int argc, bool ignore_debug_flag) { ACE_TRACE ("ACE_Service_Gestalt::open"); + this->no_static_svcs_ = ignore_static_svcs; if (this->parse_args_i (argc, - argv) == -1) + argv, + ignore_default_svc_conf) == -1) return -1; - else - return this->open_i (argv == 0 ? 0 : argv[0], - logger_key, - ignore_static_svcs, - ignore_default_svc_conf, - ignore_debug_flag); + + return this->open_i (argv == 0 ? 0 : argv[0], + logger_key, + ignore_static_svcs, + ignore_default_svc_conf, + ignore_debug_flag); } /// Searches for a service object declaration in the local repo, only diff --git a/ACE/ace/Service_Repository.cpp b/ACE/ace/Service_Repository.cpp index f5c5b1b9096..0034cc4a3f9 100644 --- a/ACE/ace/Service_Repository.cpp +++ b/ACE/ace/Service_Repository.cpp @@ -147,27 +147,26 @@ ACE_Service_Repository::fini (void) // Do not be tempted to use the prefix decrement operator. Use // postfix decrement operator since the index is unsigned and may // wrap around the 0 - for (size_t i = this->current_size_; i-- != 0; ) - { + for (size_t i = this->current_size_; i-- != 0; ) + { // <fini> the services in reverse order. - ACE_Service_Type *s = - const_cast<ACE_Service_Type *> (this->service_vector_[i]); - + ACE_Service_Type *s = + const_cast<ACE_Service_Type *> (this->service_vector_[i]); #ifndef ACE_NLOGGING - if (ACE::debug ()) + if (ACE::debug ()) { if (s != 0) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d] (%d), ") + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d] (%d), ") ACE_TEXT ("name=%s, type=%@, object=%@, active=%d\n"), this, i, this->total_size_, s->name(), s->type (), - (s->type () != 0) ? s->type ()->object () : 0, - s->active ())); + (s->type () != 0) ? s->type ()->object () : 0, + s->active ())); else ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d] (%d) -> 0\n"), @@ -175,13 +174,12 @@ ACE_Service_Repository::fini (void) i, this->total_size_)); } - #endif - // Collect any errors. + // Collect any errors. if (s != 0) retval += s->fini (); - } + } return (retval == 0) ? 0 : -1; } @@ -198,45 +196,45 @@ ACE_Service_Repository::close (void) return 0; #ifndef ACE_NLOGGING - if(ACE::debug ()) - ACE_DEBUG ((LM_DEBUG, + if(ACE::debug ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) SR::close - repo=%@, size=%d\n"), - this, - this->current_size_)); + this, + this->current_size_)); #endif // Do not use the prefix decrement operator since the index is // unsigned and may wrap around the 0. - for (size_t i = this->current_size_; i-- != 0; ) - { + for (size_t i = this->current_size_; i-- != 0; ) + { // Delete services in reverse order. ACE_Service_Type *s = const_cast<ACE_Service_Type *> (this->service_vector_[i]); #ifndef ACE_NLOGGING - if(ACE::debug ()) + if(ACE::debug ()) { if (s == 0) ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%P|%t) SR::close - repo=%@ [%d] -> 0\n"), this, i)); - else - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("(%P|%t) SR::close - repo=%@ [%d], name=%s, object=%@\n"), - this, - i, - s->name (), - s)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("(%P|%t) SR::close - repo=%@ [%d], name=%s, object=%@\n"), + this, + i, + s->name (), + s)); } #endif - --this->current_size_; - delete s; - } + --this->current_size_; + delete s; + } - delete [] this->service_vector_; - this->service_vector_ = 0; - this->current_size_ = 0; + delete [] this->service_vector_; + this->service_vector_ = 0; + this->current_size_ = 0; return 0; } @@ -271,8 +269,8 @@ ACE_Service_Repository::find_i (const ACE_TCHAR name[], { if (this->service_vector_[i] != 0 // skip any empty slots && ACE_OS::strcmp (name, - this->service_vector_[i]->name ()) == 0) - break; + this->service_vector_[i]->name ()) == 0) + break; } if (i < this->current_size_) @@ -287,13 +285,15 @@ ACE_Service_Repository::find_i (const ACE_TCHAR name[], if (srp != 0) *srp = this->service_vector_[i]; + if (ignore_suspended && this->service_vector_[i]->active () == 0) return -2; + return 0; } - else - return -1; + + return -1; } @@ -316,27 +316,49 @@ ACE_Service_Repository::relocate_i (size_t begin, ACE_Service_Type *type = const_cast<ACE_Service_Type *> (this->service_vector_[i]); - if (type == 0) continue; // skip any gaps - ACE_SHLIB_HANDLE old_handle = type->dll ().get_handle (0); - if (old_handle == ACE_SHLIB_INVALID_HANDLE && new_handle != old_handle) + +#ifndef ACE_NLOGGING + if (ACE::debug ()) + { + if (type == 0) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d] (size=%d)") + ACE_TEXT (": skipping empty slot\n"), + this, + i, + this->total_size_)); + else + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d] (size=%d)") + ACE_TEXT (": trying name=%s, handle: %d -> %d\n"), + this, + i, + this->total_size_, + type->name (), + old_handle, + new_handle)); + } +#endif + + if (type != 0 // skip any gaps + && old_handle == ACE_SHLIB_INVALID_HANDLE + && new_handle != old_handle) { #ifndef ACE_NLOGGING - if (ACE::debug ()) - ACE_DEBUG ((LM_DEBUG, - ACE_TEXT ("ACE (%P|%t) SR::relocate - repo=%@ [%d] (size=%d)") - ACE_TEXT (": name=%s, handle: %d -> %d\n"), + if (ACE::debug ()) + ACE_DEBUG ((LM_DEBUG, + ACE_TEXT ("ACE (%P|%t) SR::relocate_i - repo=%@ [%d] (size=%d)") + ACE_TEXT (": relocating name=%s, handle: %d -> %d\n"), this, i, this->total_size_, type->name (), - old_handle, - new_handle)); -#else - ACE_UNUSED_ARG (new_handle); + old_handle, + new_handle)); #endif type->dll (adll); // ups the refcount on adll - } + } } return 0; @@ -363,9 +385,9 @@ ACE_Service_Repository::insert (const ACE_Service_Type *sr) { ACE_TRACE ("ACE_Service_Repository::insert"); - int return_value = -1; - ACE_Service_Type *s = 0; size_t i = 0; + int return_value = -1; + ACE_Service_Type const *s = 0; // Establish scope for locking while manipulating the service // storage @@ -376,42 +398,47 @@ ACE_Service_Repository::insert (const ACE_Service_Type *sr) this->lock_, -1)); - // Check to see if this is a duplicate. - for (i = 0; i < this->current_size_; i++) + return_value = find_i (sr->name (), i, &s, false); + + // Adding an entry. + if (s != 0) { - // Replacing an existing entry? - if (this->service_vector_[i] != 0 // skip any gaps - && ACE_OS::strcmp (sr->name (), this->service_vector_[i]->name ()) == 0) - { - return_value = 0; + this->service_vector_[i] = sr; + } + else + { + // New services are always added where current_size_ points, + // because if any DLL relocation needs to happen, it will be + // performed on services with indexes between some old + // current_size_ and the new current_size_ value. See + // ACE_Service_Type_Dynamic_Guard ctor and dtor for details. - // Check for self-assignment... - if (sr != this->service_vector_[i]) + if (i < this->current_size_) + i = this->current_size_; + + if (i < this->total_size_) { - s = const_cast<ACE_Service_Type *> (this->service_vector_[i]); this->service_vector_[i] = sr; + this->current_size_++; + return_value = 0; + } + else + { + return_value = -1; // no space left } - break; - } - } - - // Adding an entry. - if (i >= this->total_size_) - { - return_value = -1; // no space left - } - else if (s == 0) - { - this->service_vector_[i] = sr; - this->current_size_++; - return_value = 0; + // Since there may be "holes" left by removed services one + // could consider wrapping current_size_ modulo + // total_size_. This is going to impact + // ACE_Service_Type_Dynamic_Guard, too and is tricky. Perhaps + // a new directive, like "reload" would be better as it can + // combine the removal and insertion in an atomic step and + // avoid creating too many "holes". } } - #ifndef ACE_NLOGGING - if (ACE::debug ()) - ACE_DEBUG ((LM_DEBUG, + if (ACE::debug ()) + ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("ACE (%P|%t) SR::insert - repo=%@ [%d] (%d),") ACE_TEXT (" name=%s (%s) (type=%@, object=%@, active=%d)\n"), this, @@ -420,13 +447,13 @@ ACE_Service_Repository::insert (const ACE_Service_Type *sr) sr->name(), (return_value == 0 ? ((s==0) ? "new" : "replacing") : "failed"), sr->type (), - (sr->type () != 0) ? sr->type ()->object () : 0, - sr->active ())); + (sr->type () != 0) ? sr->type ()->object () : 0, + sr->active ())); #endif // If necessary, delete but outside the lock. (s may be 0, but // that's okay, too) - delete s; + delete s; if (return_value == -1) ACE_OS::last_error (ENOSPC); |