Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

ACE_Process_Options Class Reference

Process Options. More...

#include <Process.h>

Collaboration diagram for ACE_Process_Options:

Collaboration graph
[legend]
List of all members.

Public Types

enum  { DEFAULT_COMMAND_LINE_BUF_LEN = 1024, NO_EXEC = 0 }

Public Methods

 ACE_Process_Options (int inherit_environment=1, int command_line_buf_len=DEFAULT_COMMAND_LINE_BUF_LEN, int env_buf_len=ENVIRONMENT_BUFFER, int max_env_args=MAX_ENVIRONMENT_ARGS)
 ~ACE_Process_Options (void)
 Destructor. More...

int set_handles (ACE_HANDLE std_in, ACE_HANDLE std_out=ACE_INVALID_HANDLE, ACE_HANDLE std_err=ACE_INVALID_HANDLE)
void release_handles (void)
 Felease the standard handles previously set with set_handles;. More...

int setenv (const ACE_TCHAR *format,...)
 <format> must be of the form "VARIABLE=VALUE". There can not be any spaces between VARIABLE and the equal sign. More...

int setenv (const ACE_TCHAR *variable_name, const ACE_TCHAR *format,...)
int setenv (ACE_TCHAR *envp[])
 Same as above with argv format. <envp> must be null terminated. More...

void working_directory (const char *wd)
 Set the working directory for the process. strlen of <wd> must be <= MAXPATHLEN. More...

void working_directory (const wchar_t *wd)
 wchar_t version of working_directory. More...

int command_line (const ACE_TCHAR *format,...)
int command_line (const ACE_ANTI_TCHAR *format,...)
 Anti-TChar version of command_line (). More...

int command_line (const ACE_TCHAR *const argv[])
 Same as above in argv format. <argv> must be null terminated. More...

void process_name (const ACE_TCHAR *name)
const ACE_TCHARprocess_name (void)
 Return the process_name. If the <process_name(name)> set method is not called, this method will return argv[0]. More...

u_long creation_flags (void) const
 Get the creation flags. More...

void creation_flags (u_long)
 Set the creation flags. More...

ACE_TCHARworking_directory (void)
 Current working directory. Returns "" if nothing has been set. More...

ACE_TCHARcommand_line_buf (int *max_len=0)
 Buffer of command-line options. Returns a pointer to a buffer that contains the list of command line options. Prior to a call to command_line_argv(), this is a single string of space separated arguments independent of which form of command_line() was used to create it. After a call to command_line_argv(), this is a list of strings each terminated by '\0'. [Note: spawn() will call command_line_argv().] The total length of all these strings is the same as the single string in the prior case and can be obtained by providing max_len.
  • max_len, if non-zero, provides a location into which the total length of the command line buffer is returned.
More...


ACE_TCHAR *const * command_line_argv (void)
ACE_TCHARenv_buf (void)
pid_t getgroup (void) const
 Get the process group. On UNIX, these methods are used by the <ACE_Process_Manager> to manage groups of processes. More...

pid_t setgroup (pid_t pgrp)
 Set the process group. On UNIX, these methods are used by the <ACE_Process_Manager> to manage groups of processes. More...

int handle_inheritence (void)
 Default is TRUE. Allows disabling of handle inheritence. More...

void handle_inheritence (int)
int pass_handle (ACE_HANDLE)
 Cause the specified handle to be passed to a child process when it runs a new program image. More...

int dup_handles (ACE_Handle_Set &set) const
 Get a copy of the handles the ACE_Process_Options duplicated for the spawned process. More...

int passed_handles (ACE_Handle_Set &set) const
 Get a copy of the handles passed to the spawned process. This will be the set of handles previously passed to More...

void avoid_zombies (int)
 Set value for avoid_zombies (has no real effect except on *nix). More...

int avoid_zombies (void)
 Get current value for avoid_zombies. More...

ACE_TEXT_STARTUPINFO * startup_info (void)
 Used for setting and getting. More...

LPSECURITY_ATTRIBUTES get_process_attributes (void) const
 Get the process_attributes. Returns NULL if set_process_attributes has not been set. More...

LPSECURITY_ATTRIBUTES set_process_attributes (void)
 If this is called, a non-null process attributes is sent to CreateProcess. More...

LPSECURITY_ATTRIBUTES get_thread_attributes (void) const
 Get the thread_attributes. Returns NULL if set_thread_attributes has not been set. More...

LPSECURITY_ATTRIBUTES set_thread_attributes (void)
 If this is called, a non-null thread attributes is sent to CreateProcess. More...


Protected Types

enum  { MAX_COMMAND_LINE_OPTIONS = 128, ENVIRONMENT_BUFFER = 16 * 1024, MAX_ENVIRONMENT_ARGS = 512 }

Protected Methods

int setenv_i (ACE_TCHAR *assignment, size_t len)
 Add <assignment> to environment_buf_ and adjust environment_argv_. <len> is the strlen of <assignment>. More...

void inherit_environment (void)
 Helper function to grab win32 environment and stick it in environment_buf_ using this->setenv_i. More...


Protected Attributes

int inherit_environment_
 Whether the child process inherits the current process environment. More...

u_long creation_flags_
 Default 0. More...

int avoid_zombies_
 Avoid zombies for spawned processes. More...

int environment_inherited_
 Ensures once only call to inherit environment. More...

ACE_TEXT_STARTUPINFO startup_info_
BOOL handle_inheritence_
 Default TRUE. More...

LPSECURITY_ATTRIBUTES process_attributes_
 Pointer to security_buf1_. More...

