diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/process_util.h | 43 | ||||
-rw-r--r-- | base/process_util_posix.cc | 12 | ||||
-rw-r--r-- | base/process_util_unittest.cc | 2 | ||||
-rw-r--r-- | base/process_util_win.cc | 12 | ||||
-rw-r--r-- | base/test/multiprocess_test.cc | 3 |
5 files changed, 36 insertions, 36 deletions
diff --git a/base/process_util.h b/base/process_util.h index 3d06f83..234bb4f 100644 --- a/base/process_util.h +++ b/base/process_util.h @@ -195,8 +195,9 @@ typedef std::vector<std::pair<std::string, std::string> > environment_vector; typedef std::vector<std::pair<int, int> > file_handle_mapping_vector; // Options for launching a subprocess that are passed to LaunchApp(). +// The default constructor constructs the object with default options. struct LaunchOptions { - LaunchOptions() : wait(false), process_handle(NULL), + LaunchOptions() : wait(false), #if defined(OS_WIN) start_hidden(false), inherit_handles(false), as_user(NULL), empty_desktop_name(false) @@ -208,13 +209,6 @@ struct LaunchOptions { // If true, wait for the process to complete. bool wait; - // If non-NULL, will be filled in with the handle of the launched process. - // NOTE: In this case, the caller is responsible for closing the handle so - // that it doesn't leak! Otherwise, the handle will be implicitly - // closed. - // Not especially useful unless |wait| is false. - ProcessHandle* process_handle; - #if defined(OS_WIN) bool start_hidden; @@ -253,7 +247,12 @@ struct LaunchOptions { }; // Launch a process via the command line |cmdline|. -// See the documentation of LaunchOptions for details on launching options. +// See the documentation of LaunchOptions for details on |options|. +// +// If |process_handle| is non-NULL, it will be filled in with the +// handle of the launched process. NOTE: In this case, the caller is +// responsible for closing the handle so that it doesn't leak! +// Otherwise, the process handle will be implicitly closed. // // Unix-specific notes: // - Before launching, all FDs open in the parent process will be marked as @@ -261,7 +260,8 @@ struct LaunchOptions { // - If the first argument on the command line does not contain a slash, // PATH will be searched. (See man execvp.) BASE_API bool LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options); + const LaunchOptions& options, + ProcessHandle* process_handle); #if defined(OS_WIN) @@ -288,7 +288,8 @@ BASE_API bool GetProcessIntegrityLevel(ProcessHandle process, // Example (including literal quotes) // cmdline = "c:\windows\explorer.exe" -foo "c:\bar\" BASE_API bool LaunchProcess(const string16& cmdline, - const LaunchOptions& options); + const LaunchOptions& options, + ProcessHandle* process_handle); // TODO(evan): deprecated; change callers to use LaunchProcess, remove. inline bool LaunchApp(const std::wstring& cmdline, @@ -297,8 +298,7 @@ inline bool LaunchApp(const std::wstring& cmdline, LaunchOptions options; options.wait = wait; options.start_hidden = start_hidden; - options.process_handle = process_handle; - return LaunchProcess(cmdline, options); + return LaunchProcess(cmdline, options, process_handle); } // TODO(evan): deprecated; change callers to use LaunchProcess, remove. @@ -308,9 +308,8 @@ inline bool LaunchAppWithHandleInheritance(const std::wstring& cmdline, LaunchOptions options; options.wait = wait; options.start_hidden = start_hidden; - options.process_handle = process_handle; options.inherit_handles = true; - return LaunchProcess(cmdline, options); + return LaunchProcess(cmdline, options, process_handle); } // TODO(evan): deprecated; change callers to use LaunchProcess, remove. @@ -320,9 +319,8 @@ inline bool LaunchAppAsUser(UserTokenHandle token, ProcessHandle* process_handle) { LaunchOptions options; options.start_hidden = start_hidden; - options.process_handle = process_handle; options.as_user = token; - return LaunchProcess(cmdline, options); + return LaunchProcess(cmdline, options, process_handle); } // TODO(evan): deprecated; change callers to use LaunchProcess, remove. @@ -332,11 +330,10 @@ inline bool LaunchAppAsUser(UserTokenHandle token, bool empty_desktop_name, bool inherit_handles) { LaunchOptions options; options.start_hidden = start_hidden; - options.process_handle = process_handle; options.as_user = token; options.empty_desktop_name = empty_desktop_name; options.inherit_handles = inherit_handles; - return LaunchProcess(cmdline, options); + return LaunchProcess(cmdline, options, process_handle); } #elif defined(OS_POSIX) @@ -345,7 +342,8 @@ inline bool LaunchAppAsUser(UserTokenHandle token, // control the command line arguments directly, but prefer the // CommandLine version if launching Chrome itself. BASE_API bool LaunchProcess(const std::vector<std::string>& argv, - const LaunchOptions& options); + const LaunchOptions& options, + ProcessHandle* process_handle); // AlterEnvironment returns a modified environment vector, constructed from the // given environment and the list of changes given in |changes|. Each key in @@ -365,9 +363,8 @@ inline bool LaunchApp(const CommandLine& cl, bool wait, bool start_hidden, ProcessHandle* process_handle) { LaunchOptions options; options.wait = wait; - options.process_handle = process_handle; - - return LaunchProcess(cl, options); + options.start_hidden = start_hidden; + return LaunchProcess(cl, options, process_handle); } #endif diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc index 0e116de..0fc8c0e 100644 --- a/base/process_util_posix.cc +++ b/base/process_util_posix.cc @@ -528,7 +528,8 @@ char** AlterEnvironment(const environment_vector& changes, } bool LaunchProcess(const std::vector<std::string>& argv, - const LaunchOptions& options) { + const LaunchOptions& options, + ProcessHandle* process_handle) { pid_t pid; InjectiveMultimap fd_shuffle1, fd_shuffle2; if (options.fds_to_remap) { @@ -631,16 +632,17 @@ bool LaunchProcess(const std::vector<std::string>& argv, DPCHECK(ret > 0); } - if (options.process_handle) - *options.process_handle = pid; + if (process_handle) + *process_handle = pid; } return true; } bool LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options) { - return LaunchProcess(cmdline.argv(), options); + const LaunchOptions& options, + ProcessHandle* process_handle) { + return LaunchProcess(cmdline.argv(), options, process_handle); } ProcessMetrics::~ProcessMetrics() { } diff --git a/base/process_util_unittest.cc b/base/process_util_unittest.cc index 826a82b..5256b37 100644 --- a/base/process_util_unittest.cc +++ b/base/process_util_unittest.cc @@ -511,7 +511,7 @@ std::string TestLaunchProcess(const base::environment_vector& env_changes) { options.wait = true; options.environ = &env_changes; options.fds_to_remap = &fds_to_remap; - EXPECT_TRUE(base::LaunchProcess(args, options)); + EXPECT_TRUE(base::LaunchProcess(args, options, NULL)); PCHECK(HANDLE_EINTR(close(fds[1])) == 0); char buf[512]; diff --git a/base/process_util_win.cc b/base/process_util_win.cc index c11878e..9aa7f44 100644 --- a/base/process_util_win.cc +++ b/base/process_util_win.cc @@ -218,7 +218,8 @@ bool GetProcessIntegrityLevel(ProcessHandle process, IntegrityLevel *level) { } bool LaunchProcess(const string16& cmdline, - const LaunchOptions& options) { + const LaunchOptions& options, + ProcessHandle* process_handle) { STARTUPINFO startup_info = {}; startup_info.cb = sizeof(startup_info); if (options.empty_desktop_name) @@ -259,8 +260,8 @@ bool LaunchProcess(const string16& cmdline, WaitForSingleObject(process_info.hProcess, INFINITE); // If the caller wants the process handle, we won't close it. - if (options.process_handle) { - *options.process_handle = process_info.hProcess; + if (process_handle) { + *process_handle = process_info.hProcess; } else { CloseHandle(process_info.hProcess); } @@ -268,8 +269,9 @@ bool LaunchProcess(const string16& cmdline, } bool LaunchProcess(const CommandLine& cmdline, - const LaunchOptions& options) { - return LaunchProcess(cmdline.command_line_string(), options); + const LaunchOptions& options, + ProcessHandle* process_handle) { + return LaunchProcess(cmdline.command_line_string(), options, process_handle); } // Attempts to kill the process identified by the given process diff --git a/base/test/multiprocess_test.cc b/base/test/multiprocess_test.cc index c691b5f..97f335c 100644 --- a/base/test/multiprocess_test.cc +++ b/base/test/multiprocess_test.cc @@ -47,13 +47,12 @@ ProcessHandle MultiProcessTest::SpawnChildImpl( bool debug_on_start) { ProcessHandle handle = kNullProcessHandle; base::LaunchOptions options; - options.process_handle = &handle; #if defined(OS_WIN) options.start_hidden = true; #else options.fds_to_remap = &fds_to_map; #endif - base::LaunchProcess(MakeCmdLine(procname, debug_on_start), options); + base::LaunchProcess(MakeCmdLine(procname, debug_on_start), options, &handle); return handle; } |