Beispiel #1
0
MgSecurityManager::~MgSecurityManager()
{
    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex));

    m_securityCache = NULL;
}
Beispiel #2
0
int
TAO_Stub::create_ior_info (IOP::IOR *&ior_info, CORBA::ULong &index)
{
  // We are creating the IOR info. Let us not be disturbed. So grab a
  // lock.
  ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                            guard,
                            this->profile_lock_,
                            -1));
  if (TAO_debug_level > 5)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - Stub::create_ior_info, acquired ")
                  ACE_TEXT ("profile lock this = 0x%x\n"),
                  this));
    }


  IOP::IOR *tmp_info = 0;

  if (this->forward_profiles_ != 0)
    {
      if (this->forwarded_ior_info_ == 0)
        {
          this->get_profile_ior_info (*this->forward_profiles_, tmp_info);

          this->forwarded_ior_info_ = tmp_info;
        }

      // First we look at the forward profiles to see whether the
      // profile_in_use is any of it.
      for (CORBA::ULong i = 0;
           i < this->forward_profiles_->profile_count ();
           ++i)
        {
          if (this->forward_profiles_->get_profile (i)
              == this->profile_in_use_)
            {
              ior_info = this->forwarded_ior_info_;
              index = i;
              return 0;
            }
        }
    }

  // Else we look at the base profiles
  if (this->ior_info_ == 0)
    {
      this->get_profile_ior_info (this->base_profiles_, tmp_info);

      this->ior_info_ = tmp_info;
    }


  for (CORBA::ULong ind = 0;
       ind < this->base_profiles_.profile_count ();
       ++ind)
    {
      if (this->base_profiles_.get_profile (ind) == this->profile_in_use_)
        {
          index = ind;
          ior_info = this->ior_info_;
          return 0;
        }
    }

  // Error, there was no match
  return -1;
}
Beispiel #3
0
pid_t
ACE_Process_Manager::wait (pid_t pid,
                           const ACE_Time_Value &timeout,
                           ACE_exitcode *status)
{
  ACE_TRACE ("ACE_Process_Manager::wait");

  ACE_exitcode local_stat = 0;
  if (status == 0)
    status = &local_stat;

  *status = 0;

  ssize_t idx = -1;
  ACE_Process *proc = 0;

  {
    // fake context after which the lock is released
    ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));

    if (pid != 0)
      {
        idx = this->find_proc (pid);
        if (idx == -1)
          return ACE_INVALID_PID;
        else
          proc = process_table_[idx].process_;
      }
    // release the lock.
  }
  if (proc != 0)
    pid = proc->wait (timeout, status);
  else
    {
      ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
      // Wait for any Process spawned by this Process_Manager.
#if defined (ACE_WIN32)
      HANDLE *handles = 0;

      ACE_NEW_RETURN (handles,
                      HANDLE[this->current_count_],
                      ACE_INVALID_PID);

      for (size_t i = 0;
           i < this->current_count_;
           ++i)
        handles[i] =
          process_table_[i].process_->gethandle ();

      DWORD handle_count = static_cast<DWORD> (this->current_count_);
      DWORD result = ::WaitForMultipleObjects (handle_count,
                                               handles,
                                               FALSE,
                                               timeout == ACE_Time_Value::max_time
                                               ? INFINITE
                                               : timeout.msec ());
      if (result == WAIT_FAILED)
        pid = ACE_INVALID_PID;
      else if (result == WAIT_TIMEOUT)
        pid = 0;
      else
        {
          // Green Hills produces a warning that result >=
          // WAIT_OBJECT_0 is a pointless comparison because
          // WAIT_OBJECT_0 is zero and DWORD is unsigned long, so this
          // test is skipped for Green Hills.  Same for mingw.
# if defined (ghs) || defined (__MINGW32__) || defined (_MSC_VER)
          ACE_ASSERT (result < WAIT_OBJECT_0 + this->current_count_);
# else
          ACE_ASSERT (result >= WAIT_OBJECT_0
                      && result < WAIT_OBJECT_0 + this->current_count_);
# endif

          idx = this->find_proc (handles[result - WAIT_OBJECT_0]);

          if (idx != -1)
            {
              pid = process_table_[idx].process_->getpid ();
              result = ::GetExitCodeProcess (handles[result - WAIT_OBJECT_0],
                                             status);
              if (result == 0)
                {
                  // <GetExitCodeProcess> failed!
                  this->remove_proc (idx);
                  pid = ACE_INVALID_PID;
                }
            }
          else
            {
              // uh oh...handle removed from process_table_, even though
              // we're holding a lock!
              delete [] handles;
              ACE_ERROR_RETURN ((LM_ERROR,
                                 ACE_TEXT ("Process removed")
                                 ACE_TEXT (" -- somebody's ignoring the lock!\n")),
                                -1);
            }
        }

      delete [] handles;
#else /* !defined(ACE_WIN32) */
      if (timeout == ACE_Time_Value::max_time)
        pid = ACE_OS::waitpid (-1, status, 0);
      else if (timeout == ACE_Time_Value::zero)
        pid = ACE_OS::waitpid (-1, status, WNOHANG);
      else
        {
# if defined (ACE_LACKS_UNIX_SIGNALS)
          pid = 0;
          ACE_Time_Value sleeptm (1);    // 1 msec
          if (sleeptm > timeout)         // if sleeptime > waittime
            sleeptm = timeout;
          ACE_Time_Value tmo (timeout);  // Need one we can change
          for (ACE_Countdown_Time time_left (&tmo); tmo > ACE_Time_Value::zero ; time_left.update ())
            {
              pid = ACE_OS::waitpid (-1, status, WNOHANG);
              if (pid > 0 || pid == ACE_INVALID_PID)
                break;          // Got a child or an error - all done

              // pid 0, nothing is ready yet, so wait.
              // Do a (very) short sleep (only this thread sleeps).
              ACE_OS::sleep (sleeptm);
            }
# else
          // Force generation of SIGCHLD, even though we don't want to
          // catch it - just need it to interrupt the sleep below.
          // If this object has a reactor set, assume it was given at
          // open(), and there's already a SIGCHLD action set, so no
          // action is needed here.
          ACE_Sig_Action old_action;
          if (this->reactor () == 0)
            {
              ACE_Sig_Action do_sigchld ((ACE_SignalHandler)sigchld_nop);
              do_sigchld.register_action (SIGCHLD, &old_action);
            }

          ACE_Time_Value tmo (timeout);  // Need one we can change
          for (ACE_Countdown_Time time_left (&tmo); ; time_left.update ())
            {
              pid = ACE_OS::waitpid (-1, status, WNOHANG);
#   if defined (ACE_VXWORKS) && (ACE_VXWORKS >= 0x600)
              if (pid > 0 || (pid == ACE_INVALID_PID && errno != EINTR))
#   else
                if (pid > 0 || pid == ACE_INVALID_PID)
#   endif
                  break;          // Got a child or an error - all done

              // pid 0, nothing is ready yet, so wait.
              // Do a sleep (only this thread sleeps) til something
              // happens. This relies on SIGCHLD interrupting the sleep.
              // If SIGCHLD isn't delivered, we'll need to do something
              // with sigaction to force it.
              if (-1 == ACE_OS::sleep (tmo) && errno == EINTR)
                continue;
              // Timed out
              pid = 0;
              break;
            }

          // Restore the previous SIGCHLD action if it was changed.
          if (this->reactor () == 0)
            old_action.register_action (SIGCHLD);
# endif /* !ACE_LACKS_UNIX_SIGNALS */
        }
#endif /* !defined (ACE_WIN32) */
    }

  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));
  if (pid != ACE_INVALID_PID && pid != 0)
    {
      //we always need to get our id, because we could have been moved in the table meanwhile
      idx = this->find_proc (pid);
      if (idx == -1)
        {
          // oops, reaped an unmanaged process!
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) oops, reaped unmanaged %d\n"),
                      pid));
          return pid;
        }
      else
        proc = process_table_[idx].process_;
      if (proc != 0)
        ACE_ASSERT (pid == proc->getpid ());

      this->notify_proc_handler (idx,
                                 *status);
      this->remove (pid);
    }

  return pid;
}
/// Insert the ACE_Service_Type SR into the repository.  Note that
/// services may be inserted either resumed or suspended. Using same
/// name as in an existing service causes the delete () to be called
/// for the old one, i.e. make sure @code sr is allocated on the heap!
int
ACE_Service_Repository::insert (const ACE_Service_Type *sr)
{
  ACE_TRACE ("ACE_Service_Repository::insert");

  size_t i = 0;
  int return_value = -1;
  ACE_Service_Type const *s = 0;

  // Establish scope for locking while manipulating the service
  // storage
  {
    // @TODO: Do we need a recursive mutex here?
    ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex,
                              ace_mon,
                              this->lock_,
                              -1));

    return_value = find_i (sr->name (), i, &s, false);

    // Adding an entry.
    if (s != 0)
      {
        this->service_array_[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.

        if (i < this->service_array_.size ())
          i = this->service_array_.size ();

        this->service_array_[i] = sr;
        return_value = 0;
      }
  }
