Example #1
0
static void convertEnvList (const Locator_XMLHandler::EnvList& in,
                            ImplementationRepository::EnvironmentList& out)
{
  CORBA::ULong const sz = static_cast<CORBA::ULong> (in.size ());
  out.length (sz);
  for (CORBA::ULong i = 0; i < sz; ++i)
    {
      out[i].name = ACE_TEXT_ALWAYS_CHAR (in[i].name.c_str ());
      out[i].value = ACE_TEXT_ALWAYS_CHAR (in[i].value.c_str ());
    }
}
Example #2
0
void
ImR_Activator_i::start_server(const char* name,
                              const char* cmdline,
                              const char* dir,
                              const ImplementationRepository::EnvironmentList & env)
{
  bool unique = false;
  if (ACE_OS::strlen (name) > unique_prefix_len &&
      ACE_OS::strncmp (name, unique_prefix, unique_prefix_len) == 0)
    {
      unique = true;
      name += unique_prefix_len;
    }

  if (debug_ > 1)
    ORBSVCS_DEBUG((LM_DEBUG,
                   "ImR Activator: Starting %C <%C>...\n",
                   (unique ? "unique server" : "server"), name));

  if (unique && this->still_running_i (name))
    {
      if (debug_ > 1)
        ORBSVCS_DEBUG((LM_DEBUG,
                       "ImR Activator: Unique instance already running\n"));
      return;
    }

  ACE_TString cmdline_tstr(ACE_TEXT_CHAR_TO_TCHAR(cmdline));
  size_t cmdline_buf_len = cmdline_tstr.length();
  if (debug_ > 1)
    ORBSVCS_DEBUG((LM_DEBUG,
            "\tcommand line : len=%d <%s>\n\tdirectory : <%C>\n",
            cmdline_buf_len, cmdline_tstr.c_str(), dir)  );

  ACE_Process_Options proc_opts (
                        1,
                        cmdline_buf_len + 1,
                        this->env_buf_len_, this->max_env_vars_);
  proc_opts.command_line (ACE_TEXT_CHAR_TO_TCHAR(cmdline));
  proc_opts.working_directory (dir);
  // Win32 does not support the CLOSE_ON_EXEC semantics for sockets
  // the way unix does, so in order to avoid having the child process
  // hold the listen socket open, we force the child to inherit no
  // handles. This includes stdin, stdout, logs, etc.
  proc_opts.handle_inheritance (0);

  // We always enable the unicode environmet buffer on Windows.  This works
  // around a 32kb environment buffer limitation.  This must come before any of
  // the setenv() calls, since the first of those will copy the current
  // process's environment.
  proc_opts.enable_unicode_environment ();

  proc_opts.setenv (ACE_TEXT("TAO_USE_IMR"), "1");
  if (!CORBA::is_nil (this->locator_.in ()))
    {
      CORBA::String_var ior = orb_->object_to_string (locator_.in ());
      proc_opts.setenv (ACE_TEXT("ImplRepoServiceIOR"), ior.in());
    }

  for (CORBA::ULong i = 0; i < env.length (); ++i)
    {
      proc_opts.setenv (ACE_TEXT_CHAR_TO_TCHAR(env[i].name.in ()), env[i].value.in ());
    }

  pid_t pid = this->process_mgr_.spawn (proc_opts, this);
  if (pid == ACE_INVALID_PID)
    {
      ORBSVCS_ERROR ((LM_ERROR,
        "ImR Activator: Cannot start server <%C> using <%s>\n", name, cmdline));

      throw ImplementationRepository::CannotActivate(
        CORBA::string_dup (
          "Process Creation Failed"));
      return;
    }
  else
    {
      if (debug_ > 1)
        {
          ORBSVCS_DEBUG((LM_DEBUG,
            "ImR Activator: register death handler for process %d\n", pid));
        }
      this->process_map_.rebind (pid, name);
      if (unique)
        {
          this->server_list_.insert (name);
        }
      if (!CORBA::is_nil (this->locator_.in ()))
        {
          if (this->notify_imr_)
            {
              if (debug_ > 1)
                {
                  ORBSVCS_DEBUG ((LM_DEBUG,
                                  ACE_TEXT ("(%P|%t) ImR Activator: Notifying ImR that ")
                                  ACE_TEXT ("<%C> has started.\n"),
                                  name));
                }
              this->locator_->spawn_pid (name, pid);
            }
        }
    }

  if (debug_ > 0)
    {
      ORBSVCS_DEBUG ((LM_DEBUG,
                      ACE_TEXT ("(%P|%t) ImR Activator: Successfully started <%C>, pid=%d\n"),
                      name, pid));
    }
}