LPSECURITY_ATTRIBUTES thread_attributes_
 Pointer to security_buf2_. More...

SECURITY_ATTRIBUTES security_buf1_
 Data for process_attributes_. More...

SECURITY_ATTRIBUTES security_buf2_
 Data for thread_attributes_. More...

int set_handles_called_
 Is 1 if stdhandles was called. More...

size_t environment_buf_index_
 Pointer into environment_buf_. This should point to the next free spot. More...

int environment_argv_index_
 Pointer to environment_argv_. More...

ACE_TCHARenvironment_buf_
 Pointer to buffer of the environment settings. More...

size_t environment_buf_len_
 Size of the environment buffer. Configurable. More...

ACE_TCHAR ** environment_argv_
 Pointers into environment_buf_. More...

int max_environment_args_
 Maximum number of environment variables. Configurable. More...

int max_environ_argv_index_
 Maximum index of environment_argv_ buffer. More...

ACE_TCHAR working_directory_ [MAXPATHLEN+1]
 The current working directory. More...

int command_line_argv_calculated_
 Ensures command_line_argv is only calculated once. More...

ACE_TCHARcommand_line_buf_
 Pointer to buffer of command-line arguments. E.g., "-f foo -b bar". More...

int command_line_buf_len_
 Max length of command_line_buf_. More...

ACE_TCHARcommand_line_argv_ [MAX_COMMAND_LINE_OPTIONS]
 Argv-style command-line arguments. More...

pid_t process_group_
 Process-group on Unix; unused on Win32. More...

ACE_Handle_Set handles_passed_
 Set of handles that were passed in pass_handle (). More...

ACE_Handle_Set dup_handles_
 Results of duplicating handles passed in pass_handle (). More...

ACE_TCHAR process_name_ [MAXPATHLEN+1]
 Pathname for the process. Relative path or absolute path or just the program name. More...


Detailed Description

Process Options.

This class controls the options passed to <CreateProcess> (or <fork> and <exec>). Notice that on Windows CE, creating a process merely means instantiating a new process. You can't set the handles (since there's no stdin, stdout and stderr,) specify process/thread options, set environment,... So, basically, this class only set the command line and nothing else. Notice that on UNIX platforms, if the <setenv> is used, the <spawn> is using the <execve> system call. It means that the <command_line> should include a full path to the program file (<execve> does not search the PATH). If <setenv> is not used then, the <spawn> is using the <execvp> which searches for the program file in the PATH variable.

Definition at line 43 of file Process.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
DEFAULT_COMMAND_LINE_BUF_LEN 
NO_EXEC 

Definition at line 46 of file Process.h.

00047   {
00048     DEFAULT_COMMAND_LINE_BUF_LEN = 1024,
00049     // UNIX process creation flags.
00050 #if defined (ACE_WIN32)
00051     NO_EXEC = 0
00052 #else
00053     NO_EXEC = 1
00054 #endif /* ACE_WIN32 */
00055   };

anonymous enum [protected]
 

Enumeration values:
MAX_COMMAND_LINE_OPTIONS 
ENVIRONMENT_BUFFER 
MAX_ENVIRONMENT_ARGS 

Definition at line 62 of file Process.h.

00063   {
00064     MAX_COMMAND_LINE_OPTIONS = 128,
00065     ENVIRONMENT_BUFFER = 16 * 1024, // 16K
00066     MAX_ENVIRONMENT_ARGS = 512 //
00067   };


Constructor & Destructor Documentation

ACE_Process_Options::ACE_Process_Options int    inherit_environment = 1,
int    command_line_buf_len = DEFAULT_COMMAND_LINE_BUF_LEN,
int    env_buf_len = ENVIRONMENT_BUFFER,
int    max_env_args = MAX_ENVIRONMENT_ARGS
 

If <inherit_environment> == 1, the new process will inherit the environment of the current process. <command_line_buf_len> is the max strlen for command-line arguments.

Definition at line 470 of file Process.cpp.

References ACE_INVALID_PID, ACE_NEW, ACE_TCHAR, command_line_buf_, environment_argv_, environment_buf_, ACE_OS_String::memset, process_name_, startup_info_, uid_t, and working_directory_.

00474   :
00475 #if !defined (ACE_HAS_WINCE)
00476     inherit_environment_ (ie),
00477 #endif /* ACE_HAS_WINCE */
00478     creation_flags_ (0),
00479     avoid_zombies_ (0),
00480 #if !defined (ACE_HAS_WINCE)
00481 #if defined (ACE_WIN32)
00482     environment_inherited_ (0),
00483     handle_inheritence_ (TRUE),
00484     process_attributes_ (0),
00485     thread_attributes_ (0),
00486 #else /* ACE_WIN32 */
00487     stdin_ (ACE_INVALID_HANDLE),
00488     stdout_ (ACE_INVALID_HANDLE),
00489     stderr_ (ACE_INVALID_HANDLE),
00490     ruid_ ((uid_t) -1),
00491     euid_ ((uid_t) -1),
00492     rgid_ ((uid_t) -1),
00493     egid_ ((uid_t) -1),
00494 #endif /* ACE_WIN32 */
00495     set_handles_called_ (0),
00496     environment_buf_index_ (0),
00497     environment_argv_index_ (0),
00498     environment_buf_ (0),
00499     environment_buf_len_ (ebl),
00500     max_environment_args_ (mea),
00501     max_environ_argv_index_ (mea - 1),
00502 #endif /* !ACE_HAS_WINCE */
00503     command_line_argv_calculated_ (0),
00504     command_line_buf_ (0),
00505     command_line_buf_len_ (cobl),
00506     process_group_ (ACE_INVALID_PID)
00507 {
00508   ACE_NEW (command_line_buf_,
00509            ACE_TCHAR[cobl]);
00510   command_line_buf_[0] = '\0';
00511 
00512 #if !defined (ACE_HAS_WINCE)
00513   working_directory_[0] = '\0';
00514   ACE_NEW (environment_buf_,
00515            ACE_TCHAR[ebl]);
00516   ACE_NEW (environment_argv_,
00517            ACE_TCHAR *[mea]);
00518   environment_buf_[0] = '\0';
00519   environment_argv_[0] = 0;
00520   process_name_[0] = '\0';
00521 #if defined (ACE_WIN32)
00522   ACE_OS::memset ((void *) &this->startup_info_,
00523                   0,
00524                   sizeof this->startup_info_);
00525   this->startup_info_.cb = sizeof this->startup_info_;
00526 #endif /* ACE_WIN32 */
00527 #endif /* !ACE_HAS_WINCE */
00528 }