#ifndef ACE_NLOGGING
  if (ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE (%P|%t) SR::insert - repo=%@ [%d],")
                ACE_TEXT (" name=%s (%C) (type=%@, object=%@, active=%d)\n"),
                this,
                i,
                sr->name(),
                (return_value == 0 ? ((s==0) ? "new" : "replacing") : "failed"),
                sr->type (),
                (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;

  if (return_value == -1)
    ACE_OS::last_error (ENOSPC);

  return return_value;
}
Beispiel #5
0
int
ACE_DLL_Handle::open (const ACE_TCHAR *dll_name,
                      int open_mode,
                      ACE_SHLIB_HANDLE handle)
{
  ACE_TRACE ("ACE_DLL_Handle::open");
  ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));

  if (this->dll_name_)
    {
      // Once dll_name_ has been set, it can't be changed..
      if (ACE_OS::strcmp (this->dll_name_, dll_name) != 0)
        {
          if (ACE::debug ())
            ACE_ERROR ((LM_ERROR,
                        ACE_TEXT ("(%P|%t) DLL_Handle::open: error, ")
                        ACE_TEXT ("tried to reopen %s with name %s\n"),
                        this->dll_name_,
                        dll_name));

          return -1;
        }
    }
  else
    this->dll_name_ = ACE::strnew (dll_name);

  if (!this->open_called_)
    this->open_called_ = 1;

  // If it hasn't been loaded yet, go ahead and do that now.
  if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
    {
      if (handle)
        this->handle_ = handle;
      else
        {
          /*
          ** Get the set of names to try loading. We need to do this to
          ** properly support the ability for a user to specify a simple,
          ** unadorned name (for example, "ACE") that will work across
          ** platforms. We apply platform specifics to get a name that will
          ** work (e.g. libACE, ACEd.dll, ACE.dll, etc.) We rely on the
          ** underlying dlopen() implementation to "Do The Right Thing" in
          ** terms of using relative paths, LD_LIBRARY_PATH, system security
          ** rules, etc. except when ACE_MUST_HELP_DLOPEN_SEARCH_PATH is set.
          ** If it is set, then ACE::ldfind() scans the configured path
          ** looking for a match on the name and prefix/suffix applications.
          ** NOTE: having ACE scan for a file and then pass a fully-qualified
          ** pathname to dlopen() is a potential security hole; therefore,
          ** do not use ACE_MUST_HELP_DLOPEN_SEARCH_PATH unless necessary
          ** and only after considering the risks.
          */
          ACE_Array<ACE_TString> dll_names;
          dll_names.max_size (10);    // Decent guess to avoid realloc later

#if defined (ACE_MUST_HELP_DLOPEN_SEARCH_PATH)
          // Find out where the library is
          ACE_TCHAR dll_pathname[MAXPATHLEN + 1];

          // Transform the pathname into the appropriate dynamic link library
          // by searching the ACE_LD_SEARCH_PATH.
          ACE::ldfind (dll_name,
                       dll_pathname,
                       (sizeof dll_pathname / sizeof (ACE_TCHAR)));
          ACE_TString dll_str (dll_pathname);
          dll_names.size (1);
          dll_names.set (dll_str, 0);
#else
          this->get_dll_names (dll_name, dll_names);
#endif

          ACE_Array_Iterator<ACE_TString> name_iter (dll_names);
          ACE_TString *name = 0;
          while (name_iter.next (name))
            {
              // The ACE_SHLIB_HANDLE object is obtained.
              this->handle_ = ACE_OS::dlopen (name->c_str (),
                                              open_mode);

              if (ACE::debug ())
                {
                  ACE_DEBUG ((LM_DEBUG,
                              ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                              ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
                              name->c_str (),
                              open_mode,
                              ((this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                               ? ACE_TEXT ("succeeded")
                               : ACE_TEXT ("failed")),
                              this->error()->c_str()));
                }

              if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)   // Good one?
                break;

              // If errno is ENOENT we just skip over this one,
              // anything else - like an undefined symbol, for
              // instance must be flagged here or the next error will
              // mask it.
              // @TODO: If we've found our DLL _and_ it's
              // broken, should we continue at all?
              if ((errno != 0) && (errno != ENOENT) && ACE::debug ())
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                            ACE_TEXT ("(\'%s\') failed, errno=")
                            ACE_TEXT ("%d: %s\n"),
                            name->c_str (),
                            errno,
                            this->error ()->c_str ()));

#if defined (AIX)
              // AIX often puts the shared library file (most often named
              // shr.o) inside an archive library. If this is an archive
              // library name, then try appending [shr.o] and retry.
              if (ACE_TString::npos != name->strstr (ACE_TEXT (".a")))
                {
                  ACE_TCHAR aix_pathname[MAXPATHLEN + 1];
                  ACE_OS::strncpy (aix_pathname,
                                   name->c_str (),
                                   name->length ());
                  aix_pathname[name->length ()] = '\0';
                  ACE_OS::strcat (aix_pathname, ACE_TEXT ("(shr.o)"));
                  open_mode |= RTLD_MEMBER;

                  if (ACE::debug ())
                    {
                      ACE_DEBUG ((LM_DEBUG,
                                  ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                                  ACE_TEXT ("(\"%s\", 0x%x) -> %s: %s\n"),
                                  aix_pathname,
                                  open_mode,
                                  ACE_TEXT ((this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                                                ? "succeeded"
                                                : "failed"),
                                  this->error()->c_str()));
                    }

                  this->handle_ = ACE_OS::dlopen (aix_pathname, open_mode);
                  if (this->handle_ != ACE_SHLIB_INVALID_HANDLE)
                    break;

                  // If errno is ENOENT we just skip over this one, anything
                  // else - like an undefined symbol, for instance
                  // must be flagged here or the next error will mask it.
                  //
                  // @TODO: If we've found our DLL _and_ it's broken,
                  // should we continue at all?
                  if (ACE::debug () && (errno != 0) && (errno != ENOENT))
                    ACE_ERROR ((LM_ERROR,
                                ACE_TEXT ("ACE (%P|%t) DLL_Handle::open ")
                                ACE_TEXT ("(\'%s\') failed, errno=")
                                ACE_TEXT ("%d: %s\n"),
                                name->c_str (),
                                errno,
                                this->error ()->c_str ()));

                }
#endif /* AIX */

              name_iter.advance ();
            }

          if (this->handle_ == ACE_SHLIB_INVALID_HANDLE)
            {
              if (ACE::debug ())
                ACE_ERROR ((LM_ERROR,
                            ACE_TEXT ("ACE (%P|%t) DLL_Handle::open (\"%s\"): ")
                            ACE_TEXT ("Invalid handle error: %s\n"),
                            this->dll_name_,
                            this->error ()->c_str ()));

              return -1;
            }
        }
    }

  ++this->refcount_;

  if (ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE (%P|%t) DLL_Handle::open - %s (%d), refcount=%d\n"),
                this->dll_name_,
                this->handle_,
                this->refcount_));
  return 0;
}
// Insert the ACE_Service_Type SR into the repository.  Note that
// services may be inserted either resumed or suspended. Using same
// name as in an existing service causes the delete () to be called
// for the old one, i.e. make sure @code sr is allocated on the heap!
int
ACE_Service_Repository::insert (const ACE_Service_Type *sr)
{
    ACE_TRACE ("ACE_Service_Repository::insert");

    size_t i = 0;
    int return_value = -1;
    ACE_Service_Type const *s = 0;

    // Establish scope for locking while manipulating the service
    // storage
    {
        // @TODO: Do we need a recursive mutex here?
        ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex,
                                  ace_mon,
                                  this->lock_,
                                  -1));

        return_value = find_i (sr->name (), i, &s, false);

        // Adding an entry.
        if (s != 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.

            if (i < this->current_size_)
                i = this->current_size_;

            if (i < this->total_size_)
            {
                this->service_vector_[i] = sr;
                this->current_size_++;
                return_value = 0;
            }
            else
            {
                return_value = -1; // no space left
            }

            // 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,
                    ACE_TEXT ("ACE (%P|%t) SR::insert - repo=%@ [%d] (%d),")
                    ACE_TEXT (" name=%s (%s) (type=%@, object=%@, active=%d)\n"),
                    this,
                    i,
                    this->total_size_,
                    sr->name(),
                    (return_value == 0 ? ((s==0) ? "new" : "replacing") : "failed"),
                    sr->type (),
                    (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;

    if (return_value == -1)
        ACE_OS::last_error (ENOSPC);

    return return_value;
}
Beispiel #7
0
int
ACE_SSL_Context::set_mode (int mode)
{
    ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex,
                              ace_ssl_mon,
                              *ACE_Static_Object_Lock::instance (),
                              -1));

    if (this->context_ != 0)
        return -1;

