summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorgspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-03 17:37:54 +0000
committergspencer@chromium.org <gspencer@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-12-03 17:37:54 +0000
commit723571af3c1a86aa14a68bce2511f3dad399287f (patch)
treec77043d78d5eb7eb1437071561fce7c8ad9b4a5d /base
parent0868ee7ae6d7fbb63ab85dfeafa34d724f9a1b45 (diff)
downloadchromium_src-723571af3c1a86aa14a68bce2511f3dad399287f.zip
chromium_src-723571af3c1a86aa14a68bce2511f3dad399287f.tar.gz
chromium_src-723571af3c1a86aa14a68bce2511f3dad399287f.tar.bz2
Start using file_util symlink code, now that it's available.
In CL http://codereview.chromium.org/5349007 I added some base API for manipulating symlinks (since I needed it for some ChromeOS code and noticed that other places could use it too), and this just starts using that API. BUG=none TEST=Ran ui_tests, passed trybots. Review URL: http://codereview.chromium.org/5286010 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@68181 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/base_paths_linux.cc8
-rw-r--r--base/command_line.cc11
-rw-r--r--base/file_util_posix.cc5
-rw-r--r--base/process_util_linux.cc7
4 files changed, 14 insertions, 17 deletions
diff --git a/base/base_paths_linux.cc b/base/base_paths_linux.cc
index 24f86b4..bdf540c 100644
--- a/base/base_paths_linux.cc
+++ b/base/base_paths_linux.cc
@@ -37,14 +37,12 @@ bool PathProviderPosix(int key, FilePath* result) {
case base::FILE_EXE:
case base::FILE_MODULE: { // TODO(evanm): is this correct?
#if defined(OS_LINUX)
- char bin_dir[PATH_MAX + 1];
- int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX);
- if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
+ FilePath bin_dir;
+ if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) {
NOTREACHED() << "Unable to resolve " << kSelfExe << ".";
return false;
}
- bin_dir[bin_dir_size] = 0;
- *result = FilePath(bin_dir);
+ *result = bin_dir;
return true;
#elif defined(OS_FREEBSD)
int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
diff --git a/base/command_line.cc b/base/command_line.cc
index b335e7c..427bed4 100644
--- a/base/command_line.cc
+++ b/base/command_line.cc
@@ -19,6 +19,7 @@
#include <algorithm>
#include "base/file_path.h"
+#include "base/file_util.h"
#include "base/logging.h"
#include "base/singleton.h"
#include "base/string_split.h"
@@ -237,13 +238,11 @@ void CommandLine::SetProcTitle() {
// show up as "exe" in process listings. Read the symlink /proc/self/exe and
// use the path it points at for our process title. Note that this is only for
// display purposes and has no TOCTTOU security implications.
- char buffer[PATH_MAX];
- // Note: readlink() does not append a null byte to terminate the string.
- ssize_t length = readlink("/proc/self/exe", buffer, sizeof(buffer));
- DCHECK(length <= static_cast<ssize_t>(sizeof(buffer)));
- if (length > 0) {
+ FilePath target;
+ FilePath self_exe("/proc/self/exe");
+ if (file_util::ReadSymbolicLink(self_exe, &target)) {
have_argv0 = true;
- title.assign(buffer, length);
+ title = target.value();
// If the binary has since been deleted, Linux appends " (deleted)" to the
// symlink target. Remove it, since this is not really part of our name.
const std::string kDeletedSuffix = " (deleted)";
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index e71051e..92527c8 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -388,11 +388,12 @@ bool ReadSymbolicLink(const FilePath& symlink_path,
char buf[PATH_MAX];
ssize_t count = ::readlink(symlink_path.value().c_str(), buf, arraysize(buf));
- if (count <= 0)
+ if (count <= 0) {
+ target_path->clear();
return false;
+ }
*target_path = FilePath(FilePath::StringType(buf, count));
-
return true;
}
diff --git a/base/process_util_linux.cc b/base/process_util_linux.cc
index 6138c07..4627aa5 100644
--- a/base/process_util_linux.cc
+++ b/base/process_util_linux.cc
@@ -111,13 +111,12 @@ FilePath GetProcessExecutablePath(ProcessHandle process) {
FilePath stat_file("/proc");
stat_file = stat_file.Append(base::IntToString(process));
stat_file = stat_file.Append("exe");
- char exename[2048];
- ssize_t len = readlink(stat_file.value().c_str(), exename, sizeof(exename));
- if (len < 1) {
+ FilePath exe_name;
+ if (!file_util::ReadSymbolicLink(stat_file, &exe_name)) {
// No such process. Happens frequently in e.g. TerminateAllChromeProcesses
return FilePath();
}
- return FilePath(std::string(exename, len));
+ return exe_name;
}
ProcessIterator::ProcessIterator(const ProcessFilter* filter)