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

Side by Side Diff: base/linux_util.cc

Issue 8341026: Replace most LOG/CHECK statements with DLOG/DCHECK 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
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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 *inode_out = buf.st_ino; 194 *inode_out = buf.st_ino;
195 return true; 195 return true;
196 } 196 }
197 197
198 bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode) { 198 bool FindProcessHoldingSocket(pid_t* pid_out, ino_t socket_inode) {
199 DCHECK(pid_out); 199 DCHECK(pid_out);
200 bool already_found = false; 200 bool already_found = false;
201 201
202 DIR* proc = opendir("/proc"); 202 DIR* proc = opendir("/proc");
203 if (!proc) { 203 if (!proc) {
204 LOG(WARNING) << "Cannot open /proc"; 204 DLOG(WARNING) << "Cannot open /proc";
205 return false; 205 return false;
206 } 206 }
207 207
208 std::vector<pid_t> pids; 208 std::vector<pid_t> pids;
209 209
210 struct dirent* dent; 210 struct dirent* dent;
211 while ((dent = readdir(proc))) { 211 while ((dent = readdir(proc))) {
212 char *endptr; 212 char *endptr;
213 const unsigned long int pid_ul = strtoul(dent->d_name, &endptr, 10); 213 const unsigned long int pid_ul = strtoul(dent->d_name, &endptr, 10);
214 if (pid_ul == ULONG_MAX || *endptr) 214 if (pid_ul == ULONG_MAX || *endptr)
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data, 256 pid_t FindThreadIDWithSyscall(pid_t pid, const std::string& expected_data,
257 bool* syscall_supported) { 257 bool* syscall_supported) {
258 char buf[256]; 258 char buf[256];
259 snprintf(buf, sizeof(buf), "/proc/%d/task", pid); 259 snprintf(buf, sizeof(buf), "/proc/%d/task", pid);
260 260
261 if (syscall_supported != NULL) 261 if (syscall_supported != NULL)
262 *syscall_supported = false; 262 *syscall_supported = false;
263 263
264 DIR* task = opendir(buf); 264 DIR* task = opendir(buf);
265 if (!task) { 265 if (!task) {
266 LOG(WARNING) << "Cannot open " << buf; 266 DLOG(WARNING) << "Cannot open " << buf;
267 return -1; 267 return -1;
268 } 268 }
269 269
270 std::vector<pid_t> tids; 270 std::vector<pid_t> tids;
271 struct dirent* dent; 271 struct dirent* dent;
272 while ((dent = readdir(task))) { 272 while ((dent = readdir(task))) {
273 char *endptr; 273 char *endptr;
274 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); 274 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10);
275 if (tid_ul == ULONG_MAX || *endptr) 275 if (tid_ul == ULONG_MAX || *endptr)
276 continue; 276 continue;
(...skipping 19 matching lines...) Expand all
296 296
297 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), 297 if (0 == strncmp(expected_data.c_str(), syscall_data.get(),
298 expected_data.length())) { 298 expected_data.length())) {
299 return current_tid; 299 return current_tid;
300 } 300 }
301 } 301 }
302 return -1; 302 return -1;
303 } 303 }
304 304
305 } // namespace base 305 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698