ACE_Process_Options::~ACE_Process_Options void   
 

Destructor.

Definition at line 766 of file Process.cpp.

References command_line_buf_, environment_argv_, environment_buf_, and release_handles.

00767 {
00768 #if !defined (ACE_HAS_WINCE)
00769   release_handles();
00770   delete [] environment_buf_;
00771   delete [] environment_argv_;
00772 #endif /* !ACE_HAS_WINCE */
00773   delete [] command_line_buf_;
00774 }


Member Function Documentation

ACE_INLINE int ACE_Process_Options::avoid_zombies void   
 

Get current value for avoid_zombies.

Definition at line 144 of file Process.i.

References avoid_zombies_.

00145 {
00146   return avoid_zombies_;
00147 }

ACE_INLINE void ACE_Process_Options::avoid_zombies int   
 

Set value for avoid_zombies (has no real effect except on *nix).

Definition at line 149 of file Process.i.

References avoid_zombies, and avoid_zombies_.

Referenced by avoid_zombies, and ACE_Process::spawn.

00150 {
00151   avoid_zombies_ = avoid_zombies;
00152 }

int ACE_Process_Options::command_line const ACE_TCHAR *const    argv[]
 

Same as above in argv format. <argv> must be null terminated.

Definition at line 777 of file Process.cpp.

References ACE_LIB_TEXT, ACE_TCHAR, command_line_argv_calculated_, command_line_buf_, and ACE_OS_String::strcat.

00778 {
00779   // @@ Factor out the code between this
00780   int i = 0;
00781 
00782   if (argv[i])
00783     {
00784       ACE_OS::strcat (command_line_buf_, argv[i]);
00785       while (argv[++i])
00786         {
00787           ACE_OS::strcat (command_line_buf_,
00788                           ACE_LIB_TEXT (" "));
00789           ACE_OS::strcat (command_line_buf_,
00790                           argv[i]);
00791         }
00792     }
00793 
00794   command_line_argv_calculated_ = 0;
00795   return 0; // Success.
00796 }

int ACE_Process_Options::command_line const ACE_ANTI_TCHAR   format,
...   
 

Anti-TChar version of command_line ().

Note:
Not available on Windows CE because it doesn't have a char version of vsprintf.

Definition at line 823 of file Process.cpp.

References ACE_ANTI_TCHAR, ACE_NEW_RETURN, ACE_TEXT_ANTI_TO_TCHAR, command_line_argv_calculated_, ACE_OS_String::strcpy, and ACE_OS::vsprintf.

00824 {
00825   ACE_ANTI_TCHAR *anti_clb;
00826   ACE_NEW_RETURN (anti_clb,
00827                   ACE_ANTI_TCHAR[this->command_line_buf_len_],
00828                   -1);
00829 
00830   // Store all ... args in argp.
00831   va_list argp;
00832   va_start (argp, format);
00833 
00834   // sprintf the format and args into command_line_buf_.
00835   ACE_OS::vsprintf (anti_clb,
00836                     format,
00837                     argp);
00838 
00839   // Useless macro.
00840   va_end (argp);
00841 
00842   ACE_OS::strcpy (this->command_line_buf_,
00843                   ACE_TEXT_ANTI_TO_TCHAR (anti_clb));
00844 
00845   delete [] anti_clb;
00846 
00847   command_line_argv_calculated_ = 0;
00848   return 0;
00849 }

int ACE_Process_Options::command_line const ACE_TCHAR   format,
...   
 

Set the command-line arguments. <format> can use any printf formats. The first token in <format> should be the path to the application. This can either be a full path, relative path, or just an executable name. If an executable name is used, we rely on the platform's support for searching paths. Since we need a path to run a process, this method *must* be called! Returns 0 on success, -1 on failure.

Definition at line 799 of file Process.cpp.

References ACE_TCHAR, command_line_argv_calculated_, command_line_buf_, and ACE_OS::vsprintf.

00800 {
00801   // Store all ... args in argp.
00802   va_list argp;
00803   va_start (argp, format);
00804 
00805   // sprintf the format and args into command_line_buf__.
00806   ACE_OS::vsprintf (command_line_buf_,
00807                     format,
00808                     argp);
00809 
00810   // Useless macro.
00811   va_end (argp);
00812 
00813   command_line_argv_calculated_ = 0;
00814   return 0;
00815 }

ACE_TCHAR *const * ACE_Process_Options::command_line_argv void   
 

