3 #include "ace/OS_NS_sys_wait.h"
4 #include "ace/OS_NS_signal.h"
5 #include "ace/OS_NS_pwd.h"
6 #include "ace/OS_NS_string.h"
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
11 ACE_Process_Options::enable_unicode_environment ()
13 this->use_unicode_environment_ = true;
17 ACE_Process_Options::disable_unicode_environment ()
19 this->use_unicode_environment_ = false;
23 ACE_Process_Options::use_unicode_environment () const
25 return this->use_unicode_environment_;
28 #if defined (ACE_WIN32)
30 ACE_INLINE PROCESS_INFORMATION
31 ACE_Process::process_info ()
35 #endif /* ACE_WIN32 */
38 ACE_Process::gethandle () const
40 #if defined (ACE_WIN32)
41 return process_info_.hProcess;
43 return ACE_HANDLE (child_id_);
44 #endif /* ACE_WIN32 */
48 ACE_Process::getpid () const
50 #if defined (ACE_WIN32)
51 return process_info_.dwProcessId;
54 #endif /* ACE_WIN32 */
58 ACE_Process::wait (ACE_exitcode *status,
62 ACE_OS::wait (this->getpid (),
65 #if defined (ACE_WIN32)
66 , process_info_.hProcess
67 #endif /* ACE_WIN32 */
70 *status = this->exit_code_;
76 ACE_Process::kill (int signum)
78 if (this->getpid () != -1)
79 return ACE_OS::kill (this->getpid (), signum);
85 ACE_Process::terminate ()
87 if (this->getpid () != -1)
88 return ACE::terminate_process (this->getpid ());
94 ACE_Process::return_value () const
96 #if defined (ACE_WIN32)
97 return this->exit_code_;
99 return WEXITSTATUS (this->exit_code_);
100 #endif /* ACE_WIN32 */
103 ACE_INLINE ACE_exitcode
104 ACE_Process::exit_code () const
106 return this->exit_code_;
110 ACE_Process::exit_code (ACE_exitcode code)
112 this->exit_code_ = code;
116 ACE_Process_Options::creation_flags () const
118 #if defined (ACE_USES_WCHAR) && defined (ACE_WIN32)
119 return creation_flags_ | CREATE_UNICODE_ENVIRONMENT;
121 return creation_flags_;
122 #endif /* ACE_USES_WCHAR */
126 ACE_Process_Options::creation_flags (u_long cf)
128 creation_flags_ = cf;
132 ACE_Process_Options::getgroup () const
134 return process_group_;
138 ACE_Process_Options::setgroup (pid_t pgrp)
140 pid_t old = process_group_;
141 process_group_ = pgrp;
146 ACE_Process_Options::handle_inheritance ()
148 return handle_inheritance_;
152 ACE_Process_Options::handle_inheritance (int hi)
154 handle_inheritance_ = hi;
158 ACE_Process_Options::avoid_zombies ()
160 return avoid_zombies_;
163 ACE_Process_Options::avoid_zombies (int avoid_zombies)
165 avoid_zombies_ = avoid_zombies;
168 #if defined (ACE_WIN32)
170 ACE_INLINE ACE_TEXT_STARTUPINFO *
171 ACE_Process_Options::startup_info ()
173 return &startup_info_;
176 ACE_INLINE LPSECURITY_ATTRIBUTES
177 ACE_Process_Options::get_process_attributes () const
179 return process_attributes_;
182 ACE_INLINE LPSECURITY_ATTRIBUTES
183 ACE_Process_Options::set_process_attributes ()
185 process_attributes_ = &security_buf1_;
186 return process_attributes_;
189 ACE_INLINE LPSECURITY_ATTRIBUTES
190 ACE_Process_Options::get_thread_attributes () const
192 return thread_attributes_;
195 ACE_INLINE LPSECURITY_ATTRIBUTES
196 ACE_Process_Options::set_thread_attributes ()
198 thread_attributes_ = &security_buf2_;
199 return thread_attributes_;
202 ACE_INLINE HANDLE ACE_Process_Options::get_user_token () const
207 #else /* !defined (ACE_WIN32) */
209 ACE_INLINE ACE_HANDLE
210 ACE_Process_Options::get_stdin () const
215 ACE_INLINE ACE_HANDLE
216 ACE_Process_Options::get_stdout () const
221 ACE_INLINE ACE_HANDLE
222 ACE_Process_Options::get_stderr () const
228 ACE_Process_Options::inherit_environment () const
230 return inherit_environment_;
234 ACE_Process_Options::inherit_environment (bool nv)
236 inherit_environment_ = nv;
240 ACE_Process_Options::setreugid (const ACE_TCHAR* user)
242 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
243 struct passwd *ent = ACE_OS::getpwnam (ACE_TEXT_ALWAYS_CHAR (user));
247 this->euid_ = ent->pw_uid;
248 this->ruid_ = ent->pw_uid;
249 this->egid_ = ent->pw_gid;
250 this->rgid_ = ent->pw_gid;
256 ACE_UNUSED_ARG (user);
257 ACE_NOTSUP_RETURN (-1);
258 #endif /* ACE_LACKS_PWD_FUNCTIONS */
262 ACE_Process_Options::setruid (uid_t id)
268 ACE_Process_Options::seteuid (uid_t id)
274 ACE_Process_Options::setrgid (gid_t id)
280 ACE_Process_Options::setegid (gid_t id)
286 ACE_Process_Options::getruid () const
292 ACE_Process_Options::geteuid () const
298 ACE_Process_Options::getrgid () const
304 ACE_Process_Options::getegid () const
308 #endif /* ACE_WIN32 */
310 ACE_INLINE ACE_TCHAR *
311 ACE_Process_Options::command_line_buf (size_t *max_lenp)
314 *max_lenp = this->command_line_buf_len_;
315 return this->command_line_buf_;
318 ACE_INLINE ACE_TCHAR *
319 ACE_Process_Options::working_directory ()
321 if (working_directory_[0] == '\0')
324 return working_directory_;
328 ACE_Process_Options::working_directory (const char *wd)
330 ACE_OS::strcpy (working_directory_, ACE_TEXT_CHAR_TO_TCHAR (wd));
333 #if defined (ACE_HAS_WCHAR)
335 ACE_Process_Options::working_directory (const wchar_t *wd)
337 ACE_OS::strcpy (working_directory_, ACE_TEXT_WCHAR_TO_TCHAR (wd));
339 #endif /* ACE_HAS_WCHAR */
342 ACE_Process_Options::process_name (const ACE_TCHAR *p)
344 ACE_OS::strcpy (this->process_name_, p);
347 ACE_INLINE const ACE_TCHAR *
348 ACE_Process_Options::process_name ()
350 if (process_name_[0] == '\0')
351 this->process_name (this->command_line_argv ()[0]);
353 return this->process_name_;
356 ACE_END_VERSIONED_NAMESPACE_DECL