OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/app/breakpad_linux.h" | 5 #include "chrome/app/breakpad_linux.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 #include <sys/socket.h> | 9 #include <sys/socket.h> |
| 10 #include <sys/time.h> |
10 #include <sys/types.h> | 11 #include <sys/types.h> |
11 #include <sys/uio.h> | 12 #include <sys/uio.h> |
| 13 #include <time.h> |
12 #include <unistd.h> | 14 #include <unistd.h> |
13 | 15 |
14 #include <algorithm> | 16 #include <algorithm> |
15 #include <string> | 17 #include <string> |
16 | 18 |
17 #include "base/command_line.h" | 19 #include "base/command_line.h" |
18 #include "base/eintr_wrapper.h" | 20 #include "base/eintr_wrapper.h" |
19 #include "base/file_path.h" | 21 #include "base/file_path.h" |
20 #include "base/file_version_info_linux.h" | 22 #include "base/file_version_info_linux.h" |
21 #include "base/global_descriptors_posix.h" | 23 #include "base/global_descriptors_posix.h" |
22 #include "base/path_service.h" | 24 #include "base/path_service.h" |
23 #include "base/rand_util.h" | 25 #include "base/rand_util.h" |
24 #include "base/string_util.h" | 26 #include "base/string_util.h" |
25 #include "breakpad/linux/directory_reader.h" | 27 #include "breakpad/linux/directory_reader.h" |
26 #include "breakpad/linux/exception_handler.h" | 28 #include "breakpad/linux/exception_handler.h" |
27 #include "breakpad/linux/linux_libc_support.h" | 29 #include "breakpad/linux/linux_libc_support.h" |
28 #include "breakpad/linux/linux_syscall_support.h" | 30 #include "breakpad/linux/linux_syscall_support.h" |
29 #include "breakpad/linux/memory.h" | 31 #include "breakpad/linux/memory.h" |
30 #include "chrome/common/chrome_descriptors.h" | 32 #include "chrome/common/chrome_descriptors.h" |
31 #include "chrome/common/chrome_paths.h" | 33 #include "chrome/common/chrome_paths.h" |
32 #include "chrome/common/chrome_switches.h" | 34 #include "chrome/common/chrome_switches.h" |
33 #include "chrome/installer/util/google_update_settings.h" | 35 #include "chrome/installer/util/google_update_settings.h" |
34 | 36 |
35 static const char kUploadURL[] = | 37 static const char kUploadURL[] = |
36 "https://clients2.google.com/cr/report"; | 38 "https://clients2.google.com/cr/report"; |
37 | 39 |
| 40 static time_t uptime = 0; |
| 41 |
38 // Writes the value |v| as 16 hex characters to the memory pointed at by | 42 // Writes the value |v| as 16 hex characters to the memory pointed at by |
39 // |output|. | 43 // |output|. |
40 static void write_uint64_hex(char* output, uint64_t v) { | 44 static void write_uint64_hex(char* output, uint64_t v) { |
41 static const char hextable[] = "0123456789abcdef"; | 45 static const char hextable[] = "0123456789abcdef"; |
42 | 46 |
43 for (int i = 15; i >= 0; --i) { | 47 for (int i = 15; i >= 0; --i) { |
44 output[i] = hextable[v & 15]; | 48 output[i] = hextable[v & 15]; |
45 v >>= 4; | 49 v >>= 4; |
46 } | 50 } |
47 } | 51 } |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 // Content-Disposition: form-data; name="prod" \r\n \r\n (2..6) | 148 // Content-Disposition: form-data; name="prod" \r\n \r\n (2..6) |
145 // Chrome_Linux \r\n (7, 8) | 149 // Chrome_Linux \r\n (7, 8) |
146 // BOUNDARY \r\n (9, 10) | 150 // BOUNDARY \r\n (9, 10) |
147 // Content-Disposition: form-data; name="ver" \r\n \r\n (11..15) | 151 // Content-Disposition: form-data; name="ver" \r\n \r\n (11..15) |
148 // 1.2.3.4 \r\n (16, 17) | 152 // 1.2.3.4 \r\n (16, 17) |
149 // BOUNDARY \r\n (18, 19) | 153 // BOUNDARY \r\n (18, 19) |
150 // Content-Disposition: form-data; name="guid" \r\n \r\n (20..24) | 154 // Content-Disposition: form-data; name="guid" \r\n \r\n (20..24) |
151 // 1.2.3.4 \r\n (25, 26) | 155 // 1.2.3.4 \r\n (25, 26) |
152 // BOUNDARY \r\n (27, 28) | 156 // BOUNDARY \r\n (27, 28) |
153 // | 157 // |
154 // zero or more: | 158 // zero or one: |
| 159 // Content-Disposition: form-data; name="ptime" \r\n \r\n (0..4) |
| 160 // abcdef \r\n (5, 6) |
| 161 // BOUNDARY \r\n (7, 8) |
| 162 // |
| 163 // zero or one: |
155 // Content-Disposition: form-data; name="ptype" \r\n \r\n (0..4) | 164 // Content-Disposition: form-data; name="ptype" \r\n \r\n (0..4) |
156 // abcdef \r\n (5, 6) | 165 // abcdef \r\n (5, 6) |
157 // BOUNDARY \r\n (7, 8) | 166 // BOUNDARY \r\n (7, 8) |
158 // | 167 // |
159 // zero or more: | 168 // zero or one: |
160 // Content-Disposition: form-data; name="lsb-release" \r\n \r\n (0..4) | 169 // Content-Disposition: form-data; name="lsb-release" \r\n \r\n (0..4) |
161 // abcdef \r\n (5, 6) | 170 // abcdef \r\n (5, 6) |
162 // BOUNDARY \r\n (7, 8) | 171 // BOUNDARY \r\n (7, 8) |
163 // | 172 // |
164 // zero or more: | 173 // zero or more: |
165 // Content-Disposition: form-data; name="url-chunk-1" \r\n \r\n (0..5) | 174 // Content-Disposition: form-data; name="url-chunk-1" \r\n \r\n (0..5) |
166 // abcdef \r\n (6, 7) | 175 // abcdef \r\n (6, 7) |
167 // BOUNDARY \r\n (8, 9) | 176 // BOUNDARY \r\n (8, 9) |
168 // | 177 // |
169 // Content-Disposition: form-data; name="dump"; filename="dump" \r\n (0,1,2) | 178 // Content-Disposition: form-data; name="dump"; filename="dump" \r\n (0,1,2) |
(...skipping 10 matching lines...) Expand all Loading... |
180 #else // OS_LINUX | 189 #else // OS_LINUX |
181 static const char chrome_product_msg[] = "Chrome_Linux"; | 190 static const char chrome_product_msg[] = "Chrome_Linux"; |
182 #endif | 191 #endif |
183 static const char ver_msg[] = "ver"; | 192 static const char ver_msg[] = "ver"; |
184 static const char guid_msg[] = "guid"; | 193 static const char guid_msg[] = "guid"; |
185 static const char dashdash_msg[] = {'-', '-'}; | 194 static const char dashdash_msg[] = {'-', '-'}; |
186 static const char dump_msg[] = "upload_file_minidump\"; filename=\"dump\""; | 195 static const char dump_msg[] = "upload_file_minidump\"; filename=\"dump\""; |
187 static const char content_type_msg[] = | 196 static const char content_type_msg[] = |
188 "Content-Type: application/octet-stream"; | 197 "Content-Type: application/octet-stream"; |
189 static const char url_chunk_msg[] = "url-chunk-"; | 198 static const char url_chunk_msg[] = "url-chunk-"; |
| 199 static const char process_time_msg[] = "ptime"; |
190 static const char process_type_msg[] = "ptype"; | 200 static const char process_type_msg[] = "ptype"; |
191 static const char distro_msg[] = "lsb-release"; | 201 static const char distro_msg[] = "lsb-release"; |
192 | 202 |
193 struct kernel_iovec iov[29]; | 203 struct kernel_iovec iov[29]; |
194 iov[0].iov_base = mime_boundary; | 204 iov[0].iov_base = mime_boundary; |
195 iov[0].iov_len = sizeof(mime_boundary) - 1; | 205 iov[0].iov_len = sizeof(mime_boundary) - 1; |
196 iov[1].iov_base = const_cast<char*>(rn); | 206 iov[1].iov_base = const_cast<char*>(rn); |
197 iov[1].iov_len = sizeof(rn); | 207 iov[1].iov_len = sizeof(rn); |
198 | 208 |
199 iov[2].iov_base = const_cast<char*>(form_data_msg); | 209 iov[2].iov_base = const_cast<char*>(form_data_msg); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 iov[26].iov_base = const_cast<char*>(rn); | 264 iov[26].iov_base = const_cast<char*>(rn); |
255 iov[26].iov_len = sizeof(rn); | 265 iov[26].iov_len = sizeof(rn); |
256 | 266 |
257 iov[27].iov_base = mime_boundary; | 267 iov[27].iov_base = mime_boundary; |
258 iov[27].iov_len = sizeof(mime_boundary) - 1; | 268 iov[27].iov_len = sizeof(mime_boundary) - 1; |
259 iov[28].iov_base = const_cast<char*>(rn); | 269 iov[28].iov_base = const_cast<char*>(rn); |
260 iov[28].iov_len = sizeof(rn); | 270 iov[28].iov_len = sizeof(rn); |
261 | 271 |
262 sys_writev(fd, iov, 29); | 272 sys_writev(fd, iov, 29); |
263 | 273 |
| 274 if (uptime) { |
| 275 struct timeval tv; |
| 276 if (!gettimeofday(&tv, NULL)) { |
| 277 int time = tv.tv_sec - uptime; |
| 278 char time_str[21]; |
| 279 const unsigned time_len = my_int_len(time); |
| 280 my_itos(time_str, time, time_len); |
| 281 |
| 282 iov[0].iov_base = const_cast<char*>(form_data_msg); |
| 283 iov[0].iov_len = sizeof(form_data_msg) - 1; |
| 284 iov[1].iov_base = const_cast<char*>(process_time_msg); |
| 285 iov[1].iov_len = sizeof(process_time_msg) - 1; |
| 286 iov[2].iov_base = const_cast<char*>(quote_msg); |
| 287 iov[2].iov_len = sizeof(quote_msg); |
| 288 iov[3].iov_base = const_cast<char*>(rn); |
| 289 iov[3].iov_len = sizeof(rn); |
| 290 iov[4].iov_base = const_cast<char*>(rn); |
| 291 iov[4].iov_len = sizeof(rn); |
| 292 |
| 293 iov[5].iov_base = const_cast<char*>(time_str); |
| 294 iov[5].iov_len = time_len; |
| 295 iov[6].iov_base = const_cast<char*>(rn); |
| 296 iov[6].iov_len = sizeof(rn); |
| 297 iov[7].iov_base = mime_boundary; |
| 298 iov[7].iov_len = sizeof(mime_boundary) - 1; |
| 299 iov[8].iov_base = const_cast<char*>(rn); |
| 300 iov[8].iov_len = sizeof(rn); |
| 301 |
| 302 sys_writev(fd, iov, 9); |
| 303 } |
| 304 } |
| 305 |
264 if (info.process_type_length) { | 306 if (info.process_type_length) { |
265 iov[0].iov_base = const_cast<char*>(form_data_msg); | 307 iov[0].iov_base = const_cast<char*>(form_data_msg); |
266 iov[0].iov_len = sizeof(form_data_msg) - 1; | 308 iov[0].iov_len = sizeof(form_data_msg) - 1; |
267 iov[1].iov_base = const_cast<char*>(process_type_msg); | 309 iov[1].iov_base = const_cast<char*>(process_type_msg); |
268 iov[1].iov_len = sizeof(process_type_msg) - 1; | 310 iov[1].iov_len = sizeof(process_type_msg) - 1; |
269 iov[2].iov_base = const_cast<char*>(quote_msg); | 311 iov[2].iov_base = const_cast<char*>(quote_msg); |
270 iov[2].iov_len = sizeof(quote_msg); | 312 iov[2].iov_len = sizeof(quote_msg); |
271 iov[3].iov_base = const_cast<char*>(rn); | 313 iov[3].iov_base = const_cast<char*>(rn); |
272 iov[3].iov_len = sizeof(rn); | 314 iov[3].iov_len = sizeof(rn); |
273 iov[4].iov_base = const_cast<char*>(rn); | 315 iov[4].iov_base = const_cast<char*>(rn); |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 parsed_command_line.GetSwitchValue(switches::kEnableCrashReporter)); | 695 parsed_command_line.GetSwitchValue(switches::kEnableCrashReporter)); |
654 size_t separator = switch_value.find(","); | 696 size_t separator = switch_value.find(","); |
655 if (separator != std::string::npos) { | 697 if (separator != std::string::npos) { |
656 google_update::linux_guid = switch_value.substr(0, separator); | 698 google_update::linux_guid = switch_value.substr(0, separator); |
657 base::linux_distro = switch_value.substr(separator + 1); | 699 base::linux_distro = switch_value.substr(separator + 1); |
658 } else { | 700 } else { |
659 google_update::linux_guid = switch_value; | 701 google_update::linux_guid = switch_value; |
660 } | 702 } |
661 EnableRendererCrashDumping(); | 703 EnableRendererCrashDumping(); |
662 } | 704 } |
| 705 |
| 706 // Set the base process uptime value. |
| 707 struct timeval tv; |
| 708 if (!gettimeofday(&tv, NULL)) |
| 709 uptime = tv.tv_sec; |
| 710 else |
| 711 uptime = 0; |
663 } | 712 } |
OLD | NEW |