Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(435)

Side by Side Diff: base/base_paths_posix.cc

Issue 1979006: use sysctl instead of /proc on FreeBSD... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 10 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This is really Posix minus Mac. Mac code is in base_paths_mac.mm. 5 // This is really Posix minus Mac. Mac code is in base_paths_mac.mm.
6 6
7 #include "base/base_paths.h" 7 #include "base/base_paths.h"
8 8
9 #include <unistd.h> 9 #include <unistd.h>
10 #if defined(OS_FREEBSD)
11 #include <sys/param.h>
12 #include <sys/sysctl.h>
13 #endif
10 14
11 #include "base/env_var.h" 15 #include "base/env_var.h"
12 #include "base/file_path.h" 16 #include "base/file_path.h"
13 #include "base/file_util.h" 17 #include "base/file_util.h"
14 #include "base/logging.h" 18 #include "base/logging.h"
15 #include "base/path_service.h" 19 #include "base/path_service.h"
16 #include "base/scoped_ptr.h" 20 #include "base/scoped_ptr.h"
17 #include "base/sys_string_conversions.h" 21 #include "base/sys_string_conversions.h"
18 #include "base/xdg_util.h" 22 #include "base/xdg_util.h"
19 23
20 namespace base { 24 namespace base {
21 25
22 #if defined(OS_LINUX) 26 #if defined(OS_LINUX)
23 const char kSelfExe[] = "/proc/self/exe"; 27 const char kSelfExe[] = "/proc/self/exe";
24 #elif defined(OS_SOLARIS) 28 #elif defined(OS_SOLARIS)
25 const char kSelfExe[] = getexecname(); 29 const char kSelfExe[] = getexecname();
26 #elif defined(OS_FREEBSD)
27 const char kSelfExe[] = "/proc/curproc/file";
28 #endif 30 #endif
29 31
30 bool PathProviderPosix(int key, FilePath* result) { 32 bool PathProviderPosix(int key, FilePath* result) {
31 FilePath path; 33 FilePath path;
32 switch (key) { 34 switch (key) {
33 case base::FILE_EXE: 35 case base::FILE_EXE:
34 case base::FILE_MODULE: { // TODO(evanm): is this correct? 36 case base::FILE_MODULE: { // TODO(evanm): is this correct?
37 #if defined(OS_LINUX)
35 char bin_dir[PATH_MAX + 1]; 38 char bin_dir[PATH_MAX + 1];
36 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX); 39 int bin_dir_size = readlink(kSelfExe, bin_dir, PATH_MAX);
37 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) { 40 if (bin_dir_size < 0 || bin_dir_size > PATH_MAX) {
38 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; 41 NOTREACHED() << "Unable to resolve " << kSelfExe << ".";
39 return false; 42 return false;
40 } 43 }
41 bin_dir[bin_dir_size] = 0; 44 bin_dir[bin_dir_size] = 0;
42 *result = FilePath(bin_dir); 45 *result = FilePath(bin_dir);
43 return true; 46 return true;
47 #elif defined(OS_FREEBSD)
48 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
49 char bin_dir[PATH_MAX + 1];
50 size_t length = sizeof(bin_dir);
51 int error = sysctl(name, 4, bin_dir, &length, NULL, 0);
52 if (error < 0 || length == 0 || strlen(bin_dir) == 0) {
53 NOTREACHED() << "Unable to resolve path.";
54 return false;
55 }
56 bin_dir[strlen(bin_dir)] = 0;
57 *result = FilePath(bin_dir);
58 return true;
59 #endif
44 } 60 }
45 case base::DIR_SOURCE_ROOT: { 61 case base::DIR_SOURCE_ROOT: {
46 // Allow passing this in the environment, for more flexibility in build 62 // Allow passing this in the environment, for more flexibility in build
47 // tree configurations (sub-project builds, gyp --output_dir, etc.) 63 // tree configurations (sub-project builds, gyp --output_dir, etc.)
48 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); 64 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
49 std::string cr_source_root; 65 std::string cr_source_root;
50 if (env->GetEnv("CR_SOURCE_ROOT", &cr_source_root)) { 66 if (env->GetEnv("CR_SOURCE_ROOT", &cr_source_root)) {
51 path = FilePath(cr_source_root); 67 path = FilePath(cr_source_root);
52 if (file_util::PathExists(path.Append("base/base_paths_posix.cc"))) { 68 if (file_util::PathExists(path.Append("base/base_paths_posix.cc"))) {
53 *result = path; 69 *result = path;
(...skipping 27 matching lines...) Expand all
81 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create()); 97 scoped_ptr<base::EnvVarGetter> env(base::EnvVarGetter::Create());
82 FilePath cache_dir(base::GetXDGDirectory(env.get(), "XDG_CACHE_HOME", 98 FilePath cache_dir(base::GetXDGDirectory(env.get(), "XDG_CACHE_HOME",
83 ".cache")); 99 ".cache"));
84 *result = cache_dir; 100 *result = cache_dir;
85 return true; 101 return true;
86 } 102 }
87 return false; 103 return false;
88 } 104 }
89 105
90 } // namespace base 106 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698