OLD | NEW |
---|---|
1 #!/bin/sh | 1 #!/bin/sh |
2 | 2 |
3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 set -e | 7 set -e |
8 | 8 |
9 # Product ID in crash report | 9 # Product ID in crash report |
10 CHROMEOS_PRODUCT=ChromeOS | 10 CHROMEOS_PRODUCT=ChromeOS |
11 | 11 |
12 # Should remove the run file when this process finishes. We don't want | 12 # Should remove the run file when this process finishes. We don't want |
13 # to always remove it since it may be for pre-existing crash_sender | 13 # to always remove it since it may be for pre-existing crash_sender |
14 # process. | 14 # process. |
15 CLEAN_UP_RUN_FILE=0 | 15 CLEAN_UP_RUN_FILE=0 |
16 | 16 |
17 # File whose existence implies crash reports may be sent, and whose | 17 # File whose existence implies crash reports may be sent, and whose |
18 # contents includes our machine's anonymized guid. | 18 # contents includes our machine's anonymized guid. |
19 CONSENT_ID="/home/chronos/Consent To Send Stats" | 19 CONSENT_ID="/home/chronos/Consent To Send Stats" |
petkov
2010/10/01 22:10:52
Unused now? Remove if so.
| |
20 | 20 |
21 # Path to find which is required for computing the crash rate. | 21 # Path to find which is required for computing the crash rate. |
22 FIND="/usr/bin/find" | 22 FIND="/usr/bin/find" |
23 | 23 |
24 # Set this to 1 in the environment to allow uploading crash reports | 24 # Set this to 1 in the environment to allow uploading crash reports |
25 # for unofficial versions. | 25 # for unofficial versions. |
26 FORCE_OFFICIAL=${FORCE_OFFICIAL:-0} | 26 FORCE_OFFICIAL=${FORCE_OFFICIAL:-0} |
27 | 27 |
28 # Path to hardware class description. | 28 # Path to hardware class description. |
29 HWCLASS_PATH="/sys/devices/platform/chromeos_acpi/HWID" | 29 HWCLASS_PATH="/sys/devices/platform/chromeos_acpi/HWID" |
30 | 30 |
31 # Maximum crashes to send per day. | 31 # Maximum crashes to send per day. |
32 MAX_CRASH_RATE=${MAX_CRASH_RATE:-32} | 32 MAX_CRASH_RATE=${MAX_CRASH_RATE:-32} |
33 | 33 |
34 # Path to metrics_client. | |
35 METRICS_CLIENT="/usr/bin/metrics_client" | |
36 | |
34 # File whose existence mocks crash sending. If empty we pretend the | 37 # File whose existence mocks crash sending. If empty we pretend the |
35 # crash sending was successful, otherwise unsuccessful. | 38 # crash sending was successful, otherwise unsuccessful. |
36 MOCK_CRASH_SENDING="/tmp/mock-crash-sending" | 39 MOCK_CRASH_SENDING="/tmp/mock-crash-sending" |
37 | 40 |
38 # File whose existence causes crash sending to be delayed (for testing). | 41 # File whose existence causes crash sending to be delayed (for testing). |
39 # Must be stateful to enable testing kernel crashes. | 42 # Must be stateful to enable testing kernel crashes. |
40 PAUSE_CRASH_SENDING="/var/lib/crash_sender_paused" | 43 PAUSE_CRASH_SENDING="/var/lib/crash_sender_paused" |
41 | 44 |
42 # URL to send official build crash reports to. | 45 # URL to send official build crash reports to. |
43 REPORT_UPLOAD_PROD_URL="http://clients2.google.com/cr/report" | 46 REPORT_UPLOAD_PROD_URL="http://clients2.google.com/cr/report" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 grep ^CHROMEOS_RELEASE_DESCRIPTION /etc/lsb-release | grep -q Official | 101 grep ^CHROMEOS_RELEASE_DESCRIPTION /etc/lsb-release | grep -q Official |
99 } | 102 } |
100 | 103 |
101 # Generate a uniform random number in 0..max-1. | 104 # Generate a uniform random number in 0..max-1. |
102 generate_uniform_random() { | 105 generate_uniform_random() { |
103 local max=$1 | 106 local max=$1 |
104 local random="$(od -An -N4 -tu /dev/urandom)" | 107 local random="$(od -An -N4 -tu /dev/urandom)" |
105 echo $((random % max)) | 108 echo $((random % max)) |
106 } | 109 } |
107 | 110 |
108 is_feedback_disabled() { | |
109 [ -r "${CONSENT_ID}" ] && return 1 | |
110 return 0 | |
111 } | |
112 | |
113 is_on_3g() { | 111 is_on_3g() { |
114 # See crosbug.com/3304. | 112 # See crosbug.com/3304. |
115 return 1 | 113 return 1 |
116 } | 114 } |
117 | 115 |
118 # Check if sending a crash now does not exceed the maximum 24hr rate and | 116 # Check if sending a crash now does not exceed the maximum 24hr rate and |
119 # commit to doing so, if not. | 117 # commit to doing so, if not. |
120 check_rate() { | 118 check_rate() { |
121 mkdir -p ${TIMESTAMPS_DIR} | 119 mkdir -p ${TIMESTAMPS_DIR} |
122 # Only consider minidumps written in the past 24 hours by removing all older. | 120 # Only consider minidumps written in the past 24 hours by removing all older. |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
285 for meta_path in $(ls -1t "${dir}"/*.meta 2>/dev/null); do | 283 for meta_path in $(ls -1t "${dir}"/*.meta 2>/dev/null); do |
286 lecho "Considering metadata ${meta_path}." | 284 lecho "Considering metadata ${meta_path}." |
287 local kind=$(get_kind "${meta_path}") | 285 local kind=$(get_kind "${meta_path}") |
288 | 286 |
289 if [ "${kind}" != "minidump" ] && [ "${kind}" != "kcrash" ]; then | 287 if [ "${kind}" != "minidump" ] && [ "${kind}" != "kcrash" ]; then |
290 lecho "Unknown report kind. Removing report." | 288 lecho "Unknown report kind. Removing report." |
291 remove_report "${meta_path}" | 289 remove_report "${meta_path}" |
292 continue | 290 continue |
293 fi | 291 fi |
294 | 292 |
295 if is_feedback_disabled; then | 293 if ${METRICS_CLIENT} -g; then |
294 lecho "Guest mode has been entered. Delaying crash sending until exited." | |
295 return 0 | |
296 fi | |
297 | |
298 if ! ${METRICS_CLIENT} -c; then | |
296 lecho "Uploading is disabled. Removing crash." | 299 lecho "Uploading is disabled. Removing crash." |
297 remove_report "${meta_path}" | 300 remove_report "${meta_path}" |
298 continue | 301 continue |
299 fi | 302 fi |
300 | 303 |
301 if ! is_mock && ! is_official; then | 304 if ! is_mock && ! is_official; then |
302 lecho "Not an official OS version. Removing crash." | 305 lecho "Not an official OS version. Removing crash." |
303 remove_report "${meta_path}" | 306 remove_report "${meta_path}" |
304 continue | 307 continue |
305 fi | 308 fi |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
340 | 343 |
341 main() { | 344 main() { |
342 trap cleanup EXIT INT TERM | 345 trap cleanup EXIT INT TERM |
343 if [ -e "${PAUSE_CRASH_SENDING}" ]; then | 346 if [ -e "${PAUSE_CRASH_SENDING}" ]; then |
344 lecho "Exiting early due to ${PAUSE_CRASH_SENDING}." | 347 lecho "Exiting early due to ${PAUSE_CRASH_SENDING}." |
345 exit 1 | 348 exit 1 |
346 fi | 349 fi |
347 | 350 |
348 check_not_already_running | 351 check_not_already_running |
349 | 352 |
350 if [ ! -x "${FIND}" ]; then | 353 for dependency in "${FIND}" "${METRICS_CLIENT}"; do |
351 lecho "Fatal: Crash sending disabled: ${FIND} not found." | 354 if [ ! -x "${dependency}" ]; then |
352 exit 1 | 355 lecho "Fatal: Crash sending disabled: ${dependency} not found." |
353 fi | 356 exit 1 |
357 fi | |
358 done | |
354 | 359 |
355 TMP_DIR="$(mktemp -d /tmp/crash_sender.XXXX)" | 360 TMP_DIR="$(mktemp -d /tmp/crash_sender.XXXX)" |
356 | 361 |
357 # Send system-wide crashes | 362 # Send system-wide crashes |
358 send_crashes "/var/spool/crash" | 363 send_crashes "/var/spool/crash" |
359 | 364 |
360 # Send user-specific crashes | 365 # Send user-specific crashes |
361 send_crashes "/home/chronos/user/crash" | 366 send_crashes "/home/chronos/user/crash" |
362 } | 367 } |
363 | 368 |
364 main | 369 main |
OLD | NEW |