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

Side by Side Diff: base/linux_util.cc

Issue 10535141: Cleanup: Move some const char definitions to the .cc file. (try 2) (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 6 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/linux_util.h ('k') | no next file » | 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) 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 <glib.h> 10 #include <glib.h>
11 #include <stdlib.h> 11 #include <stdlib.h>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 DLOG(WARNING) << "The descriptor passed from the crashing process wasn't " 100 DLOG(WARNING) << "The descriptor passed from the crashing process wasn't "
101 " a 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 DLOG(WARNING) << "Failed to parse a socket's inode number: the number " 114 DLOG(WARNING) << "Failed to parse a socket's inode number: the number "
115 "was 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
126 namespace base { 126 namespace base {
127 127
128 const char kFindInodeSwitch[] = "--find-inode";
129
130 // This should be kept in sync with sandbox/linux/suid/sandbox.c
131 const long kSUIDSandboxApiNumber = 1;
132 const char kSandboxEnvironmentApiRequest[] = "SBX_CHROME_API_RQ";
133 const char kSandboxEnvironmentApiProvides[] = "SBX_CHROME_API_PRV";
134
128 // Account for the terminating null character. 135 // Account for the terminating null character.
129 static const int kDistroSize = 128 + 1; 136 static const int kDistroSize = 128 + 1;
130 137
131 // We use this static string to hold the Linux distro info. If we 138 // We use this static string to hold the Linux distro info. If we
132 // crash, the crash handler code will send this in the crash dump. 139 // crash, the crash handler code will send this in the crash dump.
133 char g_linux_distro[kDistroSize] = 140 char g_linux_distro[kDistroSize] =
134 #if defined(OS_CHROMEOS) && defined(USE_AURA) 141 #if defined(OS_CHROMEOS) && defined(USE_AURA)
135 "CrOS Aura"; 142 "CrOS Aura";
136 #elif defined(OS_CHROMEOS) 143 #elif defined(OS_CHROMEOS)
137 "CrOS"; 144 "CrOS";
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 DIR* proc = opendir("/proc"); 211 DIR* proc = opendir("/proc");
205 if (!proc) { 212 if (!proc) {
206 DLOG(WARNING) << "Cannot open /proc"; 213 DLOG(WARNING) << "Cannot open /proc";
207 return false; 214 return false;
208 } 215 }
209 216
210 std::vector<pid_t> pids; 217 std::vector<pid_t> pids;
211 218
212 struct dirent* dent; 219 struct dirent* dent;
213 while ((dent = readdir(proc))) { 220 while ((dent = readdir(proc))) {
214 char *endptr; 221 char* endptr;
215 const unsigned long int pid_ul = strtoul(dent->d_name, &endptr, 10); 222 const unsigned long int pid_ul = strtoul(dent->d_name, &endptr, 10);
216 if (pid_ul == ULONG_MAX || *endptr) 223 if (pid_ul == ULONG_MAX || *endptr)
217 continue; 224 continue;
218 pids.push_back(pid_ul); 225 pids.push_back(pid_ul);
219 } 226 }
220 closedir(proc); 227 closedir(proc);
221 228
222 for (std::vector<pid_t>::const_iterator 229 for (std::vector<pid_t>::const_iterator
223 i = pids.begin(); i != pids.end(); ++i) { 230 i = pids.begin(); i != pids.end(); ++i) {
224 const pid_t current_pid = *i; 231 const pid_t current_pid = *i;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 272
266 DIR* task = opendir(buf); 273 DIR* task = opendir(buf);
267 if (!task) { 274 if (!task) {
268 DLOG(WARNING) << "Cannot open " << buf; 275 DLOG(WARNING) << "Cannot open " << buf;
269 return -1; 276 return -1;
270 } 277 }
271 278
272 std::vector<pid_t> tids; 279 std::vector<pid_t> tids;
273 struct dirent* dent; 280 struct dirent* dent;
274 while ((dent = readdir(task))) { 281 while ((dent = readdir(task))) {
275 char *endptr; 282 char* endptr;
276 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10); 283 const unsigned long int tid_ul = strtoul(dent->d_name, &endptr, 10);
277 if (tid_ul == ULONG_MAX || *endptr) 284 if (tid_ul == ULONG_MAX || *endptr)
278 continue; 285 continue;
279 tids.push_back(tid_ul); 286 tids.push_back(tid_ul);
280 } 287 }
281 closedir(task); 288 closedir(task);
282 289
283 scoped_array<char> syscall_data(new char[expected_data.length()]); 290 scoped_array<char> syscall_data(new char[expected_data.length()]);
284 for (std::vector<pid_t>::const_iterator 291 for (std::vector<pid_t>::const_iterator
285 i = tids.begin(); i != tids.end(); ++i) { 292 i = tids.begin(); i != tids.end(); ++i) {
(...skipping 12 matching lines...) Expand all
298 305
299 if (0 == strncmp(expected_data.c_str(), syscall_data.get(), 306 if (0 == strncmp(expected_data.c_str(), syscall_data.get(),
300 expected_data.length())) { 307 expected_data.length())) {
301 return current_tid; 308 return current_tid;
302 } 309 }
303 } 310 }
304 return -1; 311 return -1;
305 } 312 }
306 313
307 } // namespace base 314 } // namespace base
OLDNEW
« no previous file with comments | « base/linux_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698