argv-style command-line options. Parses and modifies the string created from <command_line_>. All spaces not in quotes ("" or '') are replaced with null (\0) bytes. An argv array is built and returned with each entry pointing to the start of null-terminated string. Returns { 0 } if nothing has been set.

Definition at line 866 of file Process.cpp.

References command_line_argv_, command_line_argv_calculated_, command_line_buf_, ACE_Tokenizer::delimiter_replace, MAX_COMMAND_LINE_OPTIONS, ACE_Tokenizer::next, and ACE_Tokenizer::preserve_designators.

Referenced by ACE_Process::spawn.

00867 {
00868   if (command_line_argv_calculated_ == 0)
00869     {
00870       command_line_argv_calculated_ = 1;
00871 
00872       // This tokenizer will replace all spaces with end-of-string
00873       // characters and will preserve text between "" and '' pairs.
00874       ACE_Tokenizer parser (command_line_buf_);
00875       parser.delimiter_replace (' ', '\0');
00876       parser.preserve_designators ('\"', '\"'); // "
00877       parser.preserve_designators ('\'', '\'');
00878 
00879       int x = 0;
00880       do
00881         command_line_argv_[x] = parser.next ();
00882       while (command_line_argv_[x] != 0
00883              // substract one for the ending zero.
00884              && ++x < MAX_COMMAND_LINE_OPTIONS - 1);
00885 
00886       command_line_argv_[x] = 0;
00887     }
00888 
00889   return command_line_argv_;
00890 }

ACE_INLINE ACE_TCHAR * ACE_Process_Options::command_line_buf int *    max_len = 0
 

Buffer of command-line options. Returns a pointer to a buffer that contains the list of command line options. Prior to a call to command_line_argv(), this is a single string of space separated arguments independent of which form of command_line() was used to create it. After a call to command_line_argv(), this is a list of strings each terminated by '\0'. [Note: spawn() will call command_line_argv().] The total length of all these strings is the same as the single string in the prior case and can be obtained by providing max_len.

  • max_len, if non-zero, provides a location into which the total length of the command line buffer is returned.

Definition at line 312 of file Process.i.

References command_line_buf_, and command_line_buf_len_.

Referenced by ACE_Process::spawn.

00313 {
00314   if (max_lenp != 0)
00315     *max_lenp = this->command_line_buf_len_;
00316   return this->command_line_buf_;
00317 }

ACE_INLINE void ACE_Process_Options::creation_flags u_long   
 

Set the creation flags.

Definition at line 103 of file Process.i.

References creation_flags_.

00104 {
00105   creation_flags_ = cf;
00106 }

ACE_INLINE u_long ACE_Process_Options::creation_flags void    const
 

Get the creation flags.

Definition at line 93 of file Process.i.

References creation_flags_.

Referenced by ACE_Process::spawn.

00094 {
00095 #if defined (UNICODE) && defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00096   return creation_flags_ | CREATE_UNICODE_ENVIRONMENT;
00097 #else
00098   return creation_flags_;
00099 #endif /* UNICODE */
00100 }

int ACE_Process_Options::dup_handles ACE_Handle_Set   set const
 

Get a copy of the handles the ACE_Process_Options duplicated for the spawned process.

Any handles created through duplication of those passed into

  • pass_handle are returned in
  • set.
Returns:
0 if there were no handles to return; 1 if there were.

Definition at line 939 of file Process.cpp.

References dup_handles_, ACE_Handle_Set::num_set, and ACE_Handle_Set::reset.

Referenced by ACE_Process::spawn.

00940 {
00941   if (this->dup_handles_.num_set () == 0)
00942     return 0;
00943   set.reset ();
00944   set = this->dup_handles_;
00945   return 1;
00946 }

ACE_TCHAR * ACE_Process_Options::env_buf void   
 

Null-terminated buffer of null terminated strings. Each string is an environment assignment "VARIABLE=value". This buffer should end with two null characters.

Definition at line 853 of file Process.cpp.

References environment_buf_.

Referenced by ACE_Process::spawn.

00854 {
00855 #if !defined (ACE_HAS_WINCE)
00856   if (environment_buf_[0] == '\0')
00857     return 0;
00858   else
00859     return environment_buf_;
00860 #else
00861   return 0;
00862 #endif /* !ACE_HAS_WINCE */
00863 }

LPSECURITY_ATTRIBUTES ACE_Process_Options::get_process_attributes void    const
 

Get the process_attributes. Returns NULL if set_process_attributes has not been set.

Referenced by ACE_Process::spawn.

LPSECURITY_ATTRIBUTES ACE_Process_Options::get_thread_attributes void    const
 

Get the thread_attributes. Returns NULL if set_thread_attributes has not been set.

Referenced by ACE_Process::spawn.

ACE_INLINE pid_t ACE_Process_Options::getgroup void    const
 

Get the process group. On UNIX, these methods are used by the <ACE_Process_Manager> to manage groups of processes.

Definition at line 109 of file Process.i.

References process_group_.

Referenced by ACE_Process::spawn.

00110 {
00111   return process_group_;
00112 }

ACE_INLINE void ACE_Process_Options::handle_inheritence int   
 

Definition at line 133 of file Process.i.

References handle_inheritence_.

00134 {
00135 #if defined (ACE_WIN32) &&  !defined (ACE_HAS_WINCE)
00136   handle_inheritence_ = hi;
00137 #else
00138   ACE_UNUSED_ARG (hi);
00139   ACE_NOTSUP;
00140 #endif /* !ACE_HAS_WINCE */
00141 }