#if OPENSSL_VERSION_NUMBER >= 0x10000002
    const SSL_METHOD *method = 0;
#else
    SSL_METHOD *method = 0;
#endif

    switch (mode)
    {
    case ACE_SSL_Context::SSLv2_client:
        method = ::SSLv2_client_method ();
        break;
    case ACE_SSL_Context::SSLv2_server:
        method = ::SSLv2_server_method ();
        break;
    case ACE_SSL_Context::SSLv2:
        method = ::SSLv2_method ();
        break;
    case ACE_SSL_Context::SSLv3_client:
        method = ::SSLv3_client_method ();
        break;
    case ACE_SSL_Context::SSLv3_server:
        method = ::SSLv3_server_method ();
        break;
    case ACE_SSL_Context::SSLv3:
        method = ::SSLv3_method ();
        break;
    case ACE_SSL_Context::SSLv23_client:
        method = ::SSLv23_client_method ();
        break;
    case ACE_SSL_Context::SSLv23_server:
        method = ::SSLv23_server_method ();
        break;
    case ACE_SSL_Context::SSLv23:
        method = ::SSLv23_method ();
        break;
    case ACE_SSL_Context::TLSv1_client:
        method = ::TLSv1_client_method ();
        break;
    case ACE_SSL_Context::TLSv1_server:
        method = ::TLSv1_server_method ();
        break;
    case ACE_SSL_Context::TLSv1:
        method = ::TLSv1_method ();
        break;
    default:
        method = ::SSLv3_method ();
        break;
    }

    this->context_ = ::SSL_CTX_new (method);
    if (this->context_ == 0)
        return -1;

    this->mode_ = mode;

    // Load the trusted certificate authority (default) certificate
    // locations. But do not return -1 on error, doing so confuses CTX
    // allocation (severe error) with the less important loading of CA
    // certificate location error.  If it is important for your
    // application then call ACE_SSL_Context::have_trusted_ca(),
    // immediately following this call to set_mode().
    (void) this->load_trusted_ca ();

    return 0;
}
int
ACE_SOCK_Dgram_Mcast::join (const ACE_INET_Addr &mcast_addr,
                            int reuse_addr,
                            const ACE_TCHAR *net_if)
{
  ACE_TRACE ("ACE_SOCK_Dgram_Mcast::join");
  ACE_INET_Addr subscribe_addr = mcast_addr;

  // If port# is 0, insert bound port# if it is set. (To satisfy lower-level
  // port# validation.)
  u_short def_port_number = this->send_addr_.get_port_number ();
  if (subscribe_addr.get_port_number () == 0
      && def_port_number != 0)
    {
      subscribe_addr.set_port_number (def_port_number);
    }

  // Check for port# different than bound port#.
  u_short sub_port_number = mcast_addr.get_port_number ();
  if (sub_port_number != 0
      && def_port_number != 0
      && sub_port_number != def_port_number)
    {
      ACE_ERROR ((LM_ERROR,
                  ACE_LIB_TEXT ("Subscribed port# (%u) different than bound ")
                  ACE_LIB_TEXT ("port# (%u).\n"),
                  (u_int) sub_port_number,
                  (u_int) def_port_number));
      errno = ENXIO;
      return -1;
    }

  // If bind_addr_opt_ is enabled, check for address different than
  // bound address.
#if defined (__linux__) && defined (ACE_HAS_IPV6)
  if (ACE_BIT_ENABLED (this->opts_, OPT_BINDADDR_YES)
      && ((this->send_addr_.get_type () == AF_INET
          && this->send_addr_.get_ip_address () != INADDR_ANY
          && this->send_addr_.get_ip_address () != mcast_addr.get_ip_address ())
      || (this->send_addr_.get_type () == AF_INET6 &&
          ACE_OS::memcmp
          (&((sockaddr_in6 *) this->send_addr_.get_addr ())->sin6_addr,
           &in6addr_any, sizeof (in6_addr)) != 0 &&
          ACE_OS::memcmp
          (&((sockaddr_in6 *) this->send_addr_.get_addr ())->sin6_addr,
           &((sockaddr_in6 *) mcast_addr.get_addr ())->sin6_addr,
           sizeof (in6_addr)) != 0)))
#else
  if (ACE_BIT_ENABLED (this->opts_, OPT_BINDADDR_YES)
      && this->send_addr_.get_ip_address () != INADDR_ANY
      && this->send_addr_.get_ip_address () != mcast_addr.get_ip_address ())
#endif /* __linux__ && ACE_HAS_IPV6 */
    {
      ACE_TCHAR sub_addr_string[MAXNAMELEN + 1];
      ACE_TCHAR bound_addr_string[MAXNAMELEN + 1];
      ACE_SDM_helpers::addr_to_string (mcast_addr, sub_addr_string,
                                       sizeof sub_addr_string, 1);
      ACE_SDM_helpers::addr_to_string (this->send_addr_, bound_addr_string,
                                       sizeof bound_addr_string, 1);
      ACE_ERROR ((LM_ERROR,
                  ACE_LIB_TEXT ("Subscribed address (%s) different than ")
                  ACE_LIB_TEXT ("bound address (%s).\n"),
                  sub_addr_string,
                  bound_addr_string));
      errno = ENXIO;
      return -1;
    }

  // Attempt subscription.
  int  result = this->subscribe_i (subscribe_addr, reuse_addr, net_if);

#if defined (ACE_SOCK_DGRAM_MCAST_DUMPABLE)
  if (result == 0)
    {
      // Add this addr/iface info to the list of subscriptions.
      // (Assumes this is unique addr/iface combo - most systems don't allow
      // re-sub to same addr/iface.)
      ip_mreq  *pmreq = new ip_mreq;
      // (should not fail)
      if (this->make_multicast_ifaddr (pmreq, subscribe_addr, net_if) != -1)
        {
          ACE_MT (ACE_GUARD_RETURN (ACE_SDM_LOCK, guard,
                                    this->subscription_list_lock_, -1));
          this->subscription_list_.insert_tail (pmreq);
          return 0;
        }
      // this still isn't really right. If ACE_GUARD_RETURN fails, we leak.
      // Need to add one of Chris' fancy ace auto pointers (bound?).
      delete pmreq;
    }
#endif /* ACE_SOCK_DGRAM_MCAST_DUMPABLE */

  return result >= 0 ? 0 : result;
}
template <class TYPE, class FUNCTOR, class ACE_LOCK> void
ACE_Timer_Queue_T<TYPE, FUNCTOR, ACE_LOCK>::return_node (ACE_Timer_Node_T<TYPE> *node)
{
  ACE_MT (ACE_GUARD (ACE_LOCK, ace_mon, this->mutex_));
  this->free_node (node);
}
Beispiel #10
0
/// <summary>
/// Pops a server connection from the top of the stack.  If
/// a connection is not available, one is created.  Stale connections
/// are dropped and not reused.
/// </summary>
/// <param name="connProp">
/// Connection to add
/// <param>
MgServerConnection* MgServerConnectionStack::Pop()
{
    // Wait up to 30 seconds for a connection to free up
    ACE_Time_Value delay(30);
    ACE_Time_Value future = ACE_OS::gettimeofday() + delay;
    int acquired = m_activeConnections.acquire(future);
    if (acquired == -1)
    {
        throw new MgConnectionFailedException(L"MgServerConnectionStack.Pop",
            __LINE__, __WFILE__, NULL, L"", NULL);
    }

    ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex, NULL));

    MgServerConnection* conn = NULL;

    ACE_Time_Value now = ACE_High_Res_Timer::gettimeofday();

    // Pull a connection from the front of the queue and make sure it's valid.
    conn = NULL;
    while (NULL == conn && m_queue->size() > 0)
    {
        // Grab a connection from the queue
        {
            conn = m_queue->front();
            if (NULL != conn) m_queue->pop_front();
        }

        // And see if it is still valid
        if (NULL != conn)
        {
            if (conn->IsStale(&now))
            {
                SAFE_RELEASE(conn);
                conn = NULL;
            }
            else
            {
                // Check to see if stream is still alive... It better be!
                Ptr<MgStream> stream = conn->GetStream();
                if (stream != NULL)
                {
                    Ptr<MgStreamHelper> helper = stream->GetStreamHelper();
                    if (helper->IsConnected() == false)
                    {
                        stream = NULL;
                        SAFE_RELEASE(conn);
                        conn = NULL;
                    }
                }
                else
                {
                    SAFE_RELEASE(conn);
                    conn = NULL;
                }
            }
        }
    }

    if (NULL != conn)
    {
        InUse(conn);
    }

    // Extra reference count from InUse will be eating by external code
    return conn;
}
Beispiel #11
0
void MgServerConnectionStack::InUse(MgServerConnection* connection)
{
    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex));
    SAFE_ADDREF(connection);
    m_inUse->push_back(connection);
}
Beispiel #12
0
void KSG_Task_Queue::insert_task(task_type task)
{
	ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex,mon,_task_list_mutex));
	_list_of_tasks.push_front(task);
}
Beispiel #13
0
///////////////////////////////////////////////////////////////////////////
// KSG_Task_Queue_Pool 
int KSG_Task_Queue_Pool::Queue_List_Cond::wait(ACE_Time_Value *time_out)
{
	int ret;
	ACE_MT(ret = _mutex.acquire(time_out));
	return ret;
}
Beispiel #14
0
void MgSecurityManager::RefreshSecurityCache(MgSecurityCache* securityCache)
{
    ACE_MT(ACE_GUARD(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex));

    sm_securityCache = securityCache;
}
void
ACE_SOCK_Dgram_Mcast::dump (void) const
{
#if defined (ACE_HAS_DUMP)
  ACE_TRACE ("ACE_SOCK_Dgram_Mcast::dump");

  ACE_DEBUG ((LM_DEBUG, ACE_BEGIN_DUMP, this));

# if defined (ACE_SOCK_DGRAM_MCAST_DUMPABLE)
  ACE_TCHAR addr_string[MAXNAMELEN + 1];

  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("\nOptions: bindaddr=%s, nulliface=%s\n"),
              ACE_BIT_ENABLED (this->opts_, OPT_BINDADDR_YES) ?
                ACE_TEXT ("<Bound>") : ACE_TEXT ("<Not Bound>"),
              ACE_BIT_ENABLED (this->opts_, OPT_NULLIFACE_ALL) ?
                ACE_TEXT ("<All Ifaces>") : ACE_TEXT ("<Default Iface>")));

  // Show default send addr, port#, and interface.
  ACE_SDM_helpers::addr_to_string (this->send_addr_, addr_string,
                                   sizeof addr_string, 0);
  ACE_DEBUG ((LM_DEBUG,
              ACE_TEXT ("Send addr=%s iface=%s\n"),
              addr_string,
              this->send_net_if_ ? this->send_net_if_
                                 : ACE_TEXT ("<default>")));

  // Show list of subscribed addresses.
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Subscription list:\n")));

  ACE_MT (ACE_GUARD (ACE_SDM_LOCK, guard, this->subscription_list_lock_));
  subscription_list_iter_t  iter (this->subscription_list_);
  for ( ; !iter.done (); iter.advance ())
    {
      ACE_TCHAR iface_string[MAXNAMELEN + 1];
      ip_mreq *pm = iter.next ();

      // Get subscribed address (w/out port# info - not relevant).
      ACE_INET_Addr ip_addr (static_cast<u_short> (0),
                             ACE_NTOHL (pm->IMR_MULTIADDR.s_addr));
      ACE_SDM_helpers::addr_to_string (ip_addr, addr_string,
                                       sizeof addr_string, 1);

      // Get interface address/specification.
      ACE_INET_Addr if_addr (static_cast<u_short> (0),
                             ACE_NTOHL (pm->imr_interface.s_addr));
      ACE_SDM_helpers::addr_to_string (if_addr, iface_string,
                                       sizeof iface_string, 1);
      if (ACE_OS::strcmp (iface_string, ACE_TEXT ("0.0.0.0")) == 0)
        // Receives on system default iface. (Note that null_iface_opt_
        // option processing has already occurred.)
        ACE_OS::strcpy (iface_string, ACE_TEXT ("<default>"));

      // Dump info.
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("\taddr=%s iface=%s\n"),
                  addr_string,
                  iface_string));
    }
