OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "base/base_paths.h" | 5 #include "base/base_paths.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "base/environment.h" | 11 #include "base/environment.h" |
12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
| 17 #include "base/process_util.h" |
17 #include "base/nix/xdg_util.h" | 18 #include "base/nix/xdg_util.h" |
18 | 19 |
19 #if defined(OS_FREEBSD) | 20 #if defined(OS_FREEBSD) |
20 #include <sys/param.h> | 21 #include <sys/param.h> |
21 #include <sys/sysctl.h> | 22 #include <sys/sysctl.h> |
22 #elif defined(OS_SOLARIS) | 23 #elif defined(OS_SOLARIS) |
23 #include <stdlib.h> | 24 #include <stdlib.h> |
24 #endif | 25 #endif |
25 | 26 |
26 namespace base { | 27 namespace base { |
27 | 28 |
28 #if defined(OS_LINUX) | |
29 const char kSelfExe[] = "/proc/self/exe"; | |
30 #endif | |
31 | |
32 bool PathProviderPosix(int key, FilePath* result) { | 29 bool PathProviderPosix(int key, FilePath* result) { |
33 FilePath path; | 30 FilePath path; |
34 switch (key) { | 31 switch (key) { |
35 case base::FILE_EXE: | 32 case base::FILE_EXE: |
36 case base::FILE_MODULE: { // TODO(evanm): is this correct? | 33 case base::FILE_MODULE: { // TODO(evanm): is this correct? |
37 #if defined(OS_LINUX) | 34 #if defined(OS_LINUX) |
38 FilePath bin_dir; | 35 FilePath bin_dir; |
39 if (!file_util::ReadSymbolicLink(FilePath(kSelfExe), &bin_dir)) { | 36 if (!file_util::ReadSymbolicLink(FilePath(kProcSelfExe), &bin_dir)) { |
40 NOTREACHED() << "Unable to resolve " << kSelfExe << "."; | 37 NOTREACHED() << "Unable to resolve " << kProcSelfExe << "."; |
41 return false; | 38 return false; |
42 } | 39 } |
43 *result = bin_dir; | 40 *result = bin_dir; |
44 return true; | 41 return true; |
45 #elif defined(OS_FREEBSD) | 42 #elif defined(OS_FREEBSD) |
46 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; | 43 int name[] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |
47 char bin_dir[PATH_MAX + 1]; | 44 char bin_dir[PATH_MAX + 1]; |
48 size_t length = sizeof(bin_dir); | 45 size_t length = sizeof(bin_dir); |
49 // Upon return, |length| is the number of bytes written to |bin_dir| | 46 // Upon return, |length| is the number of bytes written to |bin_dir| |
50 // including the string terminator. | 47 // including the string terminator. |
51 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); | 48 int error = sysctl(name, 4, bin_dir, &length, NULL, 0); |
52 if (error < 0 || length <= 1) { | 49 if (error < 0 || length <= 1) { |
53 NOTREACHED() << "Unable to resolve path."; | 50 NOTREACHED() << "Unable to resolve path."; |
54 return false; | 51 return false; |
55 } | 52 } |
56 *result = FilePath(FilePath::StringType(bin_dir, length - 1)); | 53 *result = FilePath(FilePath::StringType(bin_dir, length - 1)); |
57 return true; | 54 return true; |
58 #elif defined(OS_SOLARIS) | 55 #elif defined(OS_SOLARIS) |
59 char bin_dir[PATH_MAX + 1]; | 56 char bin_dir[PATH_MAX + 1]; |
60 if (realpath(getexecname(), bin_dir) == NULL) { | 57 if (realpath(getexecname(), bin_dir) == NULL) { |
61 NOTREACHED() << "Unable to resolve " << getexecname() << "."; | 58 NOTREACHED() << "Unable to resolve " << getexecname() << "."; |
62 return false; | 59 return false; |
63 } | 60 } |
64 *result = FilePath(bin_dir); | 61 *result = FilePath(bin_dir); |
65 return true; | 62 return true; |
66 #elif defined(OS_OPENBSD) | 63 #elif defined(OS_OPENBSD) |
67 // There is currently no way to get the executable path on OpenBSD | 64 // There is currently no way to get the executable path on OpenBSD |
68 char *cpath; | 65 char* cpath; |
69 if ((cpath = getenv("CHROME_EXE_PATH")) != NULL) | 66 if ((cpath = getenv("CHROME_EXE_PATH")) != NULL) |
70 *result = FilePath(cpath); | 67 *result = FilePath(cpath); |
71 else | 68 else |
72 *result = FilePath("/usr/local/chrome/chrome"); | 69 *result = FilePath("/usr/local/chrome/chrome"); |
73 return true; | 70 return true; |
74 #endif | 71 #endif |
75 } | 72 } |
76 case base::DIR_SOURCE_ROOT: { | 73 case base::DIR_SOURCE_ROOT: { |
77 // Allow passing this in the environment, for more flexibility in build | 74 // Allow passing this in the environment, for more flexibility in build |
78 // tree configurations (sub-project builds, gyp --output_dir, etc.) | 75 // tree configurations (sub-project builds, gyp --output_dir, etc.) |
(...skipping 29 matching lines...) Expand all Loading... |
108 } | 105 } |
109 case base::DIR_HOME: { | 106 case base::DIR_HOME: { |
110 *result = file_util::GetHomeDir(); | 107 *result = file_util::GetHomeDir(); |
111 return true; | 108 return true; |
112 } | 109 } |
113 } | 110 } |
114 return false; | 111 return false; |
115 } | 112 } |
116 | 113 |
117 } // namespace base | 114 } // namespace base |
OLD | NEW |