diff options
author | harrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-30 02:31:47 +0000 |
---|---|---|
committer | harrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-30 02:31:47 +0000 |
commit | e48ab954b1863e988428db9923e3067db40265ae (patch) | |
tree | 722f6d6393ab0ff7a75fc457b891a2944bc3202e | |
parent | dfad886a1096933b27977025d34eeda6fe64e61a (diff) | |
download | ATCD-e48ab954b1863e988428db9923e3067db40265ae.tar.gz |
Removed the class ACE_Process_Old.
-rw-r--r-- | ace/Process.cpp | 228 | ||||
-rw-r--r-- | ace/Process.h | 92 | ||||
-rw-r--r-- | ace/Process.i | 23 |
3 files changed, 0 insertions, 343 deletions
diff --git a/ace/Process.cpp b/ace/Process.cpp index 3e6dd376221..0e5547a0f44 100644 --- a/ace/Process.cpp +++ b/ace/Process.cpp @@ -306,234 +306,6 @@ ACE_Process::wait (const ACE_Time_Value &tv) // ************************************************************ -int -ACE_Process_Old::wait (void) -{ -#if defined (ACE_WIN32) - return ::WaitForSingleObject (process_info_.hProcess, INFINITE); -#else /* ACE_WIN32 */ - return ACE_OS::waitpid (this->child_id_, 0, 0); -#endif /* ACE_WIN32 */ -} - -ACE_Process_Old::ACE_Process_Old (void) -#if defined (ACE_WIN32) - : set_handles_called_ (0) -#else /* ACE_WIN32 */ - : stdin_ (ACE_INVALID_HANDLE), - stdout_ (ACE_INVALID_HANDLE), - stderr_ (ACE_INVALID_HANDLE), - child_id_ (0) -#endif /* ACE_WIN32 */ -{ -#if defined (ACE_WIN32) - ACE_OS::memset ((void *) &this->startup_info_, - 0, sizeof this->startup_info_); - ACE_OS::memset ((void *) &this->process_info_, - 0, sizeof this->process_info_); - this->startup_info_.cb = sizeof this->startup_info_; -#endif /* ACE_WIN32 */ - this->cwd_[0] = '\0'; -} - -ACE_Process_Old::~ACE_Process_Old (void) -{ -#if defined (ACE_WIN32) - // Just in case <start> wasn't called. - if (this->set_handles_called_) - { - ::CloseHandle (this->startup_info_.hStdInput); - ::CloseHandle (this->startup_info_.hStdOutput); - ::CloseHandle (this->startup_info_.hStdOutput); - this->set_handles_called_ = 0; - } - - // Free resources allocated in kernel. - ACE_OS::close (this->process_info_.hThread); - ACE_OS::close (this->process_info_.hProcess); -#endif /* ACE_WIN32 */ -} - -int -ACE_Process_Old::set_handles (ACE_HANDLE std_in, - ACE_HANDLE std_out, - ACE_HANDLE std_err) -{ -#if defined (ACE_WIN32) - this->set_handles_called_ = 1; - - // Tell the new process to use our std handles. - this->startup_info_.dwFlags = STARTF_USESTDHANDLES; - - if (std_in == ACE_INVALID_HANDLE) - std_in = ACE_STDIN; - if (std_out == ACE_INVALID_HANDLE) - std_out = ACE_STDOUT; - if (std_err == ACE_INVALID_HANDLE) - std_err = ACE_STDERR; - - if (!::DuplicateHandle (::GetCurrentProcess(), - std_in, - ::GetCurrentProcess(), - &this->startup_info_.hStdInput, - NULL, - TRUE, - DUPLICATE_SAME_ACCESS)) - return -1; - - if (!::DuplicateHandle (::GetCurrentProcess(), - std_out, - ::GetCurrentProcess(), - &this->startup_info_.hStdOutput, - NULL, - TRUE, - DUPLICATE_SAME_ACCESS)) - return -1; - - if (!::DuplicateHandle (::GetCurrentProcess(), - std_err, - ::GetCurrentProcess(), - &this->startup_info_.hStdError, - NULL, - TRUE, - DUPLICATE_SAME_ACCESS)) - return -1; -#else /* ACE_WIN32 */ - this->stdin_ = std_in; - this->stdout_ = std_out; - this->stderr_ = std_err; -#endif /* ACE_WIN32 */ - - return 0; // Success. -} - -int -ACE_Process_Old::set_cwd (LPCTSTR cwd) -{ - ACE_OS::strncpy (this->cwd_, cwd, MAXPATHLEN); - // This is for paranoia... - this->cwd_[MAXPATHLEN] = '\0'; - return 0; -} - -pid_t -ACE_Process_Old::start (char *argv[], char *envp[]) -{ -#if defined (ACE_WIN32) - ACE_ARGV argv_buf (argv); - - LPTSTR buf = (LPTSTR) ACE_WIDE_STRING (argv_buf.buf ()); - - if (buf == 0) - return -1; - - // If there is no current working directory, we *MUST* pass 0, not "". - TCHAR *cwd = ACE_OS::strlen (cwd_) == 0 ? 0 : cwd_; - - BOOL fork_result = - ::CreateProcess (NULL, - buf, - NULL, // No process attributes. - NULL, // No thread attributes. - TRUE, // Allow handle inheritance. - NULL, // CREATE_NEW_CONSOLE, // Create a new console window. - envp, // Environment. - cwd, // Current directory to start in. - &this->startup_info_, - &this->process_info_); - - if (set_handles_called_) - { - ::CloseHandle (this->startup_info_.hStdInput); - ::CloseHandle (this->startup_info_.hStdOutput); - ::CloseHandle (this->startup_info_.hStdError); - this->set_handles_called_ = 0; - } - - if (fork_result) // If success. - return 0; - else - // CreateProcess failed. - return -1; -#else /* ACE_WIN32 */ - // Fork the new process. - this->child_id_ = ACE_OS::fork (argv == 0 ? "child" : argv[1]); - - switch (this->child_id_) - { - case -1: - // Error. - return -1; - case 0: - if (stdin_ != ACE_INVALID_HANDLE - && ACE_OS::dup2 (stdin_, ACE_STDIN) == -1) - return -1; - else if (stdout_ != ACE_INVALID_HANDLE - && ACE_OS::dup2 (stdout_, ACE_STDOUT) == -1) - return -1; - else if (stderr_ != ACE_INVALID_HANDLE - && ACE_OS::dup2 (stderr_, ACE_STDERR) == -1) - return -1; - - // If we must, set the working directory for the child process. - if (this->cwd_[0] != '\0') - ::chdir (cwd_); - - if (argv != 0) - { - // Child process executes the command. - int result; - - if (envp == 0) - result = ACE_OS::execvp (argv[0], argv); - else - result = ACE_OS::execve (argv[0], argv, envp); - - if (result == -1) - // If the execv fails, this child needs to exit. - ACE_OS::exit (errno); - } - return 0; - /* NOTREACHED */ - default: - // Server process. The fork succeeded. - return this->child_id_; - } -#endif /* ACE_WIN32 */ -} - -ACE_Process_Old::ACE_Process_Old (char *argv[], - ACE_HANDLE std_in, - ACE_HANDLE std_out, - ACE_HANDLE std_err, - char *envp[]) -#if defined (ACE_WIN32) - : set_handles_called_ (0) -#else /* ACE_WIN32 */ - : stdin_ (ACE_INVALID_HANDLE), - stdout_ (ACE_INVALID_HANDLE), - stderr_ (ACE_INVALID_HANDLE) -#endif /* ACE_WIN32 */ -{ -#if defined (ACE_WIN32) - ACE_OS::memset ((void *) &this->startup_info_, - 0, - sizeof this->startup_info_); - ACE_OS::memset ((void *) &this->process_info_, - 0, - sizeof this->process_info_); - this->startup_info_.cb = sizeof this->startup_info_; -#endif /* ACE_WIN32 */ - this->cwd_[0] = '\0'; - - if (this->set_handles (std_in, std_out, std_err) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "set_handles")); - else if (this->start (argv, envp) == -1) - ACE_ERROR ((LM_ERROR, "%p\n", "start")); -} - -// ************************************************************ - ACE_Process_Options::ACE_Process_Options (int ie, int cobl) : inherit_environment_ (ie), diff --git a/ace/Process.h b/ace/Process.h index 6295c606a63..53181496297 100644 --- a/ace/Process.h +++ b/ace/Process.h @@ -272,98 +272,6 @@ protected: // ************************************************************ -class ACE_Export ACE_Process_Old -// = TITLE -// A Portable encapsulation for creating new processes and -// allows assignment of STDIN, STDOUT, and STDERR of the new -// process. -// -// = DESCRIPTION -// On UNIX, ACE_Process_Old uses fork and exec. On Win32, it uses -// CreateProcess. Since we can set the standard handles, we can -// mimic UNIX pipes on Win32 by building chains of processes. -// This class should be used instead ACE_OS::fork_exec. I'm -// implementing the functionality that I need as I go, instead of -// trying to build an all encompassing process abstraction. If -// anyone needs more functionality, please feel free to add it and -// send us the updates. We'll put it in ACE. -{ -public: - ACE_Process_Old (void); - // Default construction. - - ACE_Process_Old (char *argv[], - ACE_HANDLE std_in, - ACE_HANDLE std_out = ACE_INVALID_HANDLE, - ACE_HANDLE std_err = ACE_INVALID_HANDLE, - char *envp[] = 0); - // Set the standard handles of the new process to the respective - // handles and start the new process (using <execvp>/<execve> on - // UNIX and <CreateProcess> on Win32>). If <argv> is non-NULL it - // should be of the following form: argv = { - // "c:\full\path\to\foo.exe", "-a", "arg1", "etc", 0 }. If <argv> - // is NULL then no <exec> is performed. If <argv> is non-NULL and - // <envp> is specified, it is passed as the environment for the new - // process, according to the rules for execve(). If you want to - // affect a subset of the handles, make sure to set the others to - // ACE_INVALID_HANDLE. - - ~ACE_Process_Old (void); - // Destructor. - - int 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. - - int set_cwd (const TCHAR *cwd); - // Set the working directory for the process. - - pid_t start (char *argv[], char *envp[] = 0); - // Start the new process (using <execvp>/<execve> on UNIX and - // <CreateProcess> on Win32>). If <argv> is non-NULL it should be - // of the following form: argv = { "c:\full\path\to\foo.exe", "-a", - // "arg1", "etc", 0 }. If <argv> is NULL then no <exec> is - // performed. If <argv> is non-NULL and <envp> is specified, it is - // passed as the environment for the new process, according to the - // rules for execve(). Returns the new process id on success, -1 on - // failure. - - int wait (void); - // Wait for the process we just created to exit. - - int kill (int signum = SIGINT); - // Send the process a signal. - - pid_t getpid (void); - // Return the pid of the new process. - -private: -#if defined (ACE_WIN32) - PROCESS_INFORMATION process_info_; - STARTUPINFO startup_info_; - - int set_handles_called_; - // Is 1 if stdhandles was called. - -#else /* ACE_WIN32 */ - ACE_HANDLE stdin_; - ACE_HANDLE stdout_; - ACE_HANDLE stderr_; - - pid_t child_id_; - // Process id of the child. -#endif /* ACE_WIN32 */ - - TCHAR cwd_[MAXPATHLEN + 1]; - // The current working directory. -}; - -// ************************************************************ - class ACE_Export ACE_Tokenizer // = TITLE // Tokenizer diff --git a/ace/Process.i b/ace/Process.i index ef411a61f9e..b52c2ef03d9 100644 --- a/ace/Process.i +++ b/ace/Process.i @@ -33,29 +33,6 @@ ACE_Process::kill (int signum) // ************************************************************ -ACE_INLINE pid_t -ACE_Process_Old::getpid (void) -{ -#if defined (ACE_WIN32) - return process_info_.dwProcessId; -#else /* ACE_WIN32 */ - return child_id_; -#endif /* ACE_WIN32 */ -} - -ACE_INLINE int -ACE_Process_Old::kill (int signum) -{ -#if defined (ACE_WIN32) - ACE_UNUSED_ARG (signum); - return (int) ::TerminateProcess (this->process_info_.hProcess, 0); -#else - return ACE_OS::kill (this->getpid (), signum); -#endif /* ACE_WIN32 */ -} - -// ************************************************************ - #if defined (ACE_WIN32) ACE_INLINE u_long |