summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-10 16:56:31 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-10 16:56:31 +0000
commitaffb184c81037ecea9f5e97170bd472fb44e1275 (patch)
treebca67a20f33545dd5b29a3d804711d77d53e479d /base
parentdf4956ec32c4899aa79ec529e9525dabfd051e03 (diff)
downloadchromium_src-affb184c81037ecea9f5e97170bd472fb44e1275.zip
chromium_src-affb184c81037ecea9f5e97170bd472fb44e1275.tar.gz
chromium_src-affb184c81037ecea9f5e97170bd472fb44e1275.tar.bz2
POSIX: read subprocess output before waiting for termination.
Previously, GetAppOutput was designed only for fuser. However, it appears that Mac is using it to read the output of ps: which outputs rather more. In this case, ps can fill up the pipe buffer while we are waiting for it to exit, leading to deadlock depending on how many other process are running on the system at the time. http://codereview.chromium.org/118514 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18068 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/process_util_posix.cc15
1 files changed, 7 insertions, 8 deletions
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index d5d6cb8..840339f 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -457,13 +457,6 @@ bool GetAppOutput(const CommandLine& cl, std::string* output) {
// write to the pipe).
close(pipe_fd[1]);
- int exit_code = EXIT_FAILURE;
- bool success = WaitForExitCode(pid, &exit_code);
- if (!success || exit_code != EXIT_SUCCESS) {
- close(pipe_fd[0]);
- return false;
- }
-
char buffer[256];
std::string buf_output;
@@ -474,8 +467,14 @@ bool GetAppOutput(const CommandLine& cl, std::string* output) {
break;
buf_output.append(buffer, bytes_read);
}
- output->swap(buf_output);
close(pipe_fd[0]);
+
+ int exit_code = EXIT_FAILURE;
+ bool success = WaitForExitCode(pid, &exit_code);
+ if (!success || exit_code != EXIT_SUCCESS)
+ return false;
+
+ output->swap(buf_output);
return true;
}
}