summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 08:09:30 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 08:09:30 +0000
commit1912cfef3207b30c2691a3f71c524a69ac969b19 (patch)
treee13101b5a3c721dfd3a00179a49e43b454dcd5d5 /base
parent37f876a54ffb14d1630b1c0ebdbeda82ed150816 (diff)
downloadchromium_src-1912cfef3207b30c2691a3f71c524a69ac969b19.zip
chromium_src-1912cfef3207b30c2691a3f71c524a69ac969b19.tar.gz
chromium_src-1912cfef3207b30c2691a3f71c524a69ac969b19.tar.bz2
More solid detection of browser process in chrome_process_util_linux.cc:
- use GetAppOutput instead of popen - make unexpected conditions fatal (otherwise the tests using this code would mistakenly assume that there is no running browser process) Also add a constant for SingletonSocket. Make necessary adjustments to GetAppOutput - ignore stderr (because fuser prints the file name to stderr and having stderr in |output| would require more parsing). Review URL: http://codereview.chromium.org/77031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14091 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/process_util.h7
-rw-r--r--base/process_util_posix.cc10
2 files changed, 12 insertions, 5 deletions
diff --git a/base/process_util.h b/base/process_util.h
index 367c772..20cdd5e 100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -126,9 +126,10 @@ bool LaunchApp(const CommandLine& cl,
#if defined(OS_POSIX)
// Execute the application specified by |cl| and wait for it to exit. Store
-// the output (stdout and stderr) in |output|. Returns true on success
-// (application launched and exited cleanly, with exit code indicating success).
-// |output| is modified only when the function finished successfully.
+// the output (stdout) in |output|. Redirects stderr to /dev/null. Returns true
+// on success (application launched and exited cleanly, with exit code
+// indicating success). |output| is modified only when the function finished
+// successfully.
bool GetAppOutput(const CommandLine& cl, std::string* output);
#endif // defined(OS_POSIX)
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 75c9b96..3570a16 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -326,17 +326,23 @@ bool GetAppOutput(const CommandLine& cl, std::string* output) {
return false;
case 0: // child
{
+ int dev_null = open("/dev/null", O_WRONLY);
+ if (dev_null < 0)
+ exit(127);
+
int rv;
do {
rv = dup2(pipe_fd[1], STDOUT_FILENO);
} while (rv == -1 && errno == EINTR);
do {
- rv = dup2(pipe_fd[1], STDERR_FILENO);
+ rv = dup2(dev_null, STDERR_FILENO);
} while (rv == -1 && errno == EINTR);
if (pipe_fd[0] != STDOUT_FILENO && pipe_fd[0] != STDERR_FILENO)
close(pipe_fd[0]);
if (pipe_fd[1] != STDOUT_FILENO && pipe_fd[1] != STDERR_FILENO)
close(pipe_fd[1]);
+ if (dev_null != STDOUT_FILENO && dev_null != STDERR_FILENO)
+ close(dev_null);
const std::vector<std::string> argv = cl.argv();
char* argv_cstr[argv.size() + 1];
@@ -373,7 +379,7 @@ bool GetAppOutput(const CommandLine& cl, std::string* output) {
if (bytes_read > 0)
buf_output.append(buffer, bytes_read);
}
- output->assign(buf_output);
+ output->swap(buf_output);
close(pipe_fd[0]);
return true;
}