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

Side by Side Diff: base/linux_util.cc

Issue 8368009: Replace most LOG statements with DLOG statements in base. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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 | « base/i18n/time_formatting.cc ('k') | base/mac/foundation_util.mm » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 // path: e.g. /proc/1234/fd/5 (must be a UNIX domain socket descriptor) 81 // path: e.g. /proc/1234/fd/5 (must be a UNIX domain socket descriptor)
82 // log: if true, log messages about failure details 82 // log: if true, log messages about failure details
83 bool ProcPathGetInode(ino_t* inode_out, const char* path, bool log = false) { 83 bool ProcPathGetInode(ino_t* inode_out, const char* path, bool log = false) {
84 DCHECK(inode_out); 84 DCHECK(inode_out);
85 DCHECK(path); 85 DCHECK(path);
86 86
87 char buf[256]; 87 char buf[256];
88 const ssize_t n = readlink(path, buf, sizeof(buf) - 1); 88 const ssize_t n = readlink(path, buf, sizeof(buf) - 1);
89 if (n == -1) { 89 if (n == -1) {
90 if (log) { 90 if (log) {
91 LOG(WARNING) << "Failed to read the inode number for a socket from /proc" 91 DLOG(WARNING) << "Failed to read the inode number for a socket from /proc"
92 "(" << errno << ")"; 92 "(" << errno << ")";
93 } 93 }
94 return false; 94 return false;
95 } 95 }
96 buf[n] = 0; 96 buf[n] = 0;
97 97
98 if (memcmp(kSocketLinkPrefix, buf, sizeof(kSocketLinkPrefix) - 1)) { 98 if (memcmp(kSocketLinkPrefix, buf, sizeof(kSocketLinkPrefix) - 1)) {
99 if (log) { 99 if (log) {
100 LOG(WARNING) << "The descriptor passed from the crashing process wasn't a" 100 DLOG(WARNING) << "The descriptor passed from the crashing process wasn't "
101 " UNIX domain socket."; 101 " a UNIX domain socket.";
102 } 102 }
103 return false; 103 return false;
104 } 104 }
105 105
106 char *endptr; 106 char *endptr;
107 const unsigned long long int inode_ul = 107 const unsigned long long int inode_ul =
108 strtoull(buf + sizeof(kSocketLinkPrefix) - 1, &endptr, 10); 108 strtoull(buf + sizeof(kSocketLinkPrefix) - 1, &endptr, 10);
109 if (*endptr != ']') 109 if (*endptr != ']')
110 return false; 110 return false;
111 111
112 if (inode_ul == ULLONG_MAX) { 112 if (inode_ul == ULLONG_MAX) {
113 if (log) { 113 if (log) {
114 LOG(WARNING) << "Failed to parse a socket's inode number: the number was " 114 DLOG(WARNING) << "Failed to parse a socket's inode number: the number "
115 "too large. Please report this bug: " << buf; 115 "was too large. Please report this bug: " << buf;
116 } 116 }
117 return false; 117 return false;
118 } 118 }
119 119
120 *inode_out = inode_ul; 120 *inode_out = inode_ul;
121 return true; 121 return true;
122 } 122 }
123 123
124 } // namespace 124 } // namespace
125 125
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 *inode_out = buf.st_ino; 193 *inode_out = buf.st_ino;
194 return true; 194 return true;
195 } 195 }
196 196
197 bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode) { 197 bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode) {
198 DCHECK(pid_out); 198 DCHECK(pid_out);
199 bool already_found = false; 199 bool already_found = false;
200 200
201 DIR* proc = opendir("/proc"); 201 DIR* proc = opendir("/proc");
202 if (!proc) { 202 if (!proc) {
203 LOG(WARNING) << "Cannot open /proc"; 203 DLOG(WARNING) << "Cannot open /proc";
204 return false; 204 return false;
205 } 205 }
206 206
207 std::vector<pid_t> pids; 207 std::vector<pid_t> pids;
208 208
209 struct dirent* dent; 209 struct dirent* dent;
210 while ((dent = readdir(proc))) { 210 while ((dent = readdir(proc))) {
211 char *endptr; 211 char *endptr;
212 const unsigned long int pid_ul = strtoul(dent->d_name, &endptr, 10); 212 const unsigned long int pid_ul = strtoul(dent->d_name, &endptr, 10);
213 if (pid_ul == ULONG_MAX || *endptr) 213 if (pid_ul == ULONG_MAX || *endptr)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data, 255 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data,
256 bool* syscall_supported) { 256 bool* syscall_supported) {
257 char buf[256]; 257 char buf[256];
258 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); 258 snprintf(buf, sizeof(buf), "/proc/%d/task", pid);
259 259
260 if (syscall_supported != NULL) 260 if (syscall_supported != NULL)
261 *syscall_supported = false; 261 *syscall_supported = false;
262 262
263 DIR* task = opendir(buf); 263 DIR* task = opendir(buf);
264 if (!task) { 264 if (!task) {
265 LOG(WARNING) << "Cannot open " << buf; 265 DLOG(WARNING) << "Cannot open " << buf;
266 return -1; 266 return -1;
267 } 267 }
268 268
269 std::vector<pid_t> tids; 269 std::vector<pid_t> tids;
270 struct dirent* dent; 270 struct dirent* dent;
271 while ((dent = readdir(task))) { 271 while ((dent = readdir(task))) {
272 char *endptr; 272 char *endptr;
273 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); 273 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10);
274 if (tid_ul == ULONG_MAX || *endptr) 274 if (tid_ul == ULONG_MAX || *endptr)
275 continue; 275 continue;
(...skipping 19 matching lines...) Expand all
295 295
296 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), 296 if (0 == strncmp(expected_data.c_str(), syscall_data.get(),
297 expected_data.length())) { 297 expected_data.length())) {
298 return current_tid; 298 return current_tid;
299 } 299 }
300 } 300 }
301 return -1; 301 return -1;
302 } 302 }
303 303
304 } // namespace base 304 } // namespace base
OLDNEW
« no previous file with comments | « base/i18n/time_formatting.cc ('k') | base/mac/foundation_util.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698