summaryrefslogtreecommitdiffstats
path: root/base/process_util_linux.cc
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-18 16:17:22 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-18 16:17:22 +0000
commitd940627c90386df7844092dae635ed2f20535f28 (patch)
tree34a32b11a9db6f69fef27e7e81863d82a29bcd2d /base/process_util_linux.cc
parent07ca9113c5c8d889e5f46cb059eb5a5ed6f51475 (diff)
downloadchromium_src-d940627c90386df7844092dae635ed2f20535f28.zip
chromium_src-d940627c90386df7844092dae635ed2f20535f28.tar.gz
chromium_src-d940627c90386df7844092dae635ed2f20535f28.tar.bz2
Cleanup in LaunchApp:
- don't copy argv strings - use pid_t instead of int - simplify the control flow a bit Review URL: http://codereview.chromium.org/77024 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14004 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/process_util_linux.cc')
-rw-r--r--base/process_util_linux.cc28
1 files changed, 11 insertions, 17 deletions
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index dcac3bd..faec590 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -31,20 +31,14 @@ namespace base {
bool LaunchApp(const std::vector<std::string>& argv,
const file_handle_mapping_vector& fds_to_remap,
bool wait, ProcessHandle* process_handle) {
- bool retval = true;
-
- char* argv_copy[argv.size() + 1];
- for (size_t i = 0; i < argv.size(); i++) {
- argv_copy[i] = new char[argv[i].size() + 1];
- strcpy(argv_copy[i], argv[i].c_str());
- }
- argv_copy[argv.size()] = NULL;
-
// Make sure we don't leak any FDs to the child process by marking all FDs
// as close-on-exec.
SetAllFDsToCloseOnExec();
- int pid = fork();
+ pid_t pid = fork();
+ if (pid < 0)
+ return false;
+
if (pid == 0) {
for (file_handle_mapping_vector::const_iterator it = fds_to_remap.begin();
it != fds_to_remap.end();
@@ -61,9 +55,12 @@ bool LaunchApp(const std::vector<std::string>& argv,
}
}
- execvp(argv_copy[0], argv_copy);
- } else if (pid < 0) {
- retval = false;
+ char* argv_cstr[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;
+ execvp(argv_cstr[0], argv_cstr);
+ exit(127);
} else {
if (wait)
waitpid(pid, 0, 0);
@@ -72,10 +69,7 @@ bool LaunchApp(const std::vector<std::string>& argv,
*process_handle = pid;
}
- for (size_t i = 0; i < argv.size(); i++)
- delete[] argv_copy[i];
-
- return retval;
+ return true;
}
bool LaunchApp(const CommandLine& cl,