# endif /* ACE_SOCK_DGRAM_MCAST_DUMPABLE */
  ACE_DEBUG ((LM_DEBUG, ACE_END_DUMP));
#endif /* ACE_HAS_DUMP */
}
Beispiel #16
0
int KSG_Task_Queue::insert_task(task_type task)
{
	ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex,mon,_task_list_mutex,-1));
	_list_of_tasks.push_front(task);
	return 0;
}
Beispiel #17
0
int
ACE_UPIPE_Connector::connect (ACE_UPIPE_Stream &new_stream,
                              const ACE_UPIPE_Addr &addr,
                              ACE_Time_Value *timeout,
                              const ACE_Addr & /* local_sap */,
                              int /* reuse_addr */,
                              int flags,
                              int perms)
{
  ACE_TRACE ("ACE_UPIPE_Connector::connect");
  ACE_ASSERT (new_stream.get_handle () == ACE_INVALID_HANDLE);

  ACE_HANDLE handle = ACE::handle_timed_open (timeout,
                                              addr.get_path_name (),
                                              flags, perms);

  if (handle == ACE_INVALID_HANDLE)
    return -1;
#if !defined (ACE_WIN32)
  else if (ACE_OS::isastream (handle) != 1)
    return -1;
#endif
  else // We're connected!
    {
      ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, new_stream.lock_, -1));

      ACE_UPIPE_Stream *ustream = &new_stream;

      new_stream.set_handle (handle);
      new_stream.remote_addr_ = addr; // class copy.
      new_stream.reference_count_++;

      // Now send the address of our ACE_UPIPE_Stream over this pipe
      // to our corresponding ACE_UPIPE_Acceptor, so he may link the
      // two streams.
      ssize_t result = ACE_OS::write (handle,
                                      (const char *) &ustream,
                                      sizeof ustream);
      if (result == -1)
        ACELIB_ERROR ((LM_ERROR,
                    ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
                    ACE_TEXT ("write to pipe failed")));

      // Wait for confirmation of stream linking.
      ACE_Message_Block *mb_p = 0;

      // Our part is done, wait for server to confirm connection.
      result = new_stream.recv (mb_p, 0);

      // Do *not* coalesce the following two checks for result == -1.
      // They perform different checks and cannot be merged.
      if (result == -1)
          ACELIB_ERROR ((LM_ERROR,
                      ACE_TEXT ("ACE_UPIPE_Connector %p\n"),
                      ACE_TEXT ("no confirmation from server")));
      else
        // Close down the new_stream at this point in order to
        // conserve handles.  Note that we don't need the SPIPE
        // connection anymore since we're linked via the Message_Queue
        // now.
        new_stream.ACE_SPIPE::close ();
      return static_cast<int> (result);
    }
}
Beispiel #18
0
int KSG_Task_Queue::push_preemptive_task(task_type task)
{
	ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex,mon,_task_list_mutex,-1));
	_list_of_preempt_tasks.push_back(task);
	return 0;
}
Beispiel #19
0
int
ACE_Service_Config::open_i (const ACE_TCHAR program_name[],
                            const ACE_TCHAR *logger_key,
                            bool ,
                            bool ,
                            bool )
{
  ACE_TRACE ("ACE_Service_Config::open_i");
  ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->lock_, -1));

  ACE_Log_Msg *log_msg = ACE_LOG_MSG;

  if(ACE::debug ())
    ACE_DEBUG ((LM_DEBUG,
                ACE_TEXT ("ACE (%P|%t) SC::open_i - this=%@, opened=%d\n"),
                this, this->is_opened_));

  // Guard against reentrant processing.
  if(this->is_opened_)
    return 0;

  this->is_opened_ = true;

  // 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

  // Become a daemon before doing anything else.
  if(ACE_Service_Config::be_a_daemon_)
    ACE::daemonize ();

  // Write process id to file.
  if(this->pid_file_name_ != 0)
    {
      FILE* pidf = ACE_OS::fopen (this->pid_file_name_,
                                  ACE_TEXT("w"));

      if(pidf != 0)
        {
          ACE_OS::fprintf (pidf,
                           "%ld\n",
                           static_cast<long> (ACE_OS::getpid()));
          ACE_OS::fclose (pidf);
        }
    }

  u_long flags = log_msg->flags ();

  // Only use STDERR if the caller hasn't already set the flags.
  if(flags == 0)
    flags = (u_long) ACE_Log_Msg::STDERR;

  const ACE_TCHAR *key = logger_key;

  if(key == 0 || ACE_OS::strcmp (key, ACE_DEFAULT_LOGGER_KEY) == 0)
    {
      // Only use the static <logger_key_> if the caller doesn't
      // override it in the parameter list or if the key supplied is
      // equal to the default static logger key.
      key = ACE_Service_Config::current()->logger_key_;
    }
  else
    {
      ACE_SET_BITS (flags, ACE_Log_Msg::LOGGER);
    }

  if(log_msg->open (program_name,
                     flags,
                     key) == -1)
    return -1;

  if(ACE::debug ())
    ACE_DEBUG ((LM_STARTUP,
                ACE_TEXT ("starting up daemon %n\n")));

  // Initialize the Service Repository (this will still work if
  // user forgets to define an object of type ACE_Service_Config).
  ACE_Service_Repository::instance (ACE_Service_Gestalt::MAX_SERVICES);

  // Initialize the ACE_Reactor (the ACE_Reactor should be the
  // same size as the ACE_Service_Repository).
  ACE_Reactor::instance ();

  // There's no point in dealing with this on NT since it doesn't
  // really support signals very well...
