diff options
author | harrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-08 16:26:58 +0000 |
---|---|---|
committer | harrison <harrison@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 1997-05-08 16:26:58 +0000 |
commit | 3bc5fa86ffa427b6c3092d6b3bc2e43a6eff56ec (patch) | |
tree | 4ca82d04cfd7a010766ca1649928b35e50e80305 /ace | |
parent | 230db24aee45e086d91ded35b25c41ad94821805 (diff) | |
download | ATCD-3bc5fa86ffa427b6c3092d6b3bc2e43a6eff56ec.tar.gz |
Compiles (not runs) on Solaris.
Diffstat (limited to 'ace')
-rw-r--r-- | ace/Process.cpp | 62 | ||||
-rw-r--r-- | ace/Process.h | 54 | ||||
-rw-r--r-- | ace/Process.i | 37 |
3 files changed, 114 insertions, 39 deletions
diff --git a/ace/Process.cpp b/ace/Process.cpp index 3553f754eac..c818bbddb09 100644 --- a/ace/Process.cpp +++ b/ace/Process.cpp @@ -233,6 +233,55 @@ ACE_ProcessEx::start (ACE_Process_Options &options) // CreateProcess failed. return -1; #else /* ACE_WIN32 */ + // Fork the new process. + this->child_id_ = ACE_OS::fork (options.path ()); + + switch (this->child_id_) + { + case -1: + // Error. + return -1; + case 0: + // Child process. + { + if (options.get_stdin () != ACE_INVALID_HANDLE + && ACE_OS::dup2 (options.get_stdin (), ACE_STDIN) == -1) + return -1; + else if (options.get_stdout () != ACE_INVALID_HANDLE + && ACE_OS::dup2 (options.get_stdout (), ACE_STDOUT) == -1) + return -1; + else if (options.get_stderr () != ACE_INVALID_HANDLE + && ACE_OS::dup2 (options.get_stderr (), ACE_STDERR) == -1) + return -1; + + // If we must, set the working directory for the child process. + if (options.working_directory () != 0) + ::chdir (options.working_directory ()); + + // Child process executes the command. + int result; + + if (options.env_argv () == 0) + // Not sure if options.path () will work. + result = ACE_OS::execvp (options.path (), + options.cl_options_argv ()); // command-line args + else + result = ACE_OS::execve (options.path (), + options.cl_options_argv (), // command-line args + options.env_argv ()); // environment variables + + if (result == -1) + // If the execv fails, this child needs to exit. + ACE_OS::exit (errno); + + return 0; + } + + default: + // Server process. The fork succeeded. + return this->child_id_; + } + return 0; #endif /* ACE_WIN32 */ } @@ -253,6 +302,7 @@ ACE_ProcessEx::wait (const ACE_Time_Value &tv) #if defined (ACE_WIN32) return ::WaitForSingleObject (process_info_.hProcess, tv.msec ()); #else /* ACE_WIN32 */ + ACE_UNUSED_ARG (tv); ACE_NOTSUP_RETURN (-1); #endif /* ACE_WIN32 */ } @@ -489,15 +539,15 @@ ACE_Process::ACE_Process (char *argv[], ACE_Process_Options::ACE_Process_Options (int ie, int cobl) - : -#if defined (ACE_WIN32) + : cl_options_ (0), inherit_environment_ (ie), - environment_inherited_ (0), +#if defined (ACE_WIN32) handle_inheritence_ (TRUE), new_console_ (FALSE), set_handles_called_ (0), process_attributes_ (NULL), thread_attributes_ (NULL), + environment_inherited_ (0), #else /* ACE_WIN32 */ stdin_ (ACE_INVALID_HANDLE), stdout_ (ACE_INVALID_HANDLE), @@ -505,13 +555,9 @@ ACE_Process_Options::ACE_Process_Options (int ie, #endif /* ACE_WIN32 */ environment_buf_index_ (0), environment_argv_index_ (0), - cl_options_buf_ (0), - cl_options_ (0) + cl_options_buf_ (0) { ACE_NEW (cl_options_, char[cobl]); - - if (cl_options_ == 0) - ACE_ERROR ((LM_ERROR, "%p.\n", "ACE_Process_Options::ACE_Process_Options")); cl_options_[0] = '\0'; working_directory_[0] = '\0'; diff --git a/ace/Process.h b/ace/Process.h index 951846fce54..b31f3b5391a 100644 --- a/ace/Process.h +++ b/ace/Process.h @@ -28,8 +28,10 @@ class ACE_Export ACE_Process_Options // and exec). { public: + enum { DEFAULT_CL_OPTIONS_BUF_LEN = 1024 }; + ACE_Process_Options (int inherit_environment = 1, - int cl_options_buf_len=1024); + int cl_options_buf_len=DEFAULT_CL_OPTIONS_BUF_LEN); // If <inherit_environment> == 1, the new process will inherit the // environment of the current process. <cl_options_buf_len> is the // max strlen for command-line arguments. @@ -106,9 +108,9 @@ public: #if defined (ACE_WIN32) // = Non-portable accessors for when you "just have to use them." - BOOL new_console (void) const; + int new_console (void) const; // Get. - void new_console (BOOL); + void new_console (int); // Set. STARTUPINFO *startup_info (void); @@ -127,15 +129,16 @@ public: // If this is called, a non-null thread attributes is sent to // CreateProcess. - BOOL handle_inheritence (void); + int handle_inheritence (void); // Default is TRUE. - void handle_inheritence (BOOL); + void handle_inheritence (int); // Allows disabling of handle inheritence. #else /* All things not WIN32 */ - ACE_HANDLE std_in (void); - ACE_HANDLE std_out (void); - ACE_HANDLE std_err (void); + // = Accessors for the standard handles. + ACE_HANDLE get_stdin (void); + ACE_HANDLE get_stdout (void); + ACE_HANDLE get_stderr (void); #endif /* ACE_WIN32 */ @@ -151,15 +154,15 @@ protected: MAX_ENVIRONMENT_ARGS = 128 }; + int inherit_environment_; + // Whether the child process inherits the current process + // environment. + #if defined (ACE_WIN32) void inherit_environment (void); // Helper function to grab win32 environment and stick it in // environment_buf_ using this->setenv_i. - int inherit_environment_; - // Whether the child process inherits the current process - // environment. - int environment_inherited_; // Ensures once only call to inherit environment. @@ -409,24 +412,51 @@ private: int index_; struct Preserve_Entry + // = TITLE + // Preserve Entry + // = DESCRIPTION + // Defines a set of characters that designate an area that + // should not be parsed, but should be treated as a complete + // token. For instance, in: (this is a preserve region), start + // would be a left paren -(- and stop would be a right paren + // -)-. The strip determines whether the designators should be + // removed from the token. { char start_; + // E.g., "(". char stop_; + // E.g., ")". int strip_; + // Whether the designators should be removed from the token. }; Preserve_Entry preserves_[MAX_PRESERVES]; + // The application can specify MAX_PRESERVES preserve designators. + int preserves_index_; + // Pointer to the next free spot in preserves_. struct Delimiter_Entry + // = TITLE + // Delimiter Entry + // = DESCRIPTION + // Describes a delimiter for the tokenizer. { char delimiter_; + // Most commonly a space ' '. char replacement_; + // What occurrences of delimiter_ should be replaced with. int replace_; + // Whether replacement_ should be used. This should be replaced + // with a technique that sets replacement_ = delimiter by + // default. I'll do that next iteration. }; Delimiter_Entry delimiters_[MAX_DELIMITERS]; + // The tokenizer allows MAX_DELIMITERS number of delimiters. + int delimiter_index_; + // Pointer to the next free space in delimiters_. }; #if defined (__ACE_INLINE__) diff --git a/ace/Process.i b/ace/Process.i index bcd1f488d6f..6d0859c304f 100644 --- a/ace/Process.i +++ b/ace/Process.i @@ -48,14 +48,14 @@ ACE_Process::kill (int signum) #if defined (ACE_WIN32) -ACE_INLINE BOOL +ACE_INLINE int ACE_Process_Options::new_console (void) const { return new_console_; } ACE_INLINE void -ACE_Process_Options::new_console (BOOL nc) +ACE_Process_Options::new_console (int nc) { new_console_ = nc; } @@ -92,22 +92,35 @@ ACE_Process_Options::set_thread_attributes (void) return thread_attributes_; } + +ACE_INLINE int +ACE_Process_Options::handle_inheritence (void) +{ + return handle_inheritence_; +} + +ACE_INLINE void +ACE_Process_Options::handle_inheritence (int hi) +{ + handle_inheritence_ = hi; +} + #else /* !defined (ACE_WIN32) */ ACE_INLINE ACE_HANDLE -ACE_Process_Options::std_in (void) +ACE_Process_Options::get_stdin (void) { return stdin_; } ACE_INLINE ACE_HANDLE -ACE_Process_Options::std_out (void) +ACE_Process_Options::get_stdout (void) { return stdout_; } ACE_INLINE ACE_HANDLE -ACE_Process_Options::std_err (void) +ACE_Process_Options::get_stderr (void) { return stderr_; } @@ -146,17 +159,3 @@ ACE_Process_Options::path (LPCTSTR p) { ACE_OS::strcpy (path_, p); } - -#if defined (ACE_WIN32) -ACE_INLINE BOOL -ACE_Process_Options::handle_inheritence (void) -{ - return handle_inheritence_; -} - -ACE_INLINE void -ACE_Process_Options::handle_inheritence (BOOL hi) -{ - handle_inheritence_ = hi; -} -#endif /* ACE_WIN32 */ |