Process.inl

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 //
00003 // Process.inl,v 4.4 2005/10/28 16:14:54 ossama Exp
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 #if defined (ACE_WIN32)
00014 
00015 ACE_INLINE PROCESS_INFORMATION
00016 ACE_Process::process_info (void)
00017 {
00018   return process_info_;
00019 }
00020 #endif /* ACE_WIN32 */
00021 
00022 ACE_INLINE ACE_HANDLE
00023 ACE_Process::gethandle (void) const
00024 {
00025 #if defined (ACE_WIN32)
00026   return process_info_.hProcess;
00027 #else
00028   return ACE_HANDLE (child_id_);
00029 #endif /* ACE_WIN32 */
00030 }
00031 
00032 ACE_INLINE pid_t
00033 ACE_Process::getpid (void)
00034     const
00035 {
00036 #if defined (ACE_WIN32)
00037   return process_info_.dwProcessId;
00038 #else /* ACE_WIN32 */
00039   return child_id_;
00040 #endif /* ACE_WIN32 */
00041 }
00042 
00043 ACE_INLINE pid_t
00044 ACE_Process::wait (ACE_exitcode *status,
00045                    int wait_options)
00046 {
00047   pid_t retv =
00048     ACE_OS::wait (this->getpid (),
00049                   &this->exit_code_,
00050                   wait_options
00051 #if defined (ACE_WIN32)
00052                   , process_info_.hProcess
00053 #endif /* ACE_WIN32 */
00054                   );
00055   if (status != 0)
00056     *status = this->exit_code_;
00057 
00058   return retv;
00059 }
00060 
00061 ACE_INLINE int
00062 ACE_Process::kill (int signum)
00063 {
00064   if (this->getpid () != -1)
00065     return ACE_OS::kill (this->getpid (), signum);
00066   else
00067     return -1;
00068 }
00069 
00070 ACE_INLINE int
00071 ACE_Process::terminate (void)
00072 {
00073   if (this->getpid () != -1)
00074     return ACE::terminate_process (this->getpid ());
00075   else
00076     return -1;
00077 }
00078 
00079 ACE_INLINE int
00080 ACE_Process::return_value (void) const
00081 {
00082 #if defined (ACE_WIN32)
00083   return this->exit_code_;
00084 #else
00085   return WEXITSTATUS (this->exit_code_);
00086 #endif /* ACE_WIN32 */
00087 }
00088 
00089 ACE_INLINE ACE_exitcode
00090 ACE_Process::exit_code (void) const
00091 {
00092   return this->exit_code_;
00093 }
00094 
00095 ACE_INLINE void
00096 ACE_Process::exit_code (ACE_exitcode code)
00097 {
00098   this->exit_code_ = code;
00099 }
00100 
00101 ACE_INLINE u_long
00102 ACE_Process_Options::creation_flags (void) const
00103 {
00104 #if defined (UNICODE) && defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)
00105   return creation_flags_ | CREATE_UNICODE_ENVIRONMENT;
00106 #else
00107   return creation_flags_;
00108 #endif /* UNICODE */
00109 }
00110 
00111 ACE_INLINE void
00112 ACE_Process_Options::creation_flags (u_long cf)
00113 {
00114   creation_flags_ = cf;
00115 }
00116 
00117 ACE_INLINE pid_t
00118 ACE_Process_Options::getgroup (void) const
00119 {
00120   return process_group_;
00121 }
00122 
00123 ACE_INLINE pid_t
00124 ACE_Process_Options::setgroup (pid_t pgrp)
00125 {
00126   pid_t old = process_group_;
00127   process_group_ = pgrp;
00128   return old;
00129 }
00130 
00131 ACE_INLINE int
00132 ACE_Process_Options::handle_inheritence (void)
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 }
00140 
00141 ACE_INLINE void
00142 ACE_Process_Options::handle_inheritence (int hi)
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 }
00151 
00152 ACE_INLINE int
00153 ACE_Process_Options::avoid_zombies (void)
00154 {
00155   return avoid_zombies_;
00156 }
00157 ACE_INLINE void
00158 ACE_Process_Options::avoid_zombies (int avoid_zombies)
00159 {
00160   avoid_zombies_ = avoid_zombies;
00161 }
00162 
00163 #if defined (ACE_WIN32)
00164 
00165 ACE_INLINE ACE_TEXT_STARTUPINFO *
00166 ACE_Process_Options::startup_info (void)
00167 {
00168 #if !defined (ACE_HAS_WINCE)
00169   return &startup_info_;
00170 #else
00171   return 0;
00172 #endif /* !ACE_HAS_WINCE */
00173 }
00174 
00175 ACE_INLINE LPSECURITY_ATTRIBUTES
00176 ACE_Process_Options::get_process_attributes (void) const
00177 {
00178 #if !defined (ACE_HAS_WINCE)
00179   return process_attributes_;
00180 #else
00181   return 0;
00182 #endif /* !ACE_HAS_WINCE */
00183 }
00184 
00185 ACE_INLINE LPSECURITY_ATTRIBUTES
00186 ACE_Process_Options::set_process_attributes (void)
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 }
00195 
00196 ACE_INLINE LPSECURITY_ATTRIBUTES
00197 ACE_Process_Options::get_thread_attributes (void) const
00198 {
00199 #if !defined (ACE_HAS_WINCE)
00200   return thread_attributes_;
00201 #else
00202   return 0;
00203 #endif /* !ACE_HAS_WINCE */
00204 }
00205 
00206 ACE_INLINE LPSECURITY_ATTRIBUTES
00207 ACE_Process_Options::set_thread_attributes (void)
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 }
00216 
00217 #else /* !defined (ACE_WIN32) */
00218 
00219 ACE_INLINE ACE_HANDLE
00220 ACE_Process_Options::get_stdin (void) const
00221 {
00222   return stdin_;
00223 }
00224 
00225 ACE_INLINE ACE_HANDLE
00226 ACE_Process_Options::get_stdout (void) const
00227 {
00228   return stdout_;
00229 }
00230 
00231 ACE_INLINE ACE_HANDLE
00232 ACE_Process_Options::get_stderr (void) const
00233 {
00234   return stderr_;
00235 }
00236 
00237 ACE_INLINE int
00238 ACE_Process_Options::inherit_environment (void) const
00239 {
00240   return inherit_environment_;
00241 }
00242 
00243 ACE_INLINE void
00244 ACE_Process_Options::inherit_environment (int nv)
00245 {
00246   inherit_environment_ = nv;
00247 }
00248 
00249 ACE_INLINE int
00250 ACE_Process_Options::setreugid (const ACE_TCHAR* user)
00251 {
00252 #if !defined (ACE_LACKS_PWD_FUNCTIONS)
00253   struct passwd *ent = ACE_OS::getpwnam (ACE_TEXT_ALWAYS_CHAR (user));
00254 
00255   if (ent != 0)
00256     {
00257       this->euid_ = ent->pw_uid;
00258       this->ruid_ = ent->pw_uid;
00259       this->egid_ = ent->pw_gid;
00260       this->rgid_ = ent->pw_gid;
00261       return 0;
00262     }
00263   else
00264     return -1;
00265 #else
00266   ACE_UNUSED_ARG (user);
00267   ACE_NOTSUP_RETURN (-1);
00268 #endif /* ACE_LACKS_PWD_FUNCTIONS */
00269 }
00270 
00271 ACE_INLINE void
00272 ACE_Process_Options::setruid (uid_t id)
00273 {
00274   this->ruid_ = id;
00275 }
00276 
00277 ACE_INLINE void
00278 ACE_Process_Options::seteuid (uid_t id)
00279 {
00280   this->euid_ = id;
00281 }
00282 
00283 ACE_INLINE void
00284 ACE_Process_Options::setrgid (uid_t id)
00285 {
00286   this->rgid_ = id;
00287 }
00288 
00289 ACE_INLINE void
00290 ACE_Process_Options::setegid (uid_t id)
00291 {
00292   this->egid_ = id;
00293 }
00294 
00295 ACE_INLINE uid_t
00296 ACE_Process_Options::getruid (void) const
00297 {
00298   return this->ruid_;
00299 }
00300 
00301 ACE_INLINE uid_t
00302 ACE_Process_Options::geteuid (void) const
00303 {
00304   return this->euid_;
00305 }
00306 
00307 ACE_INLINE uid_t
00308 ACE_Process_Options::getrgid (void) const
00309 {
00310   return this->rgid_;
00311 }
00312 
00313 ACE_INLINE uid_t
00314 ACE_Process_Options::getegid (void) const
00315 {
00316   return this->egid_;
00317 }
00318 #endif /* ACE_WIN32 */
00319 
00320 ACE_INLINE ACE_TCHAR *
00321 ACE_Process_Options::command_line_buf (int *max_lenp)
00322 {
00323   if (max_lenp != 0)
00324     *max_lenp = this->command_line_buf_len_;
00325   return this->command_line_buf_;
00326 }
00327 
00328 ACE_INLINE ACE_TCHAR *
00329 ACE_Process_Options::working_directory (void)
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 }
00340 
00341 ACE_INLINE void
00342 ACE_Process_Options::working_directory (const char *wd)
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 }
00350 
00351 #if defined (ACE_HAS_WCHAR)
00352 ACE_INLINE void
00353 ACE_Process_Options::working_directory (const wchar_t *wd)
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 }
00361 #endif /* ACE_HAS_WCHAR */
00362 
00363 ACE_INLINE void
00364 ACE_Process_Options::process_name (const ACE_TCHAR *p)
00365 {
00366   ACE_OS::strcpy (this->process_name_, p);
00367 }
00368 
00369 ACE_INLINE const ACE_TCHAR *
00370 ACE_Process_Options::process_name (void)
00371 {
00372   if (process_name_[0] == '\0')
00373     this->process_name (this->command_line_argv ()[0]);
00374 
00375   return this->process_name_;
00376 }
00377 
00378 #if defined (ACE_HAS_WINCE)
00379 // Here is a collection of inline functions which are defined only
00380 // under CE.  They are not empty on most other platforms.
00381 
00382 ACE_INLINE int
00383 ACE_Process_Options::setenv (ACE_TCHAR * /* envp */[])
00384 {
00385   return -1;
00386 }
00387 
00388 ACE_INLINE int
00389 ACE_Process_Options::setenv (const ACE_TCHAR * /* format */, ...)
00390 {
00391   return -1;
00392 }
00393 
00394 ACE_INLINE int
00395 ACE_Process_Options::setenv (const ACE_TCHAR * /* variable_name */,
00396                              const ACE_TCHAR * /* format */,
00397                              ...)
00398 {
00399   return -1;
00400 }
00401 
00402 ACE_INLINE int
00403 ACE_Process_Options::set_handles (ACE_HANDLE /* std_in */,
00404                                   ACE_HANDLE /* std_out */,
00405                                   ACE_HANDLE /* std_err */)
00406 {
00407   return -1;
00408 }
00409 
00410 #endif /* ACE_HAS_WINCE */
00411 
00412 ACE_END_VERSIONED_NAMESPACE_DECL

Generated on Thu Nov 9 09:42:00 2006 for ACE by doxygen 1.3.6