#if !defined (ACE_LACKS_UNIX_SIGNALS)
  // Only attempt to register a signal handler for positive
  // signal numbers.
  if(ACE_Service_Config::signum_ > 0)
    {
      ACE_Sig_Set ss;
      ss.sig_add (ACE_Service_Config::signum_);
      if((ACE_Reactor::instance () != 0) &&
          (ACE_Reactor::instance ()->register_handler
           (ss, ACE_Service_Config::signal_handler_) == -1))
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("can't register signal handler\n")));
    }
#endif /* ACE_LACKS_UNIX_SIGNALS */

  return 0;
}
Beispiel #20
0
size_t KSG_Task_Queue::count_of_preemptive_tasks()
{
	ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex,mon,_task_list_mutex,0));
	return _list_of_preempt_tasks.size();
}
int
ACE_Service_Repository::fini (void)
{
  ACE_TRACE ("ACE_Service_Repository::fini");
  ACE_MT (ACE_GUARD_RETURN (ACE_Recursive_Thread_Mutex, ace_mon, this->lock_, -1));

  int retval = 0;
  // 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
  //
  // debug output for empty service entries
#ifndef ACE_NLOGGING
  if (ACE::debug ())
  {
    for (size_t i = this->service_array_.size (); i-- != 0;)
    {
      ACE_Service_Type *s =
        const_cast<ACE_Service_Type *> (this->service_array_[i]);
      if (s == 0)
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d] -> 0\n"),
                    this,
                    i));
    }
  }