ACE_INLINE int ACE_Process_Options::handle_inheritence void   
 

Default is TRUE. Allows disabling of handle inheritence.

Definition at line 123 of file Process.i.

References handle_inheritence_.

Referenced by ACE_Process::spawn.

00124 {
00125 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00126   return handle_inheritence_;
00127 #else
00128   ACE_NOTSUP_RETURN (0);  // This is a benign error.
00129 #endif /* ACE_WIN32 && ! ACE_HAS_WINCE */
00130 }

void ACE_Process_Options::inherit_environment void    [protected]
 

Helper function to grab win32 environment and stick it in environment_buf_ using this->setenv_i.

Definition at line 533 of file Process.cpp.

References ACE_ERROR, ACE_LIB_TEXT, ACE_TCHAR, environment_inherited_, ACE_OS::getenvstrings, LM_ERROR, setenv_i, and ACE_OS_String::strlen.

Referenced by setenv, and ACE_Process::spawn.

00534 {
00535   // Ensure only once execution.
00536   if (environment_inherited_)
00537     return;
00538   environment_inherited_ = 1;
00539 
00540   // Get the existing environment.
00541   ACE_TCHAR *existing_environment = ACE_OS::getenvstrings ();
00542 
00543   size_t slot = 0;
00544 
00545   while (existing_environment[slot] != '\0')
00546     {
00547       size_t len = ACE_OS::strlen (existing_environment + slot);
00548 
00549       // Add the string to our env buffer.
00550       if (this->setenv_i (existing_environment + slot, len) == -1)
00551         {
00552           ACE_ERROR ((LM_ERROR,
00553                       ACE_LIB_TEXT ("%p.\n"),
00554                       ACE_LIB_TEXT ("ACE_Process_Options::ACE_Process_Options")));
00555           break;
00556         }
00557 
00558       // Skip to the next word.
00559       slot += len + 1;
00560     }
00561 
00562   ACE_TEXT_FreeEnvironmentStrings (existing_environment);
00563 }

int ACE_Process_Options::pass_handle ACE_HANDLE   
 

Cause the specified handle to be passed to a child process when it runs a new program image.

The specified handle value will be included in the spawned process's command line as

  • +H
  • handle, if a new program is spawned (always on Win32; else if NO_EXEC is not set in creation flags). The passed handle value will be duplicated if on Win32 less capable than NT.
Returns:
0 if success, -1 if failure.

Definition at line 896 of file Process.cpp.

References dup_handles_, handles_passed_, and ACE_Handle_Set::set_bit.

00897 {
00898 # if defined (ACE_WIN32)
00899 #  if defined (ACE_HAS_WINCE)
00900   ACE_NOTSUP_RETURN (-1);
00901 #  else
00902 
00903   // This is oriented towards socket handles... may need some adjustment
00904   // for non-sockets.
00905   // This is all based on an MSDN article:
00906   // http://support.microsoft.com/support/kb/articles/Q150/5/23.asp
00907   // If on Win95/98, the handle needs to be duplicated for the to-be-spawned
00908   // process. On WinNT, they get inherited by the child process automatically.
00909   // If the handle is duplicated, remember the duplicate so it can be
00910   // closed later. Can't be closed now, or the child won't get it.
00911   OSVERSIONINFO osvi;
00912   ZeroMemory (&osvi, sizeof (osvi));
00913   osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
00914   // If this is Win95/98 or we can't tell, duplicate the handle.
00915   if (!GetVersionEx (&osvi) || osvi.dwPlatformId != VER_PLATFORM_WIN32_NT)
00916     {
00917       HANDLE dup_handle;
00918       if (!DuplicateHandle (GetCurrentProcess (),
00919                             ACE_static_cast (HANDLE, h),
00920                             GetCurrentProcess (),
00921                             &dup_handle,
00922                             0,
00923                             TRUE,   // Inheritable
00924                             DUPLICATE_SAME_ACCESS))
00925         return -1;
00926       dup_handles_.set_bit (ACE_static_cast (ACE_HANDLE, dup_handle));
00927     }
00928 #  endif /* ACE_HAS_WINCE */
00929 #endif /* ACE_WIN32 */
00930 
00931   this->handles_passed_.set_bit (h);
00932 
00933   return 0;
00934 }

int ACE_Process_Options::passed_handles ACE_Handle_Set   set const
 

Get a copy of the handles passed to the spawned process. This will be the set of handles previously passed to

Any handles previously passed to

  • pass_handle are returned in
  • set.
Returns:
0 if there were no handles to return; 1 if there were.

Definition at line 951 of file Process.cpp.

References handles_passed_, ACE_Handle_Set::num_set, and ACE_Handle_Set::reset.

Referenced by ACE_Process::spawn.

00952 {
00953   if (this->handles_passed_.num_set () == 0)
00954     return 0;
00955   set.reset ();
00956   set = this->handles_passed_;
00957   return 1;
00958 }

ACE_INLINE const ACE_TCHAR * ACE_Process_Options::process_name void   
 

Return the process_name. If the <process_name(name)> set method is not called, this method will return argv[0].

Definition at line 361 of file Process.i.

References process_name_.

00362 {
00363   if (process_name_[0] == '\0')
00364     this->process_name (this->command_line_argv ()[0]);
00365 
00366   return this->process_name_;
00367 }

ACE_INLINE void ACE_Process_Options::process_name const ACE_TCHAR   name
 

