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

Side by Side Diff: base/linux_util.cc

Issue 3186028: Make crash reporting client_id accessible through child_process_logging. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: address mark's feedback Created 10 years, 4 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
« no previous file with comments | « base/linux_util.h ('k') | chrome/app/breakpad_linux.cc » ('j') | 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 #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 <glib.h> 10 #include <glib.h>
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 *inode_out = inode_ul; 121 *inode_out = inode_ul;
122 return true; 122 return true;
123 } 123 }
124 124
125 } // namespace 125 } // namespace
126 126
127 namespace base { 127 namespace base {
128 128
129 // Account for the terminating null character.
130 static const int kDistroSize = 128 + 1;
131
129 // We use this static string to hold the Linux distro info. If we 132 // We use this static string to hold the Linux distro info. If we
130 // crash, the crash handler code will send this in the crash dump. 133 // crash, the crash handler code will send this in the crash dump.
131 std::string linux_distro = 134 char g_linux_distro[kDistroSize] =
132 #if defined(OS_CHROMEOS) 135 #if defined(OS_CHROMEOS)
133 "CrOS"; 136 "CrOS";
134 #else // if defined(OS_LINUX) 137 #else // if defined(OS_LINUX)
135 "Unknown"; 138 "Unknown";
136 #endif 139 #endif
137 140
138 std::string GetLinuxDistro() { 141 std::string GetLinuxDistro() {
139 #if defined(OS_CHROMEOS) 142 #if defined(OS_CHROMEOS)
140 return linux_distro; 143 return g_linux_distro;
141 #elif defined(OS_LINUX) 144 #elif defined(OS_LINUX)
142 LinuxDistroHelper* distro_state_singleton = LinuxDistroHelper::Get(); 145 LinuxDistroHelper* distro_state_singleton = LinuxDistroHelper::Get();
143 LinuxDistroState state = distro_state_singleton->State(); 146 LinuxDistroState state = distro_state_singleton->State();
144 if (STATE_DID_NOT_CHECK == state) { 147 if (STATE_DID_NOT_CHECK == state) {
145 // We do this check only once per process. If it fails, there's 148 // We do this check only once per process. If it fails, there's
146 // little reason to believe it will work if we attempt to run 149 // little reason to believe it will work if we attempt to run
147 // lsb_release again. 150 // lsb_release again.
148 std::vector<std::string> argv; 151 std::vector<std::string> argv;
149 argv.push_back("lsb_release"); 152 argv.push_back("lsb_release");
150 argv.push_back("-d"); 153 argv.push_back("-d");
151 std::string output; 154 std::string output;
152 base::GetAppOutput(CommandLine(argv), &output); 155 base::GetAppOutput(CommandLine(argv), &output);
153 if (output.length() > 0) { 156 if (output.length() > 0) {
154 // lsb_release -d should return: Description:<tab>Distro Info 157 // lsb_release -d should return: Description:<tab>Distro Info
155 static const std::string field = "Description:\t"; 158 static const std::string field = "Description:\t";
156 if (output.compare(0, field.length(), field) == 0) { 159 if (output.compare(0, field.length(), field) == 0) {
157 linux_distro = output.substr(field.length()); 160 SetLinuxDistro(output.substr(field.length()));
158 TrimWhitespaceASCII(linux_distro, TRIM_ALL, &linux_distro);
159 } 161 }
160 } 162 }
161 distro_state_singleton->CheckFinished(); 163 distro_state_singleton->CheckFinished();
162 return linux_distro; 164 return g_linux_distro;
163 } else if (STATE_CHECK_STARTED == state) { 165 } else if (STATE_CHECK_STARTED == state) {
164 // If the distro check above is in progress in some other thread, we're 166 // If the distro check above is in progress in some other thread, we're
165 // not going to wait for the results. 167 // not going to wait for the results.
166 return "Unknown"; 168 return "Unknown";
167 } else { 169 } else {
168 // In STATE_CHECK_FINISHED, no more writing to |linux_distro|. 170 // In STATE_CHECK_FINISHED, no more writing to |linux_distro|.
169 return linux_distro; 171 return g_linux_distro;
170 } 172 }
171 #else 173 #else
172 NOTIMPLEMENTED(); 174 NOTIMPLEMENTED();
173 #endif 175 #endif
174 } 176 }
175 177
178 void SetLinuxDistro(const std::string& distro) {
179 std::string trimmed_distro;
180 TrimWhitespaceASCII(distro, TRIM_ALL, &trimmed_distro);
181 base::strlcpy(g_linux_distro, trimmed_distro.c_str(), kDistroSize);
182 }
183
176 bool FileDescriptorGetInode(ino_t* inode_out, int fd) { 184 bool FileDescriptorGetInode(ino_t* inode_out, int fd) {
177 DCHECK(inode_out); 185 DCHECK(inode_out);
178 186
179 struct stat buf; 187 struct stat buf;
180 if (fstat(fd, &buf) < 0) 188 if (fstat(fd, &buf) < 0)
181 return false; 189 return false;
182 190
183 if (!S_ISSOCK(buf.st_mode)) 191 if (!S_ISSOCK(buf.st_mode))
184 return false; 192 return false;
185 193
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 289
282 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), 290 if (0 == strncmp(expected_data.c_str(), syscall_data.get(),
283 expected_data.length())) { 291 expected_data.length())) {
284 return current_tid; 292 return current_tid;
285 } 293 }
286 } 294 }
287 return -1; 295 return -1;
288 } 296 }
289 297
290 } // namespace base 298 } // namespace base
OLDNEW
« no previous file with comments | « base/linux_util.h ('k') | chrome/app/breakpad_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698