#endif
  //
  // Remove all the Service_Object and Stream instances
  //
  for (size_t i = this->service_array_.size (); i-- != 0;)
  {
    // <fini> the services in reverse order.
    ACE_Service_Type *s =
      const_cast<ACE_Service_Type *> (this->service_array_[i]);

    if (s != 0 &&
        s->type () != 0 &&
        (s->type ()->service_type () != ACE_Service_Type::MODULE))
    {
#ifndef ACE_NLOGGING
      if (ACE::debug ())
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d], ")
                    ACE_TEXT ("name=%s, type=%@, object=%@, active=%d\n"),
                    this,
                    i,
                    s->name (),
                    s->type (),
                    (s->type () != 0) ? s->type ()->object () : 0,
                    s->active ()));
      }
#endif

      // Collect any errors.
      retval += s->fini ();
    }
  }
  //
  // Remove all the Module instances
  //
  for (size_t i = this->service_array_.size (); i-- != 0;)
  {
    // <fini> the services in reverse order.
    ACE_Service_Type *s =
      const_cast<ACE_Service_Type *> (this->service_array_[i]);

    if (s != 0 &&
        s->type () != 0 &&
        (s->type ()->service_type () == ACE_Service_Type::MODULE))
    {
#ifndef ACE_NLOGGING
      if (ACE::debug ())
      {
        ACE_DEBUG ((LM_DEBUG,
                    ACE_TEXT ("ACE (%P|%t) SR::fini, repo=%@ [%d], ")
                    ACE_TEXT ("name=%s, type=%@, object=%@, active=%d\n"),
                    this,
                    i,
                    s->name (),
                    s->type (),
                    (s->type () != 0) ? s->type ()->object () : 0,
                    s->active ()));
      }
#endif
      // Collect any errors.
      retval += s->fini ();
    }
  }
  return (retval == 0) ? 0 : -1;
}
Beispiel #22
0
static void *
worker (void *c)
{
  int count = *(static_cast<int*> (c));

  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) worker, iterations = %d\n"), count));

  ACE_thread_key_t key = ACE_OS::NULL_key;
  int *ip = 0;

  // Make one key that will be available when the thread exits so that
  // we'll have something to cleanup!

  if (ACE_Thread::keycreate (&key, cleanup) == -1)
    {
      ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p (no keys available)\n"),
                  ACE_TEXT ("ACE_Thread::keycreate")));
      return (void *) -1;
    }

  ACE_NEW_RETURN (ip, int, 0);

  if (ACE_Thread::setspecific (key, (void *) ip) == -1)
    ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                ACE_TEXT ("ACE_Thread::setspecific")));

  for (int i = 0; i < count; i++)
    {
      if (ACE_Thread::keycreate (&key, cleanup) == -1)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p (no more keys)\n"),
                      ACE_TEXT ("ACE_Thread::keycreate")));
          break;
        }

      ACE_NEW_RETURN (ip, int, 0);

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) in worker at location 1, ")
                            ACE_TEXT ("key = %d, ip = %x\n"),
                  key, ip));

      // Needed to work around (possibly broken?) strict aliasing warning in GCC.
      void *v_ip (reinterpret_cast <void *> (ip));

      if (ACE_Thread::setspecific (key, v_ip) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      if (ACE_Thread::getspecific (key, &v_ip) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::getspecific")));

      if (ACE_Thread::setspecific (key, (void *) 0) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      // See comment in cleanup () above.
      delete ip;

#if defined (ACE_HAS_TSS_EMULATION)
      if (ACE_Thread::keyfree (key) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::keyfree")));
#endif /* ACE_HAS_TSS_EMULATION */

      // Cause an error.
      ACE_OS::read (ACE_INVALID_HANDLE, 0, 0);

      // The following two lines set the thread-specific state.
      (*tss_error)->error (errno);
      (*tss_error)->line (__LINE__);

      // This sets the static state (note how C++ makes it easy to do
      // both).
      (*tss_error)->flags (count);

      {
        // Use the guard to serialize access
        ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, output_lock, 0));
        ACE_ASSERT ((*tss_error)->flags () == ITERATIONS);
      }

      // Demonstrate use of ACE_TSS_Type_Adapter to wrap built-in
      // types when used with ACE_TSS.  See DESCRIPTION of template
      // class ACE_TSS_Type_Adapter in ace/Synch_T.h for what this
      // should look like.  Unfortunately, some compilers have trouble
      // with the implicit type conversions.  Others have problems with
      // the *explicit* type conversions.
#if !defined (ACE_HAS_BROKEN_EXPLICIT_TYPECAST_OPERATOR_INVOCATION)
      (*u)->operator u_int & () = 37;
      if ((*u)->operator u_int () != 37)
        {
          // Use the guard to serialize access to errors.
          ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, output_lock,
                                    0));
          ACE_DEBUG ((LM_ERROR,
                      ACE_TEXT ("use of ACE_TSS_Type_Adapter failed, value ")
                      ACE_TEXT ("is %u, it should be 37!\n"),
                      (*u)->operator u_int ()));
          ++errors;
        }
#endif /* !defined (ACE_HAS_BROKEN_EXPLICIT_TYPECAST_OPERATOR_INVOCATION) */

