summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2013-07-18 11:57:30 +0100
committerBen Murdoch <benm@google.com>2013-07-18 11:57:30 +0100
commit9ab5563a3196760eb381d102cbb2bc0f7abc6a50 (patch)
tree1c690f8b0c998ba536a0c7aeff34764383c7dff6 /base
parent106cdaa9e420b49e5b1ef6941f08dd990128a374 (diff)
downloadchromium_org-9ab5563a3196760eb381d102cbb2bc0f7abc6a50.tar.gz
Merge from Chromium at DEPS revision r212225
This commit was generated by merge_to_master.py. Change-Id: I9b658b6bade7aff6166611a04fb26f4bcf0ca77c
Diffstat (limited to 'base')
-rw-r--r--base/base.gypi14
-rw-r--r--base/base.target.darwin-arm.mk2
-rw-r--r--base/base.target.darwin-mips.mk2
-rw-r--r--base/base.target.darwin-x86.mk2
-rw-r--r--base/base.target.linux-arm.mk2
-rw-r--r--base/base.target.linux-mips.mk2
-rw-r--r--base/base.target.linux-x86.mk2
-rw-r--r--base/process/launch.h258
-rw-r--r--base/process/launch_ios.cc (renamed from base/process_util_ios.mm)11
-rw-r--r--base/process/launch_mac.cc (renamed from base/process_util_mac.mm)34
-rw-r--r--base/process/launch_posix.cc (renamed from base/process_util_posix.cc)2
-rw-r--r--base/process/launch_win.cc (renamed from base/process_util_win.cc)3
-rw-r--r--base/process_util.h278
13 files changed, 283 insertions, 329 deletions
diff --git a/base/base.gypi b/base/base.gypi
index 0808838898..63c2b931c1 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -386,10 +386,6 @@
'process_linux.cc',
'process_posix.cc',
'process_util.h',
- 'process_util_ios.mm',
- 'process_util_mac.mm',
- 'process_util_posix.cc',
- 'process_util_win.cc',
'process_win.cc',
'process/internal_linux.cc',
'process/internal_linux.h',
@@ -398,6 +394,11 @@
'process/kill_mac.cc',
'process/kill_posix.cc',
'process/kill_win.cc',
+ 'process/launch.h',
+ 'process/launch_ios.cc',
+ 'process/launch_mac.cc',
+ 'process/launch_posix.cc',
+ 'process/launch_win.cc',
'process/memory.h',
'process/memory_linux.cc',
'process/memory_mac.mm',
@@ -701,9 +702,8 @@
'posix/unix_domain_socket_linux.cc',
'process/kill_posix.cc',
'process/process_metrics_posix.cc',
+ 'process/launch_posix.cc',
'process_posix.cc',
- 'process_util.cc',
- 'process_util_posix.cc',
'rand_util_posix.cc',
'scoped_native_library.cc',
'files/scoped_temp_dir.cc',
@@ -770,6 +770,8 @@
# needed on iOS (mostly for unit tests).
['exclude', '^process_util'],
['include', '^process_util_ios\\.mm$'],
+ ['exclude', '^process/launch_posix\\.cc$'],
+ ['exclude', '^process/launch_mac\\.cc$'],
['exclude', '^process/memory_mac\\.mm$'],
['include', '^process/process_handle_posix\\.cc$'],
],
diff --git a/base/base.target.darwin-arm.mk b/base/base.target.darwin-arm.mk
index d5cf2d13f0..41fc09fdbb 100644
--- a/base/base.target.darwin-arm.mk
+++ b/base/base.target.darwin-arm.mk
@@ -143,10 +143,10 @@ LOCAL_SRC_FILES := \
base/power_monitor/power_monitor.cc \
base/power_monitor/power_monitor_android.cc \
base/process_posix.cc \
- base/process_util_posix.cc \
base/process/internal_linux.cc \
base/process/kill.cc \
base/process/kill_posix.cc \
+ base/process/launch_posix.cc \
base/process/memory_linux.cc \
base/process/process_handle_linux.cc \
base/process/process_handle_posix.cc \
diff --git a/base/base.target.darwin-mips.mk b/base/base.target.darwin-mips.mk
index 0682c91cf8..31b64123d4 100644
--- a/base/base.target.darwin-mips.mk
+++ b/base/base.target.darwin-mips.mk
@@ -143,10 +143,10 @@ LOCAL_SRC_FILES := \
base/power_monitor/power_monitor.cc \
base/power_monitor/power_monitor_android.cc \
base/process_posix.cc \
- base/process_util_posix.cc \
base/process/internal_linux.cc \
base/process/kill.cc \
base/process/kill_posix.cc \
+ base/process/launch_posix.cc \
base/process/memory_linux.cc \
base/process/process_handle_linux.cc \
base/process/process_handle_posix.cc \
diff --git a/base/base.target.darwin-x86.mk b/base/base.target.darwin-x86.mk
index 2955e4e379..f1adb451d1 100644
--- a/base/base.target.darwin-x86.mk
+++ b/base/base.target.darwin-x86.mk
@@ -144,10 +144,10 @@ LOCAL_SRC_FILES := \
base/power_monitor/power_monitor.cc \
base/power_monitor/power_monitor_android.cc \
base/process_posix.cc \
- base/process_util_posix.cc \
base/process/internal_linux.cc \
base/process/kill.cc \
base/process/kill_posix.cc \
+ base/process/launch_posix.cc \
base/process/memory_linux.cc \
base/process/process_handle_linux.cc \
base/process/process_handle_posix.cc \
diff --git a/base/base.target.linux-arm.mk b/base/base.target.linux-arm.mk
index d5cf2d13f0..41fc09fdbb 100644
--- a/base/base.target.linux-arm.mk
+++ b/base/base.target.linux-arm.mk
@@ -143,10 +143,10 @@ LOCAL_SRC_FILES := \
base/power_monitor/power_monitor.cc \
base/power_monitor/power_monitor_android.cc \
base/process_posix.cc \
- base/process_util_posix.cc \
base/process/internal_linux.cc \
base/process/kill.cc \
base/process/kill_posix.cc \
+ base/process/launch_posix.cc \
base/process/memory_linux.cc \
base/process/process_handle_linux.cc \
base/process/process_handle_posix.cc \
diff --git a/base/base.target.linux-mips.mk b/base/base.target.linux-mips.mk
index 0682c91cf8..31b64123d4 100644
--- a/base/base.target.linux-mips.mk
+++ b/base/base.target.linux-mips.mk
@@ -143,10 +143,10 @@ LOCAL_SRC_FILES := \
base/power_monitor/power_monitor.cc \
base/power_monitor/power_monitor_android.cc \
base/process_posix.cc \
- base/process_util_posix.cc \
base/process/internal_linux.cc \
base/process/kill.cc \
base/process/kill_posix.cc \
+ base/process/launch_posix.cc \
base/process/memory_linux.cc \
base/process/process_handle_linux.cc \
base/process/process_handle_posix.cc \
diff --git a/base/base.target.linux-x86.mk b/base/base.target.linux-x86.mk
index 2955e4e379..f1adb451d1 100644
--- a/base/base.target.linux-x86.mk
+++ b/base/base.target.linux-x86.mk
@@ -144,10 +144,10 @@ LOCAL_SRC_FILES := \
base/power_monitor/power_monitor.cc \
base/power_monitor/power_monitor_android.cc \
base/process_posix.cc \
- base/process_util_posix.cc \
base/process/internal_linux.cc \
base/process/kill.cc \
base/process/kill_posix.cc \
+ base/process/launch_posix.cc \
base/process/memory_linux.cc \
base/process/process_handle_linux.cc \
base/process/process_handle_posix.cc \
diff --git a/base/process/launch.h b/base/process/launch.h
new file mode 100644
index 0000000000..45b10537b8
--- /dev/null
+++ b/base/process/launch.h
@@ -0,0 +1,258 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// This file contains functions for launching subprocesses.
+
+#ifndef BASE_PROCESS_LAUNCH_H_
+#define BASE_PROCESS_LAUNCH_H_
+
+#include <set>
+#include <string>
+#include <utility>
+#include <vector>
+
+#include "base/base_export.h"
+#include "base/basictypes.h"
+#include "base/process/process_handle.h"
+
+#if defined(OS_POSIX)
+#include "base/posix/file_descriptor_shuffle.h"
+#elif defined(OS_WIN)
+#include <windows.h>
+#endif
+
+class CommandLine;
+
+namespace base {
+
+typedef std::vector<std::pair<std::string, std::string> > EnvironmentVector;
+typedef std::vector<std::pair<int, int> > FileHandleMappingVector;
+
+// Options for launching a subprocess that are passed to LaunchProcess().
+// The default constructor constructs the object with default options.
+struct LaunchOptions {
+ LaunchOptions()
+ : wait(false),
+#if defined(OS_WIN)
+ start_hidden(false),
+ inherit_handles(false),
+ as_user(NULL),
+ empty_desktop_name(false),
+ job_handle(NULL),
+ stdin_handle(NULL),
+ stdout_handle(NULL),
+ stderr_handle(NULL),
+ force_breakaway_from_job_(false)
+#else
+ environ(NULL),
+ fds_to_remap(NULL),
+ maximize_rlimits(NULL),
+ new_process_group(false)
+#if defined(OS_LINUX)
+ , clone_flags(0)
+#endif // OS_LINUX
+#if defined(OS_CHROMEOS)
+ , ctrl_terminal_fd(-1)
+#endif // OS_CHROMEOS
+#endif // !defined(OS_WIN)
+ {}
+
+ // If true, wait for the process to complete.
+ bool wait;
+
+#if defined(OS_WIN)
+ bool start_hidden;
+
+ // If true, the new process inherits handles from the parent. In production
+ // code this flag should be used only when running short-lived, trusted
+ // binaries, because open handles from other libraries and subsystems will
+ // leak to the child process, causing errors such as open socket hangs.
+ bool inherit_handles;
+
+ // If non-NULL, runs as if the user represented by the token had launched it.
+ // Whether the application is visible on the interactive desktop depends on
+ // the token belonging to an interactive logon session.
+ //
+ // To avoid hard to diagnose problems, when specified this loads the
+ // environment variables associated with the user and if this operation fails
+ // the entire call fails as well.
+ UserTokenHandle as_user;
+
+ // If true, use an empty string for the desktop name.
+ bool empty_desktop_name;
+
+ // If non-NULL, launches the application in that job object. The process will
+ // be terminated immediately and LaunchProcess() will fail if assignment to
+ // the job object fails.
+ HANDLE job_handle;
+
+ // Handles for the redirection of stdin, stdout and stderr. The handles must
+ // be inheritable. Caller should either set all three of them or none (i.e.
+ // there is no way to redirect stderr without redirecting stdin). The
+ // |inherit_handles| flag must be set to true when redirecting stdio stream.
+ HANDLE stdin_handle;
+ HANDLE stdout_handle;
+ HANDLE stderr_handle;
+
+ // If set to true, ensures that the child process is launched with the
+ // CREATE_BREAKAWAY_FROM_JOB flag which allows it to breakout of the parent
+ // job if any.
+ bool force_breakaway_from_job_;
+#else
+ // If non-NULL, set/unset environment variables.
+ // See documentation of AlterEnvironment().
+ // This pointer is owned by the caller and must live through the
+ // call to LaunchProcess().
+ const EnvironmentVector* environ;
+
+ // If non-NULL, remap file descriptors according to the mapping of
+ // src fd->dest fd to propagate FDs into the child process.
+ // This pointer is owned by the caller and must live through the
+ // call to LaunchProcess().
+ const FileHandleMappingVector* fds_to_remap;
+
+ // Each element is an RLIMIT_* constant that should be raised to its
+ // rlim_max. This pointer is owned by the caller and must live through
+ // the call to LaunchProcess().
+ const std::set<int>* maximize_rlimits;
+
+ // If true, start the process in a new process group, instead of
+ // inheriting the parent's process group. The pgid of the child process
+ // will be the same as its pid.
+ bool new_process_group;
+
+#if defined(OS_LINUX)
+ // If non-zero, start the process using clone(), using flags as provided.
+ int clone_flags;
+#endif // defined(OS_LINUX)
+
+#if defined(OS_CHROMEOS)
+ // If non-negative, the specified file descriptor will be set as the launched
+ // process' controlling terminal.
+ int ctrl_terminal_fd;
+#endif // defined(OS_CHROMEOS)
+
+#endif // !defined(OS_WIN)
+};
+
+// Launch a process via the command line |cmdline|.
+// See the documentation of LaunchOptions for details on |options|.
+//
+// Returns true upon success.
+//
+// Upon success, 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:
+// - All file descriptors open in the parent process will be closed in the
+// child process except for any preserved by options::fds_to_remap, and
+// stdin, stdout, and stderr. If not remapped by options::fds_to_remap,
+// stdin is reopened as /dev/null, and the child is allowed to inherit its
+// parent's stdout and stderr.
+// - If the first argument on the command line does not contain a slash,
+// PATH will be searched. (See man execvp.)
+BASE_EXPORT bool LaunchProcess(const CommandLine& cmdline,
+ const LaunchOptions& options,
+ ProcessHandle* process_handle);
+
+#if defined(OS_WIN)
+// Windows-specific LaunchProcess that takes the command line as a
+// string. Useful for situations where you need to control the
+// command line arguments directly, but prefer the CommandLine version
+// if launching Chrome itself.
+//
+// The first command line argument should be the path to the process,
+// and don't forget to quote it.
+//
+// Example (including literal quotes)
+// cmdline = "c:\windows\explorer.exe" -foo "c:\bar\"
+BASE_EXPORT bool LaunchProcess(const string16& cmdline,
+ const LaunchOptions& options,
+ ProcessHandle* process_handle);
+
+#elif defined(OS_POSIX)
+// A POSIX-specific version of LaunchProcess that takes an argv array
+// instead of a CommandLine. Useful for situations where you need to
+// control the command line arguments directly, but prefer the
+// CommandLine version if launching Chrome itself.
+BASE_EXPORT bool LaunchProcess(const std::vector<std::string>& argv,
+ 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
+// the environment is matched against the first element of the pairs. In the
+// event of a match, the value is replaced by the second of the pair, unless
+// the second is empty, in which case the key-value is removed.
+//
+// The returned array is allocated using new[] and must be freed by the caller.
+BASE_EXPORT char** AlterEnvironment(const EnvironmentVector& changes,
+ const char* const* const env);
+
+// Close all file descriptors, except those which are a destination in the
+// given multimap. Only call this function in a child process where you know
+// that there aren't any other threads.
+BASE_EXPORT void CloseSuperfluousFds(const InjectiveMultimap& saved_map);
+#endif // defined(OS_POSIX)
+
+#if defined(OS_WIN)
+// Set JOBOBJECT_EXTENDED_LIMIT_INFORMATION to JobObject |job_object|.
+// As its limit_info.BasicLimitInformation.LimitFlags has
+// JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE.
+// When the provide JobObject |job_object| is closed, the binded process will
+// be terminated.
+BASE_EXPORT bool SetJobObjectAsKillOnJobClose(HANDLE job_object);
+
+// Output multi-process printf, cout, cerr, etc to the cmd.exe console that ran
+// chrome. This is not thread-safe: only call from main thread.
+BASE_EXPORT void RouteStdioToConsole();
+#endif // defined(OS_WIN)
+
+// Executes the application specified by |cl| and wait for it to exit. Stores
+// the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true
+// on success (application launched and exited cleanly, with exit code
+// indicating success).
+BASE_EXPORT bool GetAppOutput(const CommandLine& cl, std::string* output);
+
+#if defined(OS_POSIX)
+// A POSIX-specific version of GetAppOutput that takes an argv array
+// instead of a CommandLine. Useful for situations where you need to
+// control the command line arguments directly.
+BASE_EXPORT bool GetAppOutput(const std::vector<std::string>& argv,
+ std::string* output);
+
+// A restricted version of |GetAppOutput()| which (a) clears the environment,
+// and (b) stores at most |max_output| bytes; also, it doesn't search the path
+// for the command.
+BASE_EXPORT bool GetAppOutputRestricted(const CommandLine& cl,
+ std::string* output, size_t max_output);
+
+// A version of |GetAppOutput()| which also returns the exit code of the
+// executed command. Returns true if the application runs and exits cleanly. If
+// this is the case the exit code of the application is available in
+// |*exit_code|.
+BASE_EXPORT bool GetAppOutputWithExitCode(const CommandLine& cl,
+ std::string* output, int* exit_code);
+#endif // defined(OS_POSIX)
+
+// If supported on the platform, and the user has sufficent rights, increase
+// the current process's scheduling priority to a high priority.
+BASE_EXPORT void RaiseProcessToHighPriority();
+
+#if defined(OS_MACOSX)
+// Restore the default exception handler, setting it to Apple Crash Reporter
+// (ReportCrash). When forking and execing a new process, the child will
+// inherit the parent's exception ports, which may be set to the Breakpad
+// instance running inside the parent. The parent's Breakpad instance should
+// not handle the child's exceptions. Calling RestoreDefaultExceptionHandler
+// in the child after forking will restore the standard exception handler.
+// See http://crbug.com/20371/ for more details.
+void RestoreDefaultExceptionHandler();
+#endif // defined(OS_MACOSX)
+
+} // namespace base
+
+#endif // BASE_PROCESS_LAUNCH_H_
diff --git a/base/process_util_ios.mm b/base/process/launch_ios.cc
index 3064c9567f..3c700f8f0a 100644
--- a/base/process_util_ios.mm
+++ b/base/process/launch_ios.cc
@@ -2,16 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/process_util.h"
-
-#import <Foundation/Foundation.h>
-#include <stdio.h>
-#include <sys/resource.h>
-
-#include "base/logging.h"
-
-// This is just enough of a shim to let the support needed by test_support
-// link. In general, process_util isn't valid on iOS.
+#include "base/process/launch.h"
namespace base {
diff --git a/base/process_util_mac.mm b/base/process/launch_mac.cc
index 964a3d20aa..176edca72e 100644
--- a/base/process_util_mac.mm
+++ b/base/process/launch_mac.cc
@@ -2,41 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/process_util.h"
+#include "base/process/launch.h"
-#import <Cocoa/Cocoa.h>
-#include <crt_externs.h>
-#include <errno.h>
#include <mach/mach.h>
-#include <mach/mach_init.h>
-#include <mach/mach_vm.h>
-#include <mach/shared_region.h>
-#include <mach/task.h>
-#include <malloc/malloc.h>
-#import <objc/runtime.h>
-#include <signal.h>
-#include <spawn.h>
-#include <sys/event.h>
-#include <sys/sysctl.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include <new>
-#include <string>
-
-#include "base/containers/hash_tables.h"
-#include "base/debug/debugger.h"
-#include "base/file_util.h"
-#include "base/lazy_instance.h"
-#include "base/logging.h"
-#include "base/mac/mac_util.h"
-#include "base/mac/scoped_mach_port.h"
-#include "base/posix/eintr_wrapper.h"
-#include "base/scoped_clear_errno.h"
-#include "base/strings/string_util.h"
-#include "base/sys_info.h"
-#include "third_party/apple_apsl/CFBase.h"
-#include "third_party/apple_apsl/malloc.h"
namespace base {
diff --git a/base/process_util_posix.cc b/base/process/launch_posix.cc
index 5b5121022b..336633c305 100644
--- a/base/process_util_posix.cc
+++ b/base/process/launch_posix.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/process/launch.h"
+
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
diff --git a/base/process_util_win.cc b/base/process/launch_win.cc
index 480cf8bc5a..41477f7408 100644
--- a/base/process_util_win.cc
+++ b/base/process/launch_win.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/process_util.h"
+#include "base/process/launch.h"
#include <fcntl.h>
#include <io.h>
@@ -20,6 +20,7 @@
#include "base/memory/scoped_ptr.h"
#include "base/message_loop.h"
#include "base/metrics/histogram.h"
+#include "base/process/kill.h"
#include "base/sys_info.h"
#include "base/win/object_watcher.h"
#include "base/win/scoped_handle.h"
diff --git a/base/process_util.h b/base/process_util.h
index 111943ed37..1c980c3abd 100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -1,286 +1,18 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-// This file/namespace contains utility functions for enumerating, ending and
-// computing statistics of processes.
+// Forwarding header until all include paths can be updated.
+// TODO(rsesek): Remove this file <http://crbug.com/242290>.
#ifndef BASE_PROCESS_UTIL_H_
#define BASE_PROCESS_UTIL_H_
-#include "base/basictypes.h"
-#include "base/time/time.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#include <tlhelp32.h>
-#elif defined(OS_MACOSX) || defined(OS_BSD)
-// malloc_zone_t is defined in <malloc/malloc.h>, but this forward declaration
-// is sufficient for GetPurgeableZone() below.
-typedef struct _malloc_zone_t malloc_zone_t;
-#if !defined(OS_BSD)
-#include <mach/mach.h>
-#endif
-#elif defined(OS_POSIX)
-#include <dirent.h>
-#include <limits.h>
-#include <sys/types.h>
-#endif
-
-#include <list>
-#include <set>
-#include <string>
-#include <utility>
-#include <vector>
-
-#include "base/base_export.h"
-#include "base/files/file_path.h"
-#include "base/process.h"
-#include "base/process/memory.h"
#include "base/process/kill.h"
+#include "base/process/launch.h"
+#include "base/process/memory.h"
#include "base/process/process_handle.h"
#include "base/process/process_iterator.h"
#include "base/process/process_metrics.h"
-#if defined(OS_POSIX)
-#include "base/posix/file_descriptor_shuffle.h"
-#endif
-
-class CommandLine;
-
-namespace base {
-
-#if defined(OS_WIN)
-// Output multi-process printf, cout, cerr, etc to the cmd.exe console that ran
-// chrome. This is not thread-safe: only call from main thread.
-BASE_EXPORT void RouteStdioToConsole();
-#endif
-
-#if defined(OS_POSIX)
-// Close all file descriptors, except those which are a destination in the
-// given multimap. Only call this function in a child process where you know
-// that there aren't any other threads.
-BASE_EXPORT void CloseSuperfluousFds(const InjectiveMultimap& saved_map);
-#endif // defined(OS_POSIX)
-
-typedef std::vector<std::pair<std::string, std::string> > EnvironmentVector;
-typedef std::vector<std::pair<int, int> > FileHandleMappingVector;
-
-// Options for launching a subprocess that are passed to LaunchProcess().
-// The default constructor constructs the object with default options.
-struct LaunchOptions {
- LaunchOptions()
- : wait(false),
-#if defined(OS_WIN)
- start_hidden(false),
- inherit_handles(false),
- as_user(NULL),
- empty_desktop_name(false),
- job_handle(NULL),
- stdin_handle(NULL),
- stdout_handle(NULL),
- stderr_handle(NULL),
- force_breakaway_from_job_(false)
-#else
- environ(NULL),
- fds_to_remap(NULL),
- maximize_rlimits(NULL),
- new_process_group(false)
-#if defined(OS_LINUX)
- , clone_flags(0)
-#endif // OS_LINUX
-#if defined(OS_CHROMEOS)
- , ctrl_terminal_fd(-1)
-#endif // OS_CHROMEOS
-#endif // !defined(OS_WIN)
- {}
-
- // If true, wait for the process to complete.
- bool wait;
-
-#if defined(OS_WIN)
- bool start_hidden;
-
- // If true, the new process inherits handles from the parent. In production
- // code this flag should be used only when running short-lived, trusted
- // binaries, because open handles from other libraries and subsystems will
- // leak to the child process, causing errors such as open socket hangs.
- bool inherit_handles;
-
- // If non-NULL, runs as if the user represented by the token had launched it.
- // Whether the application is visible on the interactive desktop depends on
- // the token belonging to an interactive logon session.
- //
- // To avoid hard to diagnose problems, when specified this loads the
- // environment variables associated with the user and if this operation fails
- // the entire call fails as well.
- UserTokenHandle as_user;
-
- // If true, use an empty string for the desktop name.
- bool empty_desktop_name;
-
- // If non-NULL, launches the application in that job object. The process will
- // be terminated immediately and LaunchProcess() will fail if assignment to
- // the job object fails.
- HANDLE job_handle;
-
- // Handles for the redirection of stdin, stdout and stderr. The handles must
- // be inheritable. Caller should either set all three of them or none (i.e.
- // there is no way to redirect stderr without redirecting stdin). The
- // |inherit_handles| flag must be set to true when redirecting stdio stream.
- HANDLE stdin_handle;
- HANDLE stdout_handle;
- HANDLE stderr_handle;
-
- // If set to true, ensures that the child process is launched with the
- // CREATE_BREAKAWAY_FROM_JOB flag which allows it to breakout of the parent
- // job if any.
- bool force_breakaway_from_job_;
-#else
- // If non-NULL, set/unset environment variables.
- // See documentation of AlterEnvironment().
- // This pointer is owned by the caller and must live through the
- // call to LaunchProcess().
- const EnvironmentVector* environ;
-
- // If non-NULL, remap file descriptors according to the mapping of
- // src fd->dest fd to propagate FDs into the child process.
- // This pointer is owned by the caller and must live through the
- // call to LaunchProcess().
- const FileHandleMappingVector* fds_to_remap;
-
- // Each element is an RLIMIT_* constant that should be raised to its
- // rlim_max. This pointer is owned by the caller and must live through
- // the call to LaunchProcess().
- const std::set<int>* maximize_rlimits;
-
- // If true, start the process in a new process group, instead of
- // inheriting the parent's process group. The pgid of the child process
- // will be the same as its pid.
- bool new_process_group;
-
-#if defined(OS_LINUX)
- // If non-zero, start the process using clone(), using flags as provided.
- int clone_flags;
-#endif // defined(OS_LINUX)
-
-#if defined(OS_CHROMEOS)
- // If non-negative, the specified file descriptor will be set as the launched
- // process' controlling terminal.
- int ctrl_terminal_fd;
-#endif // defined(OS_CHROMEOS)
-
-#endif // !defined(OS_WIN)
-};
-
-// Launch a process via the command line |cmdline|.
-// See the documentation of LaunchOptions for details on |options|.
-//
-// Returns true upon success.
-//
-// Upon success, 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:
-// - All file descriptors open in the parent process will be closed in the
-// child process except for any preserved by options::fds_to_remap, and
-// stdin, stdout, and stderr. If not remapped by options::fds_to_remap,
-// stdin is reopened as /dev/null, and the child is allowed to inherit its
-// parent's stdout and stderr.
-// - If the first argument on the command line does not contain a slash,
-// PATH will be searched. (See man execvp.)
-BASE_EXPORT bool LaunchProcess(const CommandLine& cmdline,
- const LaunchOptions& options,
- ProcessHandle* process_handle);
-
-#if defined(OS_WIN)
-// Windows-specific LaunchProcess that takes the command line as a
-// string. Useful for situations where you need to control the
-// command line arguments directly, but prefer the CommandLine version
-// if launching Chrome itself.
-//
-// The first command line argument should be the path to the process,
-// and don't forget to quote it.
-//
-// Example (including literal quotes)
-// cmdline = "c:\windows\explorer.exe" -foo "c:\bar\"
-BASE_EXPORT bool LaunchProcess(const string16& cmdline,
- const LaunchOptions& options,
- ProcessHandle* process_handle);
-
-#elif defined(OS_POSIX)
-// A POSIX-specific version of LaunchProcess that takes an argv array
-// instead of a CommandLine. Useful for situations where you need to
-// control the command line arguments directly, but prefer the
-// CommandLine version if launching Chrome itself.
-BASE_EXPORT bool LaunchProcess(const std::vector<std::string>& argv,
- 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
-// the environment is matched against the first element of the pairs. In the
-// event of a match, the value is replaced by the second of the pair, unless
-// the second is empty, in which case the key-value is removed.
-//
-// The returned array is allocated using new[] and must be freed by the caller.
-BASE_EXPORT char** AlterEnvironment(const EnvironmentVector& changes,
- const char* const* const env);
-#endif // defined(OS_POSIX)
-
-#if defined(OS_WIN)
-// Set JOBOBJECT_EXTENDED_LIMIT_INFORMATION to JobObject |job_object|.
-// As its limit_info.BasicLimitInformation.LimitFlags has
-// JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE.
-// When the provide JobObject |job_object| is closed, the binded process will
-// be terminated.
-BASE_EXPORT bool SetJobObjectAsKillOnJobClose(HANDLE job_object);
-#endif // defined(OS_WIN)
-
-// Executes the application specified by |cl| and wait for it to exit. Stores
-// the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true
-// on success (application launched and exited cleanly, with exit code
-// indicating success).
-BASE_EXPORT bool GetAppOutput(const CommandLine& cl, std::string* output);
-
-#if defined(OS_POSIX)
-// A POSIX-specific version of GetAppOutput that takes an argv array
-// instead of a CommandLine. Useful for situations where you need to
-// control the command line arguments directly.
-BASE_EXPORT bool GetAppOutput(const std::vector<std::string>& argv,
- std::string* output);
-
-// A restricted version of |GetAppOutput()| which (a) clears the environment,
-// and (b) stores at most |max_output| bytes; also, it doesn't search the path
-// for the command.
-BASE_EXPORT bool GetAppOutputRestricted(const CommandLine& cl,
- std::string* output, size_t max_output);
-
-// A version of |GetAppOutput()| which also returns the exit code of the
-// executed command. Returns true if the application runs and exits cleanly. If
-// this is the case the exit code of the application is available in
-// |*exit_code|.
-BASE_EXPORT bool GetAppOutputWithExitCode(const CommandLine& cl,
- std::string* output, int* exit_code);
-#endif // defined(OS_POSIX)
-
-// If supported on the platform, and the user has sufficent rights, increase
-// the current process's scheduling priority to a high priority.
-BASE_EXPORT void RaiseProcessToHighPriority();
-
-#if defined(OS_MACOSX)
-// Restore the default exception handler, setting it to Apple Crash Reporter
-// (ReportCrash). When forking and execing a new process, the child will
-// inherit the parent's exception ports, which may be set to the Breakpad
-// instance running inside the parent. The parent's Breakpad instance should
-// not handle the child's exceptions. Calling RestoreDefaultExceptionHandler
-// in the child after forking will restore the standard exception handler.
-// See http://crbug.com/20371/ for more details.
-void RestoreDefaultExceptionHandler();
-#endif // defined(OS_MACOSX)
-
-} // namespace base
-
#endif // BASE_PROCESS_UTIL_H_