Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2686)

Unified Diff: base/process/launch_posix.cc

Issue 885423003: Add the ability to change directories before execing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove redundant POSIX ifdef. Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/process/launch.h ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/process/launch_posix.cc
diff --git a/base/process/launch_posix.cc b/base/process/launch_posix.cc
index ce93d5056fd838bf332da563186c5bc704130e22..203b7c8b9a71830f3a21e72e6700695dbdc76aef 100644
--- a/base/process/launch_posix.cc
+++ b/base/process/launch_posix.cc
@@ -347,7 +347,12 @@ Process LaunchProcess(const std::vector<std::string>& argv,
fd_shuffle1.reserve(fd_shuffle_size);
fd_shuffle2.reserve(fd_shuffle_size);
- scoped_ptr<char*[]> argv_cstr(new char*[argv.size() + 1]);
+ scoped_ptr<char* []> argv_cstr(new char* [argv.size() + 1]);
+ for (size_t i = 0; i < argv.size(); i++) {
+ argv_cstr[i] = const_cast<char*>(argv[i].c_str());
+ }
+ argv_cstr[argv.size()] = NULL;
+
scoped_ptr<char*[]> new_environ;
char* const empty_environ = NULL;
char* const* old_environ = GetEnvironment();
@@ -360,6 +365,11 @@ Process LaunchProcess(const std::vector<std::string>& argv,
sigfillset(&full_sigset);
const sigset_t orig_sigmask = SetSignalMask(full_sigset);
+ const char* current_directory = nullptr;
+ if (!options.current_directory.empty()) {
+ current_directory = options.current_directory.value().c_str();
+ }
+
pid_t pid;
#if defined(OS_LINUX)
if (options.clone_flags) {
@@ -515,15 +525,14 @@ Process LaunchProcess(const std::vector<std::string>& argv,
}
#endif
-#if defined(OS_POSIX)
+ if (current_directory != nullptr) {
+ RAW_CHECK(chdir(current_directory) == 0);
+ }
+
if (options.pre_exec_delegate != nullptr) {
options.pre_exec_delegate->RunAsyncSafe();
}
-#endif
- for (size_t i = 0; i < argv.size(); i++)
- argv_cstr[i] = const_cast<char*>(argv[i].c_str());
- argv_cstr[argv.size()] = NULL;
execvp(argv_cstr[0], argv_cstr.get());
RAW_LOG(ERROR, "LaunchProcess: failed to execvp:");
« no previous file with comments | « base/process/launch.h ('k') | base/process/process_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698