#include <Process.h>
Collaboration diagram for ACE_Process_Options:
Public Types | |
enum | { DEFAULT_COMMAND_LINE_BUF_LEN = 1024, NO_EXEC = 0 } |
Public Member Functions | |
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. | |
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) |
Release the standard handles previously set with set_handles;. | |
int | setenv (const ACE_TCHAR *format,...) |
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. | |
void | working_directory (const char *wd) |
void | working_directory (const wchar_t *wd) |
wchar_t version of working_directory | |
int | command_line (const ACE_TCHAR *format,...) |
int | command_line (const ACE_ANTI_TCHAR *format,...) |
Anti-TChar version of command_line (). | |
int | command_line (const ACE_TCHAR *const argv[]) |
Same as above in argv format. argv must be null terminated. | |
void | process_name (const ACE_TCHAR *name) |
const ACE_TCHAR * | process_name (void) |
u_long | creation_flags (void) const |
Get the creation flags. | |
void | creation_flags (u_long) |
ACE_TCHAR * | working_directory (void) |
Current working directory. Returns "" if nothing has been set. | |
ACE_TCHAR * | command_line_buf (int *max_len=0) |
ACE_TCHAR *const * | command_line_argv (void) |
ACE_TCHAR * | env_buf (void) |
pid_t | getgroup (void) const |
pid_t | setgroup (pid_t pgrp) |
int | handle_inheritence (void) |
Allows disabling of handle inheritence, default is TRUE. | |
void | handle_inheritence (int) |
int | pass_handle (ACE_HANDLE) |
int | dup_handles (ACE_Handle_Set &set) const |
int | passed_handles (ACE_Handle_Set &set) const |
void | avoid_zombies (int) |
Set value for avoid_zombies (has no real effect except on *nix). | |
int | avoid_zombies (void) |
Get current value for avoid_zombies. | |
ACE_TEXT_STARTUPINFO * | startup_info (void) |
Used for setting and getting. | |
LPSECURITY_ATTRIBUTES | get_process_attributes (void) const |
LPSECURITY_ATTRIBUTES | set_process_attributes (void) |
LPSECURITY_ATTRIBUTES | get_thread_attributes (void) const |
LPSECURITY_ATTRIBUTES | set_thread_attributes (void) |
Protected Types | |
enum | { MAX_COMMAND_LINE_OPTIONS = 128, ENVIRONMENT_BUFFER = 16 * 1024, MAX_ENVIRONMENT_ARGS = 512 } |
Protected Member Functions | |
int | setenv_i (ACE_TCHAR *assignment, size_t len) |
void | inherit_environment (void) |
Protected Attributes | |
int | inherit_environment_ |
u_long | creation_flags_ |
Default 0. | |
int | avoid_zombies_ |
Avoid zombies for spawned processes. | |
int | environment_inherited_ |
Ensures once only call to inherit environment. | |
ACE_TEXT_STARTUPINFO | startup_info_ |
BOOL | handle_inheritence_ |
Default TRUE. | |
LPSECURITY_ATTRIBUTES | process_attributes_ |
Pointer to security_buf1_. | |
LPSECURITY_ATTRIBUTES | thread_attributes_ |
Pointer to security_buf2_. | |
SECURITY_ATTRIBUTES | security_buf1_ |
Data for process_attributes_. | |
SECURITY_ATTRIBUTES | security_buf2_ |
Data for thread_attributes_. | |
int | set_handles_called_ |
Is 1 if stdhandles was called. | |
size_t | environment_buf_index_ |
int | environment_argv_index_ |
Pointer to environment_argv_. | |
ACE_TCHAR * | environment_buf_ |
Pointer to buffer of the environment settings. | |
size_t | environment_buf_len_ |
Size of the environment buffer. Configurable. | |
ACE_TCHAR ** | environment_argv_ |
Pointers into environment_buf_. | |
int | max_environment_args_ |
Maximum number of environment variables. Configurable. | |
int | max_environ_argv_index_ |
Maximum index of environment_argv_ buffer. | |
ACE_TCHAR | working_directory_ [MAXPATHLEN+1] |
The current working directory. | |
int | command_line_argv_calculated_ |
Ensures command_line_argv is only calculated once. | |
ACE_TCHAR * | command_line_buf_ |
Pointer to buffer of command-line arguments. E.g., "-f foo -b bar". | |
ACE_TCHAR * | command_line_copy_ |
int | command_line_buf_len_ |
Max length of command_line_buf_. | |
ACE_TCHAR * | command_line_argv_ [MAX_COMMAND_LINE_OPTIONS] |
Argv-style command-line arguments. | |
pid_t | process_group_ |
Process-group on Unix; unused on Win32. | |
ACE_Handle_Set | handles_passed_ |
Set of handles that were passed in pass_handle (). | |
ACE_Handle_Set | dup_handles_ |
Results of duplicating handles passed in pass_handle (). | |
ACE_TCHAR | process_name_ [MAXPATHLEN+1] |
This class controls the options passed to (or and ). 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 is used, the is using the system call. It means that the should include a full path to the program file ( does not search the PATH). If is not used then, the is using the which searches for the program file in the PATH variable.
Definition at line 52 of file Process.h.
|
Definition at line 55 of file Process.h.
00056 { 00057 DEFAULT_COMMAND_LINE_BUF_LEN = 1024, 00058 // UNIX process creation flags. 00059 #if defined (ACE_WIN32) 00060 NO_EXEC = 0 00061 #else 00062 NO_EXEC = 1 00063 #endif /* ACE_WIN32 */ 00064 }; |
|
Definition at line 71 of file Process.h.
00072 { 00073 MAX_COMMAND_LINE_OPTIONS = 128, 00074 ENVIRONMENT_BUFFER = 16 * 1024, // 16K 00075 MAX_ENVIRONMENT_ARGS = 512 // 00076 }; |
|
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 693 of file Process.cpp. References ACE_INVALID_PID, ACE_NEW, ACE_TCHAR, command_line_buf_, environment_argv_, environment_buf_, ACE_OS::memset(), startup_info_, uid_t, and working_directory_.
00697 : 00698 #if !defined (ACE_HAS_WINCE) 00699 inherit_environment_ (ie), 00700 #endif /* ACE_HAS_WINCE */ 00701 creation_flags_ (0), 00702 avoid_zombies_ (0), 00703 #if !defined (ACE_HAS_WINCE) 00704 #if defined (ACE_WIN32) 00705 environment_inherited_ (0), 00706 handle_inheritence_ (TRUE), 00707 process_attributes_ (0), 00708 thread_attributes_ (0), 00709 #else /* ACE_WIN32 */ 00710 stdin_ (ACE_INVALID_HANDLE), 00711 stdout_ (ACE_INVALID_HANDLE), 00712 stderr_ (ACE_INVALID_HANDLE), 00713 ruid_ ((uid_t) -1), 00714 euid_ ((uid_t) -1), 00715 rgid_ ((uid_t) -1), 00716 egid_ ((uid_t) -1), 00717 #endif /* ACE_WIN32 */ 00718 set_handles_called_ (0), 00719 environment_buf_index_ (0), 00720 environment_argv_index_ (0), 00721 environment_buf_ (0), 00722 environment_buf_len_ (ebl), 00723 max_environment_args_ (mea), 00724 max_environ_argv_index_ (mea - 1), 00725 #endif /* !ACE_HAS_WINCE */ 00726 command_line_argv_calculated_ (0), 00727 command_line_buf_ (0), 00728 command_line_copy_ (0), 00729 command_line_buf_len_ (cobl), 00730 process_group_ (ACE_INVALID_PID) 00731 { 00732 ACE_NEW (command_line_buf_, 00733 ACE_TCHAR[cobl]); 00734 command_line_buf_[0] = '\0'; 00735 00736 #if !defined (ACE_HAS_WINCE) 00737 working_directory_[0] = '\0'; 00738 ACE_NEW (environment_buf_, 00739 ACE_TCHAR[ebl]); 00740 ACE_NEW (environment_argv_, 00741 ACE_TCHAR *[mea]); 00742 environment_buf_[0] = '\0'; 00743 environment_argv_[0] = 0; 00744 process_name_[0] = '\0'; 00745 #if defined (ACE_WIN32) 00746 ACE_OS::memset ((void *) &this->startup_info_, 00747 0, 00748 sizeof this->startup_info_); 00749 this->startup_info_.cb = sizeof this->startup_info_; 00750 #endif /* ACE_WIN32 */ 00751 #endif /* !ACE_HAS_WINCE */ 00752 } |
|
Destructor.
Definition at line 1033 of file Process.cpp. References command_line_buf_, command_line_copy_, environment_argv_, environment_buf_, release_handles(), and ACE::strdelete().
01034 { 01035 #if !defined (ACE_HAS_WINCE) 01036 release_handles(); 01037 delete [] environment_buf_; 01038 delete [] environment_argv_; 01039 #endif /* !ACE_HAS_WINCE */ 01040 delete [] command_line_buf_; 01041 ACE::strdelete (command_line_copy_); 01042 } |
|
Get current value for avoid_zombies.
Definition at line 153 of file Process.inl. References avoid_zombies_.
00154 { 00155 return avoid_zombies_; 00156 } |
|
Set value for avoid_zombies (has no real effect except on *nix).
Definition at line 158 of file Process.inl. References avoid_zombies_. Referenced by ACE_Process::spawn().
00159 { 00160 avoid_zombies_ = avoid_zombies; 00161 } |
|
Same as above in argv format. argv must be null terminated.
Definition at line 1045 of file Process.cpp. References ACE_TCHAR, ACE_TEXT, command_line_argv_calculated_, command_line_buf_, and ACE_OS::strcat().
01046 { 01047 // @@ Factor out the code between this 01048 int i = 0; 01049 01050 if (argv[i]) 01051 { 01052 ACE_OS::strcat (command_line_buf_, argv[i]); 01053 while (argv[++i]) 01054 { 01055 ACE_OS::strcat (command_line_buf_, 01056 ACE_TEXT (" ")); 01057 ACE_OS::strcat (command_line_buf_, 01058 argv[i]); 01059 } 01060 } 01061 01062 command_line_argv_calculated_ = 0; 01063 return 0; // Success. 01064 } |
|
Anti-TChar version of command_line ().
Definition at line 1102 of file Process.cpp. References ACE_ANTI_TCHAR, ACE_NEW_RETURN, ACE_TEXT_ANTI_TO_TCHAR, command_line_argv_calculated_, ACE_OS::strcpy(), and ACE_OS::vsprintf().
01103 { 01104 ACE_ANTI_TCHAR *anti_clb; 01105 ACE_NEW_RETURN (anti_clb, 01106 ACE_ANTI_TCHAR[this->command_line_buf_len_], 01107 -1); 01108 01109 // Store all ... args in argp. 01110 va_list argp; 01111 va_start (argp, format); 01112 01113 // sprintf the format and args into command_line_buf_. 01114 ACE_OS::vsprintf (anti_clb, 01115 format, 01116 argp); 01117 01118 // Useless macro. 01119 va_end (argp); 01120 01121 ACE_OS::strcpy (this->command_line_buf_, 01122 ACE_TEXT_ANTI_TO_TCHAR (anti_clb)); 01123 01124 delete [] anti_clb; 01125 01126 command_line_argv_calculated_ = 0; 01127 return 0; 01128 } |
|
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 1067 of file Process.cpp. References ACE_TCHAR, command_line_argv_calculated_, command_line_buf_, command_line_buf_len_, ACE_OS::vsnprintf(), and ACE_OS::vsprintf().
01068 { 01069 // Store all ... args in argp. 01070 va_list argp; 01071 va_start (argp, format); 01072 01073 if (command_line_buf_len_ < 1) 01074 return -1; 01075 01076 #if !defined (ACE_LACKS_VSNPRINTF) || defined (ACE_HAS_TRIO) 01077 // vsnprintf the format and args into command_line_buf__. 01078 ACE_OS::vsnprintf (command_line_buf_, 01079 command_line_buf_len_, 01080 format, 01081 argp); 01082 #else 01083 // sprintf the format and args into command_line_buf__. 01084 ACE_OS::vsprintf (command_line_buf_, 01085 format, 01086 argp); 01087 #endif 01088 01089 // Useless macro. 01090 va_end (argp); 01091 01092 command_line_argv_calculated_ = 0; 01093 return 0; 01094 } |
|
argv-style command-line options. Parses and modifies the string created from . All spaces not in quotes ("" or '') are replaced with null () 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 1145 of file Process.cpp. References command_line_argv_, command_line_argv_calculated_, command_line_buf_, command_line_copy_, ACE_Tokenizer::delimiter_replace(), MAX_COMMAND_LINE_OPTIONS, ACE_Tokenizer::next(), ACE_Tokenizer::preserve_designators(), ACE::strdelete(), and ACE::strnew(). Referenced by ACE_Process::spawn().
01146 { 01147 if (command_line_argv_calculated_ == 0) 01148 { 01149 command_line_argv_calculated_ = 1; 01150 01151 // We need to free up any previous allocated memory first. 01152 ACE::strdelete (command_line_copy_); 01153 01154 // We need to make a dynamically allocated copy here since 01155 // ACE_Tokenizer modifies its arguments. 01156 command_line_copy_ = ACE::strnew (command_line_buf_); 01157 // This tokenizer will replace all spaces with end-of-string 01158 // characters and will preserve text between "" and '' pairs. 01159 ACE_Tokenizer parser (command_line_copy_); 01160 parser.delimiter_replace (' ', '\0'); 01161 parser.preserve_designators ('\"', '\"'); // " 01162 parser.preserve_designators ('\'', '\''); 01163 01164 int x = 0; 01165 do 01166 command_line_argv_[x] = parser.next (); 01167 while (command_line_argv_[x] != 0 01168 // substract one for the ending zero. 01169 && ++x < MAX_COMMAND_LINE_OPTIONS - 1); 01170 01171 command_line_argv_[x] = 0; 01172 } 01173 01174 return command_line_argv_; 01175 } |
|
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 ''. [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.
Definition at line 321 of file Process.inl. References command_line_buf_, and command_line_buf_len_. Referenced by ACE_Process::spawn().
00322 { 00323 if (max_lenp != 0) 00324 *max_lenp = this->command_line_buf_len_; 00325 return this->command_line_buf_; 00326 } |
|
Set the creation flags to affect how a new process is spawned. The only ACE-defined flag is
On Windows, the value of creation_flags is passed to the Definition at line 112 of file Process.inl. References creation_flags_.
00113 { 00114 creation_flags_ = cf; 00115 } |
|
Get the creation flags.
Definition at line 102 of file Process.inl. References creation_flags_. Referenced by ACE_Process::spawn().
00103 { 00104 #if defined (ACE_USES_WCHAR) && defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) 00105 return creation_flags_ | CREATE_UNICODE_ENVIRONMENT; 00106 #else 00107 return creation_flags_; 00108 #endif /* ACE_USES_WCHAR */ 00109 } |
|
Any handles created through duplication of those passed into
Definition at line 1223 of file Process.cpp. References dup_handles_, ACE_Handle_Set::num_set(), and ACE_Handle_Set::reset(). Referenced by ACE_Process::spawn().
01224 { 01225 if (this->dup_handles_.num_set () == 0) 01226 return 0; 01227 set.reset (); 01228 set = this->dup_handles_; 01229 return 1; 01230 } |
|
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 1132 of file Process.cpp. References environment_buf_. Referenced by ACE_Process::spawn().
01133 { 01134 #if !defined (ACE_HAS_WINCE) 01135 if (environment_buf_[0] == '\0') 01136 return 0; 01137 else 01138 return environment_buf_; 01139 #else 01140 return 0; 01141 #endif /* !ACE_HAS_WINCE */ 01142 } |
|
Get the process_attributes. Returns NULL if set_process_attributes has not been set. Definition at line 176 of file Process.inl. References process_attributes_. Referenced by ACE_Process::spawn().
00177 { 00178 #if !defined (ACE_HAS_WINCE) 00179 return process_attributes_; 00180 #else 00181 return 0; 00182 #endif /* !ACE_HAS_WINCE */ 00183 } |
|
Get the thread_attributes. Returns NULL if set_thread_attributes has not been set. Definition at line 197 of file Process.inl. References thread_attributes_. Referenced by ACE_Process::spawn().
00198 { 00199 #if !defined (ACE_HAS_WINCE) 00200 return thread_attributes_; 00201 #else 00202 return 0; 00203 #endif /* !ACE_HAS_WINCE */ 00204 } |
|
Get the process group. On UNIX, these methods are used by the ACE_Process_Manager to manage groups of processes. Definition at line 118 of file Process.inl. References process_group_. Referenced by ACE_Process::spawn().
00119 { 00120 return process_group_; 00121 } |
|
Definition at line 142 of file Process.inl. References ACE_NOTSUP, and handle_inheritence_.
00143 { 00144 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) 00145 handle_inheritence_ = hi; 00146 #else 00147 ACE_UNUSED_ARG (hi); 00148 ACE_NOTSUP; 00149 #endif /* !ACE_HAS_WINCE */ 00150 } |
|
Allows disabling of handle inheritence, default is TRUE.
Definition at line 132 of file Process.inl. References ACE_NOTSUP_RETURN, and handle_inheritence_. Referenced by ACE_Process::spawn().
00133 { 00134 #if defined (ACE_WIN32) && !defined (ACE_HAS_WINCE) 00135 return handle_inheritence_; 00136 #else 00137 ACE_NOTSUP_RETURN (0); // This is a benign error. 00138 #endif /* ACE_WIN32 && ! ACE_HAS_WINCE */ 00139 } |
|
Helper function to grab win32 environment and stick it in environment_buf_ using this->setenv_i. Definition at line 757 of file Process.cpp. References ACE_ERROR, ACE_TCHAR, ACE_TEXT, ACE_TEXT_FreeEnvironmentStrings, environment_inherited_, ACE_OS::getenvstrings(), LM_ERROR, setenv_i(), and ACE_OS::strlen(). Referenced by setenv(), and ACE_Process::spawn().
00758 { 00759 // Ensure only once execution. 00760 if (environment_inherited_) 00761 return; 00762 environment_inherited_ = 1; 00763 00764 // Get the existing environment. 00765 ACE_TCHAR *existing_environment = ACE_OS::getenvstrings (); 00766 00767 size_t slot = 0; 00768 00769 while (existing_environment[slot] != '\0') 00770 { 00771 size_t len = ACE_OS::strlen (existing_environment + slot); 00772 00773 // Add the string to our env buffer. 00774 if (this->setenv_i (existing_environment + slot, len) == -1) 00775 { 00776 ACE_ERROR ((LM_ERROR, 00777 ACE_TEXT ("%p.\n"), 00778 ACE_TEXT ("ACE_Process_Options::ACE_Process_Options"))); 00779 break; 00780 } 00781 00782 // Skip to the next word. 00783 slot += len + 1; 00784 } 00785 00786 ACE_TEXT_FreeEnvironmentStrings (existing_environment); 00787 } |
|
The specified handle value will be included in the spawned process's command line as
Definition at line 1180 of file Process.cpp. References ACE_NOTSUP_RETURN, ACE_TEXT_GetVersionEx, ACE_TEXT_OSVERSIONINFO, dup_handles_, handles_passed_, and ACE_Handle_Set::set_bit().
01181 { 01182 # if defined (ACE_WIN32) 01183 # if defined (ACE_HAS_WINCE) 01184 ACE_NOTSUP_RETURN (-1); 01185 # else 01186 01187 // This is oriented towards socket handles... may need some adjustment 01188 // for non-sockets. 01189 // This is all based on an MSDN article: 01190 // http://support.microsoft.com/support/kb/articles/Q150/5/23.asp 01191 // If on Win95/98, the handle needs to be duplicated for the to-be-spawned 01192 // process. On WinNT, they get inherited by the child process automatically. 01193 // If the handle is duplicated, remember the duplicate so it can be 01194 // closed later. Can't be closed now, or the child won't get it. 01195 ACE_TEXT_OSVERSIONINFO osvi; 01196 ZeroMemory (&osvi, sizeof (osvi)); 01197 osvi.dwOSVersionInfoSize = sizeof (ACE_TEXT_OSVERSIONINFO); 01198 // If this is Win95/98 or we can't tell, duplicate the handle. 01199 if (!ACE_TEXT_GetVersionEx (&osvi) || osvi.dwPlatformId != VER_PLATFORM_WIN32_NT) 01200 { 01201 HANDLE dup_handle; 01202 if (!DuplicateHandle (GetCurrentProcess (), 01203 static_cast<HANDLE> (h), 01204 GetCurrentProcess (), 01205 &dup_handle, 01206 0, 01207 TRUE, // Inheritable 01208 DUPLICATE_SAME_ACCESS)) 01209 return -1; 01210 dup_handles_.set_bit (static_cast<ACE_HANDLE> (dup_handle)); 01211 } 01212 # endif /* ACE_HAS_WINCE */ 01213 #endif /* ACE_WIN32 */ 01214 01215 this->handles_passed_.set_bit (h); 01216 01217 return 0; 01218 } |
|
Any handles previously passed to
Definition at line 1235 of file Process.cpp. References handles_passed_, ACE_Handle_Set::num_set(), and ACE_Handle_Set::reset(). Referenced by ACE_Process::spawn().
01236 { 01237 if (this->handles_passed_.num_set () == 0) 01238 return 0; 01239 set.reset (); 01240 set = this->handles_passed_; 01241 return 1; 01242 } |
|
Return the process_name. If the <process_name(name)> set method is not called, this method will return argv[0]. Definition at line 370 of file Process.inl.
00371 { 00372 if (process_name_[0] == '\0') 00373 this->process_name (this->command_line_argv ()[0]); 00374 00375 return this->process_name_; 00376 } |
|
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 364 of file Process.inl. References ACE_TCHAR, and ACE_OS::strcpy(). Referenced by ACE_Process::spawn().
00365 { 00366 ACE_OS::strcpy (this->process_name_, p); 00367 } |
|
Release the standard handles previously set with set_handles;.
Definition at line 1014 of file Process.cpp. References ACE_OS::close(), set_handles_called_, and startup_info_. Referenced by ~ACE_Process_Options().
01015 { 01016 if (set_handles_called_) 01017 { 01018 #if defined (ACE_WIN32) 01019 ACE_OS::close (startup_info_.hStdInput); 01020 ACE_OS::close (startup_info_.hStdOutput); 01021 ACE_OS::close (startup_info_.hStdError); 01022 #else /* ACE_WIN32 */ 01023 ACE_OS::close (stdin_); 01024 ACE_OS::close (stdout_); 01025 ACE_OS::close (stderr_); 01026 #endif /* ACE_WIN32 */ 01027 set_handles_called_ = 0; 01028 } 01029 } |
|
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 960 of file Process.cpp. References ACE_STDERR, ACE_STDIN, ACE_STDOUT, ACE_OS::dup(), set_handles_called_, and startup_info_.
00963 { 00964 this->set_handles_called_ = 1; 00965 #if defined (ACE_WIN32) 00966 00967 // Tell the new process to use our std handles. 00968 this->startup_info_.dwFlags = STARTF_USESTDHANDLES; 00969 00970 if (std_in == ACE_INVALID_HANDLE) 00971 std_in = ACE_STDIN; 00972 if (std_out == ACE_INVALID_HANDLE) 00973 std_out = ACE_STDOUT; 00974 if (std_err == ACE_INVALID_HANDLE) 00975 std_err = ACE_STDERR; 00976 00977 if (!::DuplicateHandle (::GetCurrentProcess (), 00978 std_in, 00979 ::GetCurrentProcess (), 00980 &this->startup_info_.hStdInput, 00981 0, 00982 TRUE, 00983 DUPLICATE_SAME_ACCESS)) 00984 return -1; 00985 00986 if (!::DuplicateHandle (::GetCurrentProcess (), 00987 std_out, 00988 ::GetCurrentProcess (), 00989 &this->startup_info_.hStdOutput, 00990 0, 00991 TRUE, 00992 DUPLICATE_SAME_ACCESS)) 00993 return -1; 00994 00995 if (!::DuplicateHandle (::GetCurrentProcess (), 00996 std_err, 00997 ::GetCurrentProcess (), 00998 &this->startup_info_.hStdError, 00999 0, 01000 TRUE, 01001 DUPLICATE_SAME_ACCESS)) 01002 return -1; 01003 #else /* ACE_WIN32 */ 01004 this->stdin_ = ACE_OS::dup (std_in); 01005 this->stdout_ = ACE_OS::dup (std_out); 01006 this->stderr_ = ACE_OS::dup (std_err); 01007 #endif /* ACE_WIN32 */ 01008 01009 return 0; // Success. 01010 } |
|
If this is called, a non-null process attributes is sent to CreateProcess. Definition at line 186 of file Process.inl. References process_attributes_, and security_buf1_.
00187 { 00188 #if !defined (ACE_HAS_WINCE) 00189 process_attributes_ = &security_buf1_; 00190 return process_attributes_; 00191 #else 00192 return 0; 00193 #endif /* !ACE_HAS_WINCE */ 00194 } |
|
If this is called, a non-null thread attributes is sent to CreateProcess. Definition at line 207 of file Process.inl. References security_buf2_, and thread_attributes_.
00208 { 00209 #if !defined (ACE_HAS_WINCE) 00210 thread_attributes_ = &security_buf2_; 00211 return thread_attributes_; 00212 #else 00213 return 0; 00214 #endif /* !ACE_HAS_WINCE */ 00215 } |
|
Same as above with argv format. envp must be null terminated.
Definition at line 800 of file Process.cpp. References ACE_TCHAR, inherit_environment(), inherit_environment_, and setenv_i().
00801 { 00802 int i = 0; 00803 while (envp[i]) 00804 { 00805 if (this->setenv_i (envp[i], 00806 ACE_OS::strlen (envp[i])) == -1) 00807 return -1; 00808 i++; 00809 } 00810 00811 #if defined (ACE_WIN32) 00812 if (inherit_environment_) 00813 this->inherit_environment (); 00814 #endif /* ACE_WIN32 */ 00815 00816 return 0; 00817 } |
|
Set a single environment variable, variable_name. Since different platforms separate each environment variable differently, you must call this method once for each variable. can be any printf format string. So options->setenv ("FOO","one + two = %s", "three") will result in "FOO=one + two = three". Definition at line 849 of file Process.cpp. References ACE_NEW_RETURN, ACE_TCHAR, ACE_TEXT, DEFAULT_COMMAND_LINE_BUF_LEN, ENOTSUP, ACE_Auto_Basic_Array_Ptr< X >::get(), inherit_environment(), inherit_environment_, ACE_Auto_Basic_Array_Ptr< X >::reset(), setenv_i(), ACE_OS::sprintf(), ACE_OS::strlen(), ACE_OS::vsnprintf(), and ACE_OS::vsprintf().
00851 { 00852 // To address the potential buffer overflow, 00853 // we now allocate the buffer on heap with a variable size. 00854 size_t const buflen = ACE_OS::strlen (variable_name) + ACE_OS::strlen (format) + 2; 00855 ACE_TCHAR *newformat = 0; 00856 ACE_NEW_RETURN (newformat, ACE_TCHAR[buflen], -1); 00857 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> safe_newformat (newformat); 00858 00859 // Add in the variable name. 00860 ACE_OS::sprintf (safe_newformat.get (), 00861 ACE_TEXT ("%s=%s"), 00862 variable_name, 00863 format); 00864 00865 // Start varargs. 00866 va_list argp; 00867 va_start (argp, format); 00868 00869 // Add the rest of the varargs. 00870 size_t tmp_buflen = DEFAULT_COMMAND_LINE_BUF_LEN > buflen 00871 ? static_cast<size_t> (DEFAULT_COMMAND_LINE_BUF_LEN) : buflen; 00872 int retval = 0; 00873 00874 ACE_TCHAR *stack_buf = 0; 00875 ACE_NEW_RETURN (stack_buf, ACE_TCHAR[tmp_buflen], -1); 00876 ACE_Auto_Basic_Array_Ptr<ACE_TCHAR> safe_stack_buf (stack_buf); 00877 00878 do 00879 { 00880 retval = ACE_OS::vsnprintf (safe_stack_buf.get (), tmp_buflen, safe_newformat.get (), argp); 00881 if (retval > ACE_Utils::truncate_cast<int> (tmp_buflen)) 00882 { 00883 tmp_buflen *= 2; 00884 ACE_NEW_RETURN (stack_buf, ACE_TCHAR[tmp_buflen], -1); 00885 safe_stack_buf.reset (stack_buf); 00886 } 00887 else 00888 break; 00889 } 00890 while (1); 00891 00892 if (retval == -1) 00893 { 00894 // In case that vsnprintf is not supported, 00895 // e.g., LynxOS and VxWorks 5, we have to 00896 // fall back to vsprintf. 00897 if (errno == ENOTSUP) 00898 { 00899 // ALERT: Since we have to use vsprintf here, there is still a chance that 00900 // the stack_buf overflows, i.e., the length of the resulting string 00901 // can still possibly go beyond the allocated stack_buf. 00902 retval = ACE_OS::vsprintf (safe_stack_buf.get (), safe_newformat.get (), argp); 00903 if (retval == -1) 00904 // vsprintf is failed. 00905 return -1; 00906 } 00907 else 00908 // vsnprintf is failed. 00909 return -1; 00910 } 00911 00912 // End varargs. 00913 va_end (argp); 00914 00915 // Append the string to our environment buffer. 00916 if (this->setenv_i (safe_stack_buf.get (), 00917 ACE_OS::strlen (safe_stack_buf.get ())) == -1) 00918 return -1; 00919 00920 #if defined (ACE_WIN32) 00921 if (inherit_environment_) 00922 this->inherit_environment (); 00923 #endif /* ACE_WIN32 */ 00924 00925 return 0; 00926 } |
|
Definition at line 820 of file Process.cpp. References ACE_TCHAR, DEFAULT_COMMAND_LINE_BUF_LEN, inherit_environment(), inherit_environment_, setenv_i(), and ACE_OS::vsprintf().
00821 { 00822 ACE_TCHAR stack_buf[DEFAULT_COMMAND_LINE_BUF_LEN]; 00823 00824 // Start varargs. 00825 va_list argp; 00826 va_start (argp, format); 00827 00828 // Add the rest of the varargs. 00829 ACE_OS::vsprintf (stack_buf, 00830 format, 00831 argp); 00832 // End varargs. 00833 va_end (argp); 00834 00835 // Append the string to are environment buffer. 00836 if (this->setenv_i (stack_buf, 00837 ACE_OS::strlen (stack_buf)) == -1) 00838 return -1; 00839 00840 #if defined (ACE_WIN32) 00841 if (inherit_environment_) 00842 this->inherit_environment (); 00843 #endif /* ACE_WIN32 */ 00844 00845 return 0; 00846 } |
|
Add assignment to environment_buf_ and adjust environment_argv_. len is the strlen of assignment. Definition at line 929 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::memcpy(). Referenced by inherit_environment(), and setenv().
00931 { 00932 // Add one for the null char. 00933 ++len; 00934 00935 // If environment larger than allocated buffer return. Also check to 00936 // make sure we have enough room. 00937 if (environment_argv_index_ == max_environ_argv_index_ 00938 || (len + environment_buf_index_) >= environment_buf_len_) 00939 return -1; 00940 00941 // Copy the new environment string. 00942 ACE_OS::memcpy (environment_buf_ + environment_buf_index_, 00943 assignment, 00944 len * sizeof (ACE_TCHAR)); 00945 00946 // Update the argv array. 00947 environment_argv_[environment_argv_index_++] = 00948 environment_buf_ + environment_buf_index_; 00949 environment_argv_[environment_argv_index_] = 0; 00950 00951 // Update our index. 00952 environment_buf_index_ += len; 00953 00954 // Make sure the buffer is null-terminated. 00955 environment_buf_[environment_buf_index_] = '\0'; 00956 return 0; 00957 } |
|
Set the process group. On UNIX, these methods are used by the ACE_Process_Manager to manage groups of processes. Definition at line 124 of file Process.inl. References pid_t, and process_group_.
00125 { 00126 pid_t old = process_group_; 00127 process_group_ = pgrp; 00128 return old; 00129 } |
|
Used for setting and getting.
Definition at line 166 of file Process.inl. References startup_info_. Referenced by ACE_Process::spawn().
00167 { 00168 #if !defined (ACE_HAS_WINCE) 00169 return &startup_info_; 00170 #else 00171 return 0; 00172 #endif /* !ACE_HAS_WINCE */ 00173 } |
|
Current working directory. Returns "" if nothing has been set.
Definition at line 329 of file Process.inl. References working_directory_.
00330 { 00331 #if !defined (ACE_HAS_WINCE) 00332 if (working_directory_[0] == '\0') 00333 return 0; 00334 else 00335 return working_directory_; 00336 #else 00337 return 0; 00338 #endif /* !ACE_HAS_WINCE */ 00339 } |
|
wchar_t version of working_directory
Definition at line 353 of file Process.inl. References ACE_TEXT_WCHAR_TO_TCHAR, ACE_OS::strcpy(), and working_directory_.
00354 { 00355 #if !defined(ACE_HAS_WINCE) 00356 ACE_OS::strcpy (working_directory_, ACE_TEXT_WCHAR_TO_TCHAR (wd)); 00357 #else 00358 ACE_UNUSED_ARG (wd); 00359 #endif /* !ACE_HAS_WINCE */ 00360 } |
|
Set the working directory for the process. strlen of wd must be <= MAXPATHLEN. Definition at line 342 of file Process.inl. References ACE_TEXT_CHAR_TO_TCHAR, ACE_OS::strcpy(), and working_directory_. Referenced by ACE_Process::spawn().
00343 { 00344 #if !defined(ACE_HAS_WINCE) 00345 ACE_OS::strcpy (working_directory_, ACE_TEXT_CHAR_TO_TCHAR (wd)); 00346 #else 00347 ACE_UNUSED_ARG (wd); 00348 #endif /* !ACE_HAS_WINCE */ 00349 } |
|
Avoid zombies for spawned processes.
Definition at line 332 of file Process.h. Referenced by avoid_zombies(). |
|
Argv-style command-line arguments.
Definition at line 416 of file Process.h. Referenced by command_line_argv(). |
|
Ensures command_line_argv is only calculated once.
Definition at line 403 of file Process.h. Referenced by command_line(), and command_line_argv(). |
|
Pointer to buffer of command-line arguments. E.g., "-f foo -b bar".
Definition at line 406 of file Process.h. Referenced by ACE_Process_Options(), command_line(), command_line_argv(), command_line_buf(), and ~ACE_Process_Options(). |
|
Max length of command_line_buf_.
Definition at line 413 of file Process.h. Referenced by command_line(), and command_line_buf(). |
|
Pointer to copy of command-line arguments, which is needed when converting a command-line string into a command-line argv. Definition at line 410 of file Process.h. Referenced by command_line_argv(), and ~ACE_Process_Options(). |
|
Default 0.
Definition at line 329 of file Process.h. Referenced by creation_flags(). |
|
Results of duplicating handles passed in pass_handle ().
Definition at line 425 of file Process.h. Referenced by dup_handles(), and pass_handle(). |
|
Pointers into environment_buf_.
Definition at line 390 of file Process.h. Referenced by ACE_Process_Options(), setenv_i(), and ~ACE_Process_Options(). |
|
Pointer to environment_argv_.
Definition at line 381 of file Process.h. Referenced by setenv_i(). |
|
Pointer to buffer of the environment settings.
Definition at line 384 of file Process.h. Referenced by ACE_Process_Options(), env_buf(), setenv_i(), and ~ACE_Process_Options(). |
|
Pointer into environment_buf_. This should point to the next free spot. Definition at line 378 of file Process.h. Referenced by setenv_i(). |
|
Size of the environment buffer. Configurable.
Definition at line 387 of file Process.h. Referenced by setenv_i(). |
|
Ensures once only call to inherit environment.
Definition at line 340 of file Process.h. Referenced by inherit_environment(). |
|
Default TRUE.
Definition at line 345 of file Process.h. Referenced by handle_inheritence(). |
|
Set of handles that were passed in pass_handle ().
Definition at line 422 of file Process.h. Referenced by pass_handle(), and passed_handles(). |
|
Whether the child process inherits the current process environment. Definition at line 325 of file Process.h. Referenced by setenv(). |
|
Maximum index of environment_argv_ buffer.
Definition at line 396 of file Process.h. Referenced by setenv_i(). |
|
Maximum number of environment variables. Configurable.
|
|
Pointer to security_buf1_.
Definition at line 348 of file Process.h. Referenced by get_process_attributes(), and set_process_attributes(). |
|
Process-group on Unix; unused on Win32.
Definition at line 419 of file Process.h. Referenced by getgroup(), and setgroup(). |
|
Pathname for the process. Relative path or absolute path or just the program name. |
|
Data for process_attributes_.
Definition at line 354 of file Process.h. Referenced by set_process_attributes(). |
|
Data for thread_attributes_.
Definition at line 357 of file Process.h. Referenced by set_thread_attributes(). |
|
Is 1 if stdhandles was called.
Definition at line 374 of file Process.h. Referenced by release_handles(), and set_handles(). |
|
Definition at line 342 of file Process.h. Referenced by ACE_Process_Options(), release_handles(), set_handles(), and startup_info(). |
|
Pointer to security_buf2_.
Definition at line 351 of file Process.h. Referenced by get_thread_attributes(), and set_thread_attributes(). |
|
The current working directory.
Definition at line 399 of file Process.h. Referenced by ACE_Process_Options(), and working_directory(). |