Specify the full path or relative path, or just the executable name for the process. If this is set, then <name> will be used to create the process instead of argv[0] set in the command line. This is here so that you can supply something other than executable name as argv[0].

Definition at line 355 of file Process.i.

References ACE_TCHAR, and ACE_OS_String::strcpy.

Referenced by ACE_Process::spawn.

00356 {
00357   ACE_OS::strcpy (this->process_name_, p);
00358 }

void ACE_Process_Options::release_handles void   
 

Felease the standard handles previously set with set_handles;.

Definition at line 747 of file Process.cpp.

References ACE_OS::close, set_handles_called_, and startup_info_.

Referenced by ~ACE_Process_Options.

00748 {
00749   if (set_handles_called_)
00750     {
00751 #if defined (ACE_WIN32)
00752       ACE_OS::close (startup_info_.hStdInput);
00753       ACE_OS::close (startup_info_.hStdOutput);
00754       ACE_OS::close (startup_info_.hStdError);
00755 #else /* ACE_WIN32 */
00756       ACE_OS::close (stdin_);
00757       ACE_OS::close (stdout_);
00758       ACE_OS::close (stderr_);
00759 #endif /* ACE_WIN32 */
00760       set_handles_called_ = 0;
00761     }
00762 }

int ACE_Process_Options::set_handles ACE_HANDLE    std_in,
ACE_HANDLE    std_out = ACE_INVALID_HANDLE,
ACE_HANDLE    std_err = ACE_INVALID_HANDLE
 

Set the standard handles of the new process to the respective handles. If you want to affect a subset of the handles, make sure to set the others to ACE_INVALID_HANDLE. Returns 0 on success, -1 on failure.

Definition at line 693 of file Process.cpp.

References ACE_STDERR, ACE_STDIN, ACE_STDOUT, ACE_OS::dup, set_handles_called_, and startup_info_.

00696 {
00697   this->set_handles_called_ = 1;
00698 #if defined (ACE_WIN32)
00699 
00700   // Tell the new process to use our std handles.
00701   this->startup_info_.dwFlags = STARTF_USESTDHANDLES;
00702 
00703   if (std_in == ACE_INVALID_HANDLE)
00704     std_in = ACE_STDIN;
00705   if (std_out == ACE_INVALID_HANDLE)
00706     std_out = ACE_STDOUT;
00707   if (std_err == ACE_INVALID_HANDLE)
00708     std_err = ACE_STDERR;
00709 
00710   if (!::DuplicateHandle (::GetCurrentProcess (),
00711                           std_in,
00712                           ::GetCurrentProcess (),
00713                           &this->startup_info_.hStdInput,
00714                           0,
00715                           TRUE,
00716                           DUPLICATE_SAME_ACCESS))
00717     return -1;
00718 
00719   if (!::DuplicateHandle (::GetCurrentProcess (),
00720                           std_out,
00721                           ::GetCurrentProcess (),
00722                           &this->startup_info_.hStdOutput,
00723                           0,
00724                           TRUE,
00725                           DUPLICATE_SAME_ACCESS))
00726     return -1;
00727 
00728   if (!::DuplicateHandle (::GetCurrentProcess (),
00729                           std_err,
00730                           ::GetCurrentProcess (),
00731                           &this->startup_info_.hStdError,
00732                           0,
00733                           TRUE,
00734                           DUPLICATE_SAME_ACCESS))
00735     return -1;
00736 #else /* ACE_WIN32 */
00737   this->stdin_ = ACE_OS::dup (std_in);
00738   this->stdout_ = ACE_OS::dup (std_out);
00739   this->stderr_ = ACE_OS::dup (std_err);
00740 #endif /* ACE_WIN32 */
00741 
00742   return 0; // Success.
00743 }

LPSECURITY_ATTRIBUTES ACE_Process_Options::set_process_attributes void   
 

If this is called, a non-null process attributes is sent to CreateProcess.

LPSECURITY_ATTRIBUTES ACE_Process_Options::set_thread_attributes void   
 

If this is called, a non-null thread attributes is sent to CreateProcess.

int ACE_Process_Options::setenv ACE_TCHAR   envp[]
 

Same as above with argv format. <envp> must be null terminated.

Definition at line 576 of file Process.cpp.

References ACE_TCHAR, inherit_environment, setenv_i, and ACE_OS_String::strlen.

00577 {
00578   int i = 0;
00579   while (envp[i])
00580     {
00581       if (this->setenv_i (envp[i],
00582                           ACE_OS_String::strlen (envp[i])) == -1)
00583         return -1;
00584       i++;
00585     }
00586 
00587 #if defined (ACE_WIN32)
00588   if (inherit_environment_)
00589     this->inherit_environment ();
00590 #endif /* ACE_WIN32 */
00591 
00592   return 0;
00593 }

int ACE_Process_Options::setenv const ACE_TCHAR   variable_name,
const ACE_TCHAR   format,
...   
 

Set a single environment variable, <variable_name>. Since different platforms separate each environment variable differently, you must call this method once for each variable. <format> can be any printf format string. So options->setenv ("FOO","one + two = s", "three") will result in "FOO=one + two = three".

Definition at line 625 of file Process.cpp.

References ACE_LIB_TEXT, ACE_TCHAR, DEFAULT_COMMAND_LINE_BUF_LEN, inherit_environment, setenv_i, ACE_OS::sprintf, ACE_OS_String::strlen, and ACE_OS::vsprintf.