#if defined (ACE_HAS_TSS_EMULATION)
      key = ACE_OS::NULL_key;

      if (ACE_Thread::keycreate (&key, cleanup) == -1)
        {
          ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p (no more keys)\n"),
                      ACE_TEXT ("ACE_Thread::keycreate")));
          break;
        }

      ACE_NEW_RETURN (ip, int, 0);

      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("(%t) in worker at location 2, ")
                            ACE_TEXT ("key = %d, ip = %x\n"),
                  key, ip));

      // Needed to work around (possibly broken?) strict aliasing warning in GCC.
      void *v_ip2 (reinterpret_cast <void *> (ip));

      if (ACE_Thread::setspecific (key, v_ip2) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      if (ACE_Thread::getspecific (key, &v_ip2) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::getspecific")));

      if (ACE_Thread::setspecific (key, (void *) 0) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::setspecific")));

      // See comment in cleanup () above.
      delete ip;

      // ACE_HAS_TSS_EMULATION is turned on, then it should work.
#  if defined (ACE_HAS_TSS_EMULATION)
      if (ACE_Thread::keyfree (key) == -1)
        ACE_ERROR ((LM_ERROR, ACE_TEXT ("(%t) %p\n"),
                    ACE_TEXT ("ACE_Thread::keyfree")));
#  endif /* defined (ACE_HAS_TSS_EMULATION) */
#endif /* ACE_HAS_TSS_EMULATION */
    }
  return 0;
}
Beispiel #23
0
int
ACE_DLL_Handle::close (int unload)
{
  ACE_TRACE ("ACE_DLL_Handle::close");

  int retval = 0;
  ACE_SHLIB_HANDLE h = ACE_SHLIB_INVALID_HANDLE;

  // Only hold the lock until it comes time to dlclose() the DLL. Closing
  // the DLL can cause further shutdowns as DLLs and their dependents are
  // unloaded.
  {
    ACE_MT (ACE_GUARD_RETURN (ACE_Thread_Mutex, ace_mon, this->lock_, 0));

    // Since we don't actually unload the dll as soon as the refcount
    // reaches zero, we need to make sure we don't decrement it below
    // zero.
    if (this->refcount_ > 0)
      --this->refcount_;
    else
      this->refcount_ = 0;

    if (ACE::debug ())
      ACE_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("ACE (%P|%t) DLL_Handle::close - ")
                  ACE_TEXT ("%s (handle=%d, refcount=%d)\n"),
                  this->dll_name_,
                  this->handle_,
                  this->refcount_));

    if (this->refcount_ == 0 &&
        this->handle_ != ACE_SHLIB_INVALID_HANDLE &&
        unload == 1)
      {
        if (ACE::debug ())
          ACE_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("ACE (%P|%t) DLL_Handle::close: ")
                      ACE_TEXT ("Unloading %s (handle=%d)\n"),
                      this->dll_name_,
                      this->handle_));

        // First remove any associated Framework Components.
        ACE_Framework_Repository *frPtr= ACE_Framework_Repository::instance ();
        if (frPtr)
          {
            frPtr->remove_dll_components (this->dll_name_);
          }

        h = this->handle_;
        this->handle_ = ACE_SHLIB_INVALID_HANDLE;
      }
  } // Release lock_ here

  if (h != ACE_SHLIB_INVALID_HANDLE)
    {
      retval = ACE_OS::dlclose (h);

      if (retval != 0 && ACE::debug ())
        ACE_ERROR ((LM_ERROR,
                    ACE_TEXT ("ACE (%P|%t) DLL_Handle::close - ")
                    ACE_TEXT ("Failed with: \"%s\".\n"),
                    this->error ()->c_str ()));
    }

  return retval;
}
Beispiel #24
0
///////////////////////////////////////////////////////////////////////////////
/// \brief
/// Return unmanaged data mappings.
///
MgPropertyCollection* MgUnmanagedDataManager::GetUnmanagedDataMappings()
{
    ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, m_mutex, NULL));

    return SAFE_ADDREF(m_unmanagedDataMappings.p);
}
Beispiel #25
0
int HNDR_Device_Base::get_last_poll_record(KSGDeviceNode* node)
{
	Poll_Status_Ptr_t status = find_status_ptr(node);
	ACE_MT(ACE_GUARD_RETURN(ACE_Thread_Mutex,mon,_mutex,0));
	return status->_last_record;
}
Beispiel #26
0
template <class TYPE, class FUNCTOR, class ACE_LOCK, class BUCKET> int
ACE_Timer_Hash_T<TYPE, FUNCTOR, ACE_LOCK, BUCKET>::expire (const ACE_Time_Value &cur_time)
{
  ACE_TRACE ("ACE_Timer_Hash_T::expire");
  ACE_MT (ACE_GUARD_RETURN (ACE_LOCK, ace_mon, this->mutex_, -1));

  int number_of_timers_expired = 0;

  ACE_Timer_Node_T<TYPE> *expired;

  // Go through the table and expire anything that can be expired

  for (size_t i = 0;
       i < this->table_size_;
       i++)
    {
      while (!this->table_[i]->is_empty () 
             && this->table_[i]->earliest_time () <= cur_time)
        {
          expired = this->table_[i]->get_first ();
          TYPE type = expired->get_type ();
          const void *act = expired->get_act ();
          int reclaim = 1;

          // Check if this is an interval timer.
          if (expired->get_interval () > ACE_Time_Value::zero)
            {
              // Make sure that we skip past values that have already
              // "expired".
              do
                expired->set_timer_value (expired->get_timer_value () 
                                          + expired->get_interval ());
              while (expired->get_timer_value () <= cur_time);

              // Since this is an interval timer, we need to
              // reschedule it.
              this->reschedule (expired);
              reclaim = 0;
            }

          // Now remove the timer from the original table... if
          // it's a simple, non-recurring timer, it's got to be
          // removed anyway. If it was rescheduled, it's been
          // scheduled into the correct table (regardless of whether
          // it's the same one or not) already.
          this->table_[i]->cancel (expired->get_timer_id ());

          Hash_Token *h = ACE_reinterpret_cast (Hash_Token *, 
                                                ACE_const_cast (void *,
                                                                act));
          // Call the functor.
          this->upcall (type,
                        h->act_,
                        cur_time);
          if (reclaim)
            {
              --this->size_;
              delete h;
            }
          number_of_timers_expired++;
        }
    }

  return number_of_timers_expired;
}
Beispiel #27
0
CORBA::Boolean
TAO_Stub::marshal (TAO_OutputCDR &cdr)
{
  // do as many outside of locked else-branch as posssible

  // STRING, a type ID hint
  if ((cdr << this->type_id.in()) == 0)
    return 0;

  if ( ! this->forward_profiles_perm_)
    {
      const TAO_MProfile& mprofile = this->base_profiles_;

      CORBA::ULong const profile_count = mprofile.profile_count ();
      if ((cdr << profile_count) == 0)
        return 0;

    // @@ The MProfile should be locked during this iteration, is there
    // anyway to achieve that?
    for (CORBA::ULong i = 0; i < profile_count; ++i)
      {
        const TAO_Profile* p = mprofile.get_profile (i);
        if (p->encode (cdr) == 0)
          return 0;
      }
    }
  else
    {
      ACE_MT (ACE_GUARD_RETURN (TAO_SYNCH_MUTEX,
                                guard,
                                this->profile_lock_,
                                0));
  if (TAO_debug_level > 5)
    {
      TAOLIB_DEBUG ((LM_DEBUG,
                  ACE_TEXT ("TAO (%P|%t) - Stub::marshal, acquired ")
                  ACE_TEXT ("profile lock this = 0x%x\n"),
                  this));
    }


      ACE_ASSERT(this->forward_profiles_ !=0);

      // paranoid - in case of FT the basic_profiles_ would do, too,
      // but might be dated
      const TAO_MProfile& mprofile =
          this->forward_profiles_perm_
        ? *(this->forward_profiles_perm_)
        : this->base_profiles_;

      CORBA::ULong const profile_count = mprofile.profile_count ();
      if ((cdr << profile_count) == 0)
           return 0;

      // @@ The MProfile should be locked during this iteration, is there
      // anyway to achieve that?
      for (CORBA::ULong i = 0; i < profile_count; ++i)
        {
          const TAO_Profile* p = mprofile.get_profile (i);
          if (p->encode (cdr) == 0)
            return 0;
        }

      // release ACE_Lock
    }

  return (CORBA::Boolean) cdr.good_bit ();
}
Beispiel #28
0
// ************************************************************
//  Asynch_Operation interface
//    open
// ************************************************************
int
ACE_SSL_Asynch_Stream::open (ACE_Handler & handler,
                             ACE_HANDLE handle,
                             const void * completion_key,
                             ACE_Proactor * proactor)
{
  ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX, ace_mon, this->mutex_, -1));

  if (this->flags_ & SF_STREAM_OPEN)
    ACELIB_ERROR_RETURN
      ((LM_ERROR,
        ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
        ACE_TEXT ("- already opened")),
       -1);

  if (this->ssl_ == 0)
    ACELIB_ERROR_RETURN
      ((LM_ERROR,
        ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
        ACE_TEXT ("- SSL structure is absent")),
       -1);

  if (handle == ACE_INVALID_HANDLE)
    ACELIB_ERROR_RETURN
      ((LM_ERROR,
        ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
        ACE_TEXT ("- invalid handle")),
       -1);


  // Get a proactor for/from the user.
  this->proactor_    = this->get_proactor (proactor, handler);
  this->ext_handler_ = & handler;
  this->handle (handle);

  // Open internal input stream
  if (this->bio_istream_.open (*this,   // real callbacks to this
                               handle,
                               completion_key,
                               this->proactor_) != 0)
    return -1;

  // Open internal output stream
  if (this->bio_ostream_.open (*this,  // real callbacks to this
                               handle,
                               completion_key,
                               this->proactor_) != 0)
    return -1;

  this->bio_ = ACE_SSL_make_BIO (this);

  if (this->bio_ == 0)
    ACELIB_ERROR_RETURN
      ((LM_ERROR,
        ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
        ACE_TEXT ("- cannot allocate new BIO structure")),
       -1);

  ::SSL_set_bio (this->ssl_ , this->bio_ , this->bio_);

  switch (this->type_)
    {
    case ST_CLIENT:
      ::SSL_set_connect_state (this->ssl_);
      break;

    case ST_SERVER:
      ::SSL_set_accept_state (this->ssl_);
      break;

    default:
      ACELIB_ERROR_RETURN
        ((LM_ERROR,
          ACE_TEXT ("(%P|%t) ACE_SSL_Asynch_Stream::open() %p\n"),
          ACE_TEXT ("- invalid stream type")),
         -1);
    }

  this->flags_ |= SF_STREAM_OPEN;

  this->do_SSL_state_machine ();

  return 0;
}
Beispiel #29
0
    bool ConnectionCache::claim_connection(const ConnectionKey& key,
                                           connection_type*& connection,
                                           const factory_type& connection_factory,
                                           bool wait)
      {
        INET_TRACE ("ConnectionCache::claim_connection");

        while (1)
          {
            bool create_connection = false;
            ConnectionCacheValue::State state = ConnectionCacheValue::CST_NONE;
            do
              {
                ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
                                          guard_,
                                          this->lock_,
                                          false));

                if (this->claim_existing_connection (key, connection, state))
                  {
                    INET_DEBUG (9, (LM_INFO, DLINFO ACE_TEXT ("%P|%t) ConnectionCache::claim_connection - ")
                                             ACE_TEXT ("successfully claimed existing connection\n")));
                    return true;
                  }

                if ((state == ConnectionCacheValue::CST_BUSY ||
                        state == ConnectionCacheValue::CST_INIT) && !wait)
                  return false;

                if (state == ConnectionCacheValue::CST_CLOSED ||
                        state == ConnectionCacheValue::CST_NONE)
                  {
                    if (!this->set_connection (key, ConnectionCacheValue ()))
                      {
                        INET_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT ("ConnectionCache::claim_connection - ")
                                                  ACE_TEXT ("failed to initialize connection entry")));
                        return false;
                      }

                    create_connection = true;
                  }
                else
                  {
                    INET_DEBUG (9, (LM_INFO, DLINFO ACE_TEXT ("ConnectionCache::claim_connection - ")
                                             ACE_TEXT ("waiting for connection to become available\n")));
                    // wait for connection to become ready/free
                    if (this->condition_.wait () != 0)
                      {
                        INET_ERROR (1, (LM_ERROR, DLINFO ACE_TEXT ("(%P|%t) ConnectionCache::claim_connection - ")
                                                  ACE_TEXT ("error waiting for connection condition (%p)\n")));
                        return false;
                      }
                    INET_DEBUG (9, (LM_INFO, DLINFO ACE_TEXT ("ConnectionCache::claim_connection - ")
                                             ACE_TEXT ("awoken and retrying to claim connection\n")));
                  }
              }
            while (0);

            if (create_connection)
              {
                connection = connection_factory.create_connection (key);
                if (connection)
                  {
                    INET_DEBUG (9, (LM_INFO, DLINFO ACE_TEXT ("ConnectionCache::claim_connection - ")
                                             ACE_TEXT ("successfully created new connection\n")));

                    ACE_MT (ACE_GUARD_RETURN (ACE_SYNCH_MUTEX,
                                              guard_,
                                              this->lock_,
                                              false));

                    ConnectionCacheValue cacheval (connection);
                    cacheval.state (ConnectionCacheValue::CST_BUSY);
                    return this->set_connection (key, cacheval);
                  }
                else
                  return false;
              }
          }
      }
