summaryrefslogtreecommitdiffstats
path: root/base/base_paths_posix.cc
diff options
context:
space:
mode:
authorpvalchev@google.com <pvalchev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-10 16:30:27 +0000
committerpvalchev@google.com <pvalchev@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-10 16:30:27 +0000
commit99aae10b7b9cd4c1e08bb4e978c822483864e331 (patch)
tree5233f0f387e35b84f750a4b3ec4348e8d87d8808 /base/base_paths_posix.cc
parentb57c852a37ed73e3509f72cc74666a0ea897f890 (diff)
downloadchromium_src-99aae10b7b9cd4c1e08bb4e978c822483864e331.zip
chromium_src-99aae10b7b9cd4c1e08bb4e978c822483864e331.tar.gz
chromium_src-99aae10b7b9cd4c1e08bb4e978c822483864e331.tar.bz2
use sysctl instead of /proc on FreeBSD
(unfortunately this approach is not available on OpenBSD though) patch from sprewell Review URL: http://codereview.chromium.org/1979006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46820 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/base_paths_posix.cc')
-rw-r--r--base/base_paths_posix.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/base/base_paths_posix.cc b/base/base_paths_posix.cc
index d2ecf33..e55d10c 100644
--- a/base/base_paths_posix.cc
+++ b/base/base_paths_posix.cc
@@ -7,6 +7,10 @@
#include "base/base_paths.h"
#include <unistd.h>
+#if defined(OS_FREEBSD)
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#endif
#include "base/env_var.h"
#include "base/file_path.h"
@@ -23,8 +27,6 @@ namespace base {
const char kSelfExe[] = "/proc/self/exe";
#elif defined(OS_SOLARIS)
const char kSelfExe[] = getexecname();
-#elif defined(OS_FREEBSD)
-const char kSelfExe[] = "/proc/curproc/file";
#endif
bool PathProviderPosix(int key, FilePath* result) {
@@ -32,6 +34,7 @@ bool PathProviderPosix(int key, FilePath* result) {
switch (key) {
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) {
@@ -41,6 +44,19 @@ bool PathProviderPosix(int key, FilePath* result) {
bin_dir[bin_dir_size] = 0;
*result = FilePath(bin_dir);
return true;
+#elif defined(OS_FREEBSD)
+ int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
+ char bin_dir[PATH_MAX + 1];
+ size_t length = sizeof(bin_dir);
+ int error = sysctl(name, 4, bin_dir, &length, NULL, 0);
+ if (error < 0 || length == 0 || strlen(bin_dir) == 0) {
+ NOTREACHED() << "Unable to resolve path.";
+ return false;
+ }
+ bin_dir[strlen(bin_dir)] = 0;
+ *result = FilePath(bin_dir);
+ return true;
+#endif
}
case base::DIR_SOURCE_ROOT: {
// Allow passing this in the environment, for more flexibility in build