00627 {
00628   ACE_TCHAR newformat[DEFAULT_COMMAND_LINE_BUF_LEN];
00629 
00630   // Add in the variable name.
00631   ACE_OS::sprintf (newformat,
00632                    ACE_LIB_TEXT ("%s=%s"),
00633                    variable_name,
00634                    format);
00635 
00636   ACE_TCHAR stack_buf[DEFAULT_COMMAND_LINE_BUF_LEN];
00637 
00638   // Start varargs.
00639   va_list argp;
00640   va_start (argp, format);
00641 
00642   // Add the rest of the varargs.
00643   ACE_OS::vsprintf (stack_buf, newformat, argp);
00644 
00645   // End varargs.
00646   va_end (argp);
00647 
00648   // Append the string to our environment buffer.
00649   if (this->setenv_i (stack_buf,
00650                       ACE_OS_String::strlen (stack_buf)) == -1)
00651     return -1;
00652 
00653 #if defined (ACE_WIN32)
00654   if (inherit_environment_)
00655     this->inherit_environment ();
00656 #endif /* ACE_WIN32 */
00657 
00658   return 0;
00659 }

int ACE_Process_Options::setenv const ACE_TCHAR   format,
...   
 

<format> must be of the form "VARIABLE=VALUE". There can not be any spaces between VARIABLE and the equal sign.

Definition at line 596 of file Process.cpp.

References ACE_TCHAR, DEFAULT_COMMAND_LINE_BUF_LEN, inherit_environment, setenv_i, ACE_OS_String::strlen, and ACE_OS::vsprintf.

00597 {
00598   ACE_TCHAR stack_buf[DEFAULT_COMMAND_LINE_BUF_LEN];
00599 
00600   // Start varargs.
00601   va_list argp;
00602   va_start (argp, format);
00603 
00604   // Add the rest of the varargs.
00605   ACE_OS::vsprintf (stack_buf,
00606                     format,
00607                     argp);
00608   // End varargs.
00609   va_end (argp);
00610 
00611   // Append the string to are environment buffer.
00612   if (this->setenv_i (stack_buf,
00613                       ACE_OS_String::strlen (stack_buf)) == -1)
00614     return -1;
00615 
00616 #if defined (ACE_WIN32)
00617   if (inherit_environment_)
00618     this->inherit_environment ();
00619 #endif /* ACE_WIN32 */
00620 
00621   return 0;
00622 }

int ACE_Process_Options::setenv_i ACE_TCHAR   assignment,
size_t    len
[protected]
 

Add <assignment> to environment_buf_ and adjust environment_argv_. <len> is the strlen of <assignment>.

Definition at line 662 of file Process.cpp.

References ACE_TCHAR, environment_argv_, environment_argv_index_, environment_buf_, environment_buf_index_, environment_buf_len_, max_environ_argv_index_, and ACE_OS_String::memcpy.

Referenced by inherit_environment, and setenv.

00664 {
00665   // Add one for the null char.
00666   len++;
00667 
00668   // If environment larger than allocated buffer return. Also check to
00669   // make sure we have enough room.
00670   if (environment_argv_index_ == max_environ_argv_index_
00671       || (len + environment_buf_index_) >= environment_buf_len_)
00672     return -1;
00673 
00674   // Copy the new environment string.
00675   ACE_OS::memcpy (environment_buf_ + environment_buf_index_,
00676                   assignment,
00677                   len * sizeof (ACE_TCHAR));
00678 
00679   // Update the argv array.
00680   environment_argv_[environment_argv_index_++] =
00681     environment_buf_ + environment_buf_index_;
00682   environment_argv_[environment_argv_index_] = 0;
00683 
00684   // Update our index.
00685   environment_buf_index_ += len;
00686 
00687   // Make sure the buffer is null-terminated.
00688   environment_buf_[environment_buf_index_] = '\0';
00689   return 0;
00690 }

ACE_INLINE pid_t ACE_Process_Options::setgroup pid_t    pgrp
 

Set the process group. On UNIX, these methods are used by the <ACE_Process_Manager> to manage groups of processes.

Definition at line 115 of file Process.i.

References pid_t, and process_group_.

00116 {
00117   pid_t old = process_group_;
00118   process_group_ = pgrp;
00119   return old;
00120 }

ACE_TEXT_STARTUPINFO* ACE_Process_Options::startup_info void   
 

Used for setting and getting.

Referenced by ACE_Process::spawn.

ACE_INLINE ACE_TCHAR * ACE_Process_Options::working_directory void   
 

Current working directory. Returns "" if nothing has been set.

Definition at line 320 of file Process.i.

References working_directory_.

00321 {
00322 #if !defined (ACE_HAS_WINCE)
00323   if (working_directory_[0] == '\0')
00324     return 0;
00325   else
00326     return working_directory_;
00327 #else
00328   return 0;
00329 #endif /* !ACE_HAS_WINCE */
00330 }

void ACE_Process_Options::working_directory const wchar_t *    wd
 

wchar_t version of working_directory.

ACE_INLINE void ACE_Process_Options::working_directory const char *    wd
 

Set the working directory for the process. strlen of <wd> must be <= MAXPATHLEN.

Definition at line 333 of file Process.i.

References ACE_TEXT_CHAR_TO_TCHAR, ACE_OS_String::strcpy, and working_directory_.

Referenced by ACE_Process::spawn.

00334 {
00335 #if !defined(ACE_HAS_WINCE)
00336   ACE_OS::strcpy (working_directory_, ACE_TEXT_CHAR_TO_TCHAR (wd));
00337 #else
00338   ACE_UNUSED_ARG (wd);
00339 #endif /* !ACE_HAS_WINCE */
00340 }


