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/linux_util.h" | 5 #include "base/linux_util.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <fcntl.h> | 9 #include <fcntl.h> |
10 #include <stdlib.h> | 10 #include <stdlib.h> |
(...skipping 19 matching lines...) Expand all Loading... |
30 STATE_DID_NOT_CHECK = 0, | 30 STATE_DID_NOT_CHECK = 0, |
31 STATE_CHECK_STARTED = 1, | 31 STATE_CHECK_STARTED = 1, |
32 STATE_CHECK_FINISHED = 2, | 32 STATE_CHECK_FINISHED = 2, |
33 }; | 33 }; |
34 | 34 |
35 // Helper class for GetLinuxDistro(). | 35 // Helper class for GetLinuxDistro(). |
36 class LinuxDistroHelper { | 36 class LinuxDistroHelper { |
37 public: | 37 public: |
38 // Retrieves the Singleton. | 38 // Retrieves the Singleton. |
39 static LinuxDistroHelper* GetInstance() { | 39 static LinuxDistroHelper* GetInstance() { |
40 return Singleton<LinuxDistroHelper>::get(); | 40 return base::Singleton<LinuxDistroHelper>::get(); |
41 } | 41 } |
42 | 42 |
43 // The simple state machine goes from: | 43 // The simple state machine goes from: |
44 // STATE_DID_NOT_CHECK -> STATE_CHECK_STARTED -> STATE_CHECK_FINISHED. | 44 // STATE_DID_NOT_CHECK -> STATE_CHECK_STARTED -> STATE_CHECK_FINISHED. |
45 LinuxDistroHelper() : state_(STATE_DID_NOT_CHECK) {} | 45 LinuxDistroHelper() : state_(STATE_DID_NOT_CHECK) {} |
46 ~LinuxDistroHelper() {} | 46 ~LinuxDistroHelper() {} |
47 | 47 |
48 // Retrieve the current state, if we're in STATE_DID_NOT_CHECK, | 48 // Retrieve the current state, if we're in STATE_DID_NOT_CHECK, |
49 // we automatically move to STATE_CHECK_STARTED so nobody else will | 49 // we automatically move to STATE_CHECK_STARTED so nobody else will |
50 // do the check. | 50 // do the check. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 if (STATE_CHECK_STARTED == state) | 99 if (STATE_CHECK_STARTED == state) |
100 return "Unknown"; // Don't wait for other thread to finish. | 100 return "Unknown"; // Don't wait for other thread to finish. |
101 DCHECK_EQ(state, STATE_DID_NOT_CHECK); | 101 DCHECK_EQ(state, STATE_DID_NOT_CHECK); |
102 // We do this check only once per process. If it fails, there's | 102 // We do this check only once per process. If it fails, there's |
103 // little reason to believe it will work if we attempt to run | 103 // little reason to believe it will work if we attempt to run |
104 // lsb_release again. | 104 // lsb_release again. |
105 std::vector<std::string> argv; | 105 std::vector<std::string> argv; |
106 argv.push_back("lsb_release"); | 106 argv.push_back("lsb_release"); |
107 argv.push_back("-d"); | 107 argv.push_back("-d"); |
108 std::string output; | 108 std::string output; |
109 base::GetAppOutput(CommandLine(argv), &output); | 109 GetAppOutput(CommandLine(argv), &output); |
110 if (output.length() > 0) { | 110 if (output.length() > 0) { |
111 // lsb_release -d should return: Description:<tab>Distro Info | 111 // lsb_release -d should return: Description:<tab>Distro Info |
112 const char field[] = "Description:\t"; | 112 const char field[] = "Description:\t"; |
113 if (output.compare(0, strlen(field), field) == 0) { | 113 if (output.compare(0, strlen(field), field) == 0) { |
114 SetLinuxDistro(output.substr(strlen(field))); | 114 SetLinuxDistro(output.substr(strlen(field))); |
115 } | 115 } |
116 } | 116 } |
117 distro_state_singleton->CheckFinished(); | 117 distro_state_singleton->CheckFinished(); |
118 return g_linux_distro; | 118 return g_linux_distro; |
119 #else | 119 #else |
120 NOTIMPLEMENTED(); | 120 NOTIMPLEMENTED(); |
121 return "Unknown"; | 121 return "Unknown"; |
122 #endif | 122 #endif |
123 } | 123 } |
124 | 124 |
125 void SetLinuxDistro(const std::string& distro) { | 125 void SetLinuxDistro(const std::string& distro) { |
126 std::string trimmed_distro; | 126 std::string trimmed_distro; |
127 base::TrimWhitespaceASCII(distro, base::TRIM_ALL, &trimmed_distro); | 127 TrimWhitespaceASCII(distro, TRIM_ALL, &trimmed_distro); |
128 base::strlcpy(g_linux_distro, trimmed_distro.c_str(), kDistroSize); | 128 strlcpy(g_linux_distro, trimmed_distro.c_str(), kDistroSize); |
129 } | 129 } |
130 | 130 |
131 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data, | 131 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data, |
132 bool* syscall_supported) { | 132 bool* syscall_supported) { |
133 char buf[256]; | 133 char buf[256]; |
134 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); | 134 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); |
135 | 135 |
136 if (syscall_supported != NULL) | 136 if (syscall_supported != NULL) |
137 *syscall_supported = false; | 137 *syscall_supported = false; |
138 | 138 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), | 171 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), |
172 expected_data.length())) { | 172 expected_data.length())) { |
173 return current_tid; | 173 return current_tid; |
174 } | 174 } |
175 } | 175 } |
176 return -1; | 176 return -1; |
177 } | 177 } |
178 | 178 |
179 } // namespace base | 179 } // namespace base |
OLD | NEW |