Beispiel #30
0
MgStringCollection* MgSecurityManager::Authenticate(
    MgUserInformation* userInformation, MgStringCollection* requiredRoles,
    bool returnAssignedRoles)
{
    ACE_MT(ACE_GUARD_RETURN(ACE_Recursive_Thread_Mutex, ace_mon, sm_mutex, NULL));

    Ptr<MgStringCollection> assignedRoles;

    MG_TRY()

    if (NULL == userInformation)
    {
        throw new MgAuthenticationFailedException(
            L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
    }

    STRING user = userInformation->GetUserName();
    STRING session = userInformation->GetMgSessionId();

    if (session.empty())
    {
        if (user.empty())
        {
            throw new MgAuthenticationFailedException(
                L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
        }

        const MgUserInfo* userInfo = sm_securityCache->GetUserInfo(user);
        assert(NULL != userInfo);

        if (userInformation->GetPassword() != userInfo->GetPassword())
        {
            throw new MgAuthenticationFailedException(
                L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
        }
    }
    else
    {
        user = MgSessionManager::UpdateLastAccessedTime(session);
    }

    if (NULL != requiredRoles &&
            !sm_securityCache->IsUserInRoles(user, requiredRoles))
    {
        MG_LOG_AUTHENTICATION_ENTRY(MgResources::UnauthorizedAccess.c_str());

        throw new MgUnauthorizedAccessException(
            L"MgSecurityManager.Authenticate", __LINE__, __WFILE__, NULL, L"", NULL);
    }

    if (returnAssignedRoles)
    {
        assignedRoles = sm_securityCache->EnumerateRoles(user);
    }

    // Commented out logging of successful authentication because it creates lots of entries in the Authentication.log
//    MG_LOG_AUTHENTICATION_ENTRY(MgResources::Success.c_str());

    MG_CATCH(L"MgSecurityManager.Authenticate")

    if (mgException != NULL)
    {
        MG_LOG_AUTHENTICATION_ENTRY(MgResources::Failure.c_str());
    }

    MG_THROW()

    return assignedRoles.Detach();
}