Member Data Documentation

int ACE_Process_Options::avoid_zombies_ [protected]
 

Avoid zombies for spawned processes.

Definition at line 319 of file Process.h.

Referenced by avoid_zombies.

ACE_TCHAR* ACE_Process_Options::command_line_argv_[MAX_COMMAND_LINE_OPTIONS] [protected]
 

Argv-style command-line arguments.

Definition at line 399 of file Process.h.

Referenced by command_line_argv.

int ACE_Process_Options::command_line_argv_calculated_ [protected]
 

Ensures command_line_argv is only calculated once.

Definition at line 390 of file Process.h.

Referenced by command_line, and command_line_argv.

ACE_TCHAR* ACE_Process_Options::command_line_buf_ [protected]
 

Pointer to buffer of command-line arguments. E.g., "-f foo -b bar".

Definition at line 393 of file Process.h.

Referenced by ACE_Process_Options, command_line, command_line_argv, command_line_buf, and ~ACE_Process_Options.

int ACE_Process_Options::command_line_buf_len_ [protected]
 

Max length of command_line_buf_.

Definition at line 396 of file Process.h.

Referenced by command_line_buf.

u_long ACE_Process_Options::creation_flags_ [protected]
 

Default 0.

Definition at line 316 of file Process.h.

Referenced by creation_flags.

ACE_Handle_Set ACE_Process_Options::dup_handles_ [protected]
 

Results of duplicating handles passed in pass_handle ().

Definition at line 408 of file Process.h.

Referenced by dup_handles, and pass_handle.

ACE_TCHAR** ACE_Process_Options::environment_argv_ [protected]
 

Pointers into environment_buf_.

Definition at line 377 of file Process.h.

Referenced by ACE_Process_Options, setenv_i, and ~ACE_Process_Options.

int ACE_Process_Options::environment_argv_index_ [protected]
 

Pointer to environment_argv_.

Definition at line 368 of file Process.h.

Referenced by setenv_i.

ACE_TCHAR* ACE_Process_Options::environment_buf_ [protected]
 

Pointer to buffer of the environment settings.

Definition at line 371 of file Process.h.

Referenced by ACE_Process_Options, env_buf, setenv_i, and ~ACE_Process_Options.

size_t ACE_Process_Options::environment_buf_index_ [protected]
 

Pointer into environment_buf_. This should point to the next free spot.

Definition at line 365 of file Process.h.

Referenced by setenv_i.

size_t ACE_Process_Options::environment_buf_len_ [protected]
 

Size of the environment buffer. Configurable.

Definition at line 374 of file Process.h.

Referenced by setenv_i.

int ACE_Process_Options::environment_inherited_ [protected]
 

Ensures once only call to inherit environment.

Definition at line 327 of file Process.h.

Referenced by inherit_environment.

BOOL ACE_Process_Options::handle_inheritence_ [protected]
 

Default TRUE.

Definition at line 332 of file Process.h.

Referenced by handle_inheritence.

ACE_Handle_Set ACE_Process_Options::handles_passed_ [protected]
 

Set of handles that were passed in pass_handle ().

Definition at line 405 of file Process.h.

Referenced by pass_handle, and passed_handles.

int ACE_Process_Options::inherit_environment_ [protected]
 

Whether the child process inherits the current process environment.

Definition at line 312 of file Process.h.

int ACE_Process_Options::max_environ_argv_index_ [protected]
 

Maximum index of environment_argv_ buffer.

Definition at line 383 of file Process.h.

Referenced by setenv_i.

int ACE_Process_Options::max_environment_args_ [protected]
 

Maximum number of environment variables. Configurable.

Definition at line 380 of file Process.h.

LPSECURITY_ATTRIBUTES ACE_Process_Options::process_attributes_ [protected]
 

Pointer to security_buf1_.

Definition at line 335 of file Process.h.

pid_t ACE_Process_Options::process_group_ [protected]
 

Process-group on Unix; unused on Win32.

Definition at line 402 of file Process.h.

Referenced by getgroup, and setgroup.

ACE_TCHAR ACE_Process_Options::process_name_[MAXPATHLEN + 1] [protected]
 

Pathname for the process. Relative path or absolute path or just the program name.

Definition at line 412 of file Process.h.

Referenced by ACE_Process_Options, and process_name.

SECURITY_ATTRIBUTES ACE_Process_Options::security_buf1_ [protected]
 

Data for process_attributes_.

Definition at line 341 of file Process.h.

SECURITY_ATTRIBUTES ACE_Process_Options::security_buf2_ [protected]
 

Data for thread_attributes_.

Definition at line 344 of file Process.h.

int ACE_Process_Options::set_handles_called_ [protected]
 

Is 1 if stdhandles was called.

Definition at line 361 of file Process.h.

Referenced by release_handles, and set_handles.

ACE_TEXT_STARTUPINFO ACE_Process_Options::startup_info_ [protected]
 

Definition at line 329 of file Process.h.

Referenced by ACE_Process_Options, release_handles, and set_handles.

LPSECURITY_ATTRIBUTES ACE_Process_Options::thread_attributes_ [protected]
 

Pointer to security_buf2_.

Definition at line 338 of file Process.h.

ACE_TCHAR ACE_Process_Options::working_directory_[MAXPATHLEN + 1] [protected]
 

The current working directory.

Definition at line 386 of file Process.h.

Referenced by ACE_Process_Options, and working_directory.


The documentation for this class was generated from the following files:
Generated on Mon Jun 16 12:54:32 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002