Go to the documentation of this file.00001
00002
00003
00004
00005 #include "ace/ACE.h"
00006 #include "ace/OS_NS_sys_wait.h"
00007 #include "ace/OS_NS_signal.h"
00008 #include "ace/OS_NS_pwd.h"
00009 #include "ace/OS_NS_string.h"
00010
00011 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00012
00013 ACE_INLINE void
00014 ACE_Process_Options::enable_unicode_environment (void)
00015 {
00016 this->use_unicode_environment_ = true;
00017 }
00018
00019 ACE_INLINE void
00020 ACE_Process_Options::disable_unicode_environment (void)
00021 {
00022 this->use_unicode_environment_ = false;
00023 }
00024
00025 ACE_INLINE bool
00026 ACE_Process_Options::use_unicode_environment (void) const
00027 {
00028 return this->use_unicode_environment_;
00029 }
00030
00031 #if defined (ACE_WIN32)
00032
00033 ACE_INLINE PROCESS_INFORMATION
00034 ACE_Process::process_info (void)
00035 {
00036 return process_info_;
00037 }
00038 #endif
00039
00040 ACE_INLINE ACE_HANDLE
00041 ACE_Process::gethandle (void) const
00042 {
00043 #if defined (ACE_WIN32)
00044 return process_info_.hProcess;
00045 #else
00046 return ACE_HANDLE (child_id_);
00047 #endif
00048 }
00049
00050 ACE_INLINE pid_t
00051 ACE_Process::getpid (void)
00052 const
00053 {
00054 #if defined (ACE_WIN32)
00055 return process_info_.dwProcessId;
00056 #else
00057 return child_id_;
00058 #endif
00059 }
00060
00061 ACE_INLINE pid_t
00062 ACE_Process::wait (ACE_exitcode *status,
00063 int wait_options)
00064 {
00065 pid_t retv =
00066 ACE_OS::wait (this->getpid (),
00067 &this->exit_code_,
00068 wait_options
00069 #if defined (ACE_WIN32)
00070 , process_info_.hProcess
00071 #endif
00072 );
00073 if (status != 0)
00074 *status = this->exit_code_;
00075
00076 return retv;
00077 }
00078
00079 ACE_INLINE int
00080 ACE_Process::kill (int signum)
00081 {
00082 if (this->getpid () != -1)
00083 return ACE_OS::kill (this->getpid (), signum);
00084 else
00085 return -1;
00086 }
00087
00088 ACE_INLINE int
00089 ACE_Process::terminate (void)
00090 {
00091 if (this->getpid () != -1)
00092 return ACE::terminate_process (this->getpid ());
00093 else
00094 return -1;
00095 }
00096
00097 ACE_INLINE int
00098 ACE_Process::return_value (void) const
00099 {
00100 #if defined (ACE_WIN32)
00101 return this->exit_code_;
00102 #else
00103 return WEXITSTATUS (this->exit_code_);
00104 #endif
00105 }
00106
00107 ACE_INLINE ACE_exitcode
00108 ACE_Process::exit_code (void) const
00109 {
00110 return this->exit_code_;
00111 }
00112
00113 ACE_INLINE void
00114 ACE_Process::exit_code (ACE_exitcode code)
00115 {
00116 this->exit_code_ = code;
00117 }
00118
00119 ACE_INLINE u_long
00120 ACE_Process_Options::creation_flags (void) const
00121 {
00122 #if defined (ACE_USES_WCHAR) && defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00123 return creation_flags_ | CREATE_UNICODE_ENVIRONMENT;
00124 #else
00125 return creation_flags_;
00126 #endif
00127 }
00128
00129 ACE_INLINE void
00130 ACE_Process_Options::creation_flags (u_long cf)
00131 {
00132 creation_flags_ = cf;
00133 }
00134
00135 ACE_INLINE pid_t
00136 ACE_Process_Options::getgroup (void) const
00137 {
00138 return process_group_;
00139 }
00140
00141 ACE_INLINE pid_t
00142 ACE_Process_Options::setgroup (pid_t pgrp)
00143 {
00144 pid_t old = process_group_;
00145 process_group_ = pgrp;
00146 return old;
00147 }
00148
00149 ACE_INLINE int
00150 ACE_Process_Options::handle_inheritance (void)
00151 {
00152 return handle_inheritance_;
00153 }
00154
00155 ACE_INLINE void
00156 ACE_Process_Options::handle_inheritance (int hi)
00157 {
00158 handle_inheritance_ = hi;
00159 }
00160
00161 ACE_INLINE int
00162 ACE_Process_Options::avoid_zombies (void)
00163 {
00164 return avoid_zombies_;
00165 }
00166 ACE_INLINE void
00167 ACE_Process_Options::avoid_zombies (int avoid_zombies)
00168 {
00169 avoid_zombies_ = avoid_zombies;
00170 }
00171
00172 #if defined (ACE_WIN32)
00173
00174 ACE_INLINE ACE_TEXT_STARTUPINFO *
00175 ACE_Process_Options::startup_info (void)
00176 {
00177 #if !defined (ACE_HAS_WINCE)
00178 return &startup_info_;
00179 #else
00180 return 0;
00181 #endif
00182 }
00183
00184 ACE_INLINE LPSECURITY_ATTRIBUTES
00185 ACE_Process_Options::get_process_attributes (void) const
00186 {
00187 #if !defined (ACE_HAS_WINCE)
00188 return process_attributes_;
00189 #else
00190 return 0;
00191 #endif
00192 }
00193
00194 ACE_INLINE LPSECURITY_ATTRIBUTES
00195 ACE_Process_Options::set_process_attributes (void)
00196 {
00197 #if !defined (ACE_HAS_WINCE)
00198 process_attributes_ = &security_buf1_;
00199 return process_attributes_;
00200 #else
00201 return 0;
00202 #endif
00203 }
00204
00205 ACE_INLINE LPSECURITY_ATTRIBUTES
00206 ACE_Process_Options::get_thread_attributes (void) const
00207 {
00208 #if !defined (ACE_HAS_WINCE)
00209 return thread_attributes_;
00210 #else
00211 return 0;
00212 #endif
00213 }
00214
00215 ACE_INLINE LPSECURITY_ATTRIBUTES
00216 ACE_Process_Options::set_thread_attributes (void)
00217 {
00218 #if !defined (ACE_HAS_WINCE)
00219 thread_attributes_ = &security_buf2_;
00220 return thread_attributes_;
00221 #else
00222 return 0;
00223 #endif
00224 }
00225
00226 #else
00227
00228 ACE_INLINE ACE_HANDLE
00229 ACE_Process_Options::get_stdin (void) const
00230 {
00231 return stdin_;
00232 }
00233
00234 ACE_INLINE ACE_HANDLE
00235 ACE_Process_Options::get_stdout (void) const
00236 {
00237 return stdout_;
00238 }
00239
00240 ACE_INLINE ACE_HANDLE
00241 ACE_Process_Options::get_stderr (void) const
00242 {
00243 return stderr_;
00244 }
00245
00246 ACE_INLINE bool
00247 ACE_Process_Options::inherit_environment (void) const
00248 {
00249 return inherit_environment_;
00250 }
00251
00252 ACE_INLINE void
00253 ACE_Process_Options::inherit_environment (bool nv)
00254 {
00255 inherit_environment_ = nv;
00256 }
00257
00258 ACE_INLINE int
00259 ACE_Process_Options::setreugid (const ACE_TCHAR* user)
00260 {
00261 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
00262 struct passwd *ent = ACE_OS::getpwnam (ACE_TEXT_ALWAYS_CHAR (user));
00263
00264 if (ent != 0)
00265 {
00266 this->euid_ = ent->pw_uid;
00267 this->ruid_ = ent->pw_uid;
00268 this->egid_ = ent->pw_gid;
00269 this->rgid_ = ent->pw_gid;
00270 return 0;
00271 }
00272 else
00273 return -1;
00274 #else
00275 ACE_UNUSED_ARG (user);
00276 ACE_NOTSUP_RETURN (-1);
00277 #endif
00278 }
00279
00280 ACE_INLINE void
00281 ACE_Process_Options::setruid (uid_t id)
00282 {
00283 this->ruid_ = id;
00284 }
00285
00286 ACE_INLINE void
00287 ACE_Process_Options::seteuid (uid_t id)
00288 {
00289 this->euid_ = id;
00290 }
00291
00292 ACE_INLINE void
00293 ACE_Process_Options::setrgid (uid_t id)
00294 {
00295 this->rgid_ = id;
00296 }
00297
00298 ACE_INLINE void
00299 ACE_Process_Options::setegid (uid_t id)
00300 {
00301 this->egid_ = id;
00302 }
00303
00304 ACE_INLINE uid_t
00305 ACE_Process_Options::getruid (void) const
00306 {
00307 return this->ruid_;
00308 }
00309
00310 ACE_INLINE uid_t
00311 ACE_Process_Options::geteuid (void) const
00312 {
00313 return this->euid_;
00314 }
00315
00316 ACE_INLINE uid_t
00317 ACE_Process_Options::getrgid (void) const
00318 {
00319 return this->rgid_;
00320 }
00321
00322 ACE_INLINE uid_t
00323 ACE_Process_Options::getegid (void) const
00324 {
00325 return this->egid_;
00326 }
00327 #endif
00328
00329 ACE_INLINE ACE_TCHAR *
00330 ACE_Process_Options::command_line_buf (int *max_lenp)
00331 {
00332 if (max_lenp != 0)
00333 *max_lenp = this->command_line_buf_len_;
00334 return this->command_line_buf_;
00335 }
00336
00337 ACE_INLINE ACE_TCHAR *
00338 ACE_Process_Options::working_directory (void)
00339 {
00340 #if !defined (ACE_HAS_WINCE)
00341 if (working_directory_[0] == '\0')
00342 return 0;
00343 else
00344 return working_directory_;
00345 #else
00346 return 0;
00347 #endif
00348 }
00349
00350 ACE_INLINE void
00351 ACE_Process_Options::working_directory (const char *wd)
00352 {
00353 #if !defined(ACE_HAS_WINCE)
00354 ACE_OS::strcpy (working_directory_, ACE_TEXT_CHAR_TO_TCHAR (wd));
00355 #else
00356 ACE_UNUSED_ARG (wd);
00357 #endif
00358 }
00359
00360 #if defined (ACE_HAS_WCHAR)
00361 ACE_INLINE void
00362 ACE_Process_Options::working_directory (const wchar_t *wd)
00363 {
00364 #if !defined(ACE_HAS_WINCE)
00365 ACE_OS::strcpy (working_directory_, ACE_TEXT_WCHAR_TO_TCHAR (wd));
00366 #else
00367 ACE_UNUSED_ARG (wd);
00368 #endif
00369 }
00370 #endif
00371
00372 ACE_INLINE void
00373 ACE_Process_Options::process_name (const ACE_TCHAR *p)
00374 {
00375 ACE_OS::strcpy (this->process_name_, p);
00376 }
00377
00378 ACE_INLINE const ACE_TCHAR *
00379 ACE_Process_Options::process_name (void)
00380 {
00381 if (process_name_[0] == '\0')
00382 this->process_name (this->command_line_argv ()[0]);
00383
00384 return this->process_name_;
00385 }
00386
00387 #if defined (ACE_HAS_WINCE)
00388
00389
00390
00391 ACE_INLINE int
00392 ACE_Process_Options::setenv (ACE_TCHAR * [])
00393 {
00394 return -1;
00395 }
00396
00397 ACE_INLINE int
00398 ACE_Process_Options::setenv (const ACE_TCHAR * , ...)
00399 {
00400 return -1;
00401 }
00402
00403 ACE_INLINE int
00404 ACE_Process_Options::setenv (const ACE_TCHAR * ,
00405 const ACE_TCHAR * ,
00406 ...)
00407 {
00408 return -1;
00409 }
00410
00411 ACE_INLINE int
00412 ACE_Process_Options::set_handles (ACE_HANDLE ,
00413 ACE_HANDLE ,
00414 ACE_HANDLE )
00415 {
00416 return -1;
00417 }
00418
00419 #endif
00420
00421 ACE_END_VERSIONED_NAMESPACE_DECL