| 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 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 TAG="$(basename $0)[$$]" | 39 TAG="$(basename $0)[$$]" |
| 40 | 40 |
| 41 # Directory to store timestamp files indicating the uploads in the past 24 | 41 # Directory to store timestamp files indicating the uploads in the past 24 |
| 42 # hours. | 42 # hours. |
| 43 TIMESTAMPS_DIR="/var/lib/crash_sender" | 43 TIMESTAMPS_DIR="/var/lib/crash_sender" |
| 44 | 44 |
| 45 lecho() { | 45 lecho() { |
| 46 logger -t "${TAG}" "$@" | 46 logger -t "${TAG}" "$@" |
| 47 } | 47 } |
| 48 | 48 |
| 49 log_done() { | |
| 50 lecho "Done" | |
| 51 } | |
| 52 | |
| 53 cleanup_tmp_dir() { | 49 cleanup_tmp_dir() { |
| 54 rm -rf "${TMP_DIR}" | 50 rm -rf "${TMP_DIR}" |
| 55 log_done | |
| 56 } | 51 } |
| 57 | 52 |
| 58 cleanup_run_file_and_tmp_dir() { | 53 cleanup_run_file_and_tmp_dir() { |
| 59 rm -f "${RUN_FILE}" | 54 rm -f "${RUN_FILE}" |
| 60 cleanup_tmp_dir | 55 cleanup_tmp_dir |
| 61 } | 56 } |
| 62 | 57 |
| 63 check_not_already_running() { | 58 check_not_already_running() { |
| 64 if [ ! -f "${RUN_FILE}" ]; then | 59 if [ ! -f "${RUN_FILE}" ]; then |
| 65 return | 60 return |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 if [ ${sends_in_24hrs} -ge ${MAX_CRASH_RATE} ]; then | 107 if [ ${sends_in_24hrs} -ge ${MAX_CRASH_RATE} ]; then |
| 113 lecho "Cannot send more crashes:" | 108 lecho "Cannot send more crashes:" |
| 114 lecho " current ${sends_in_24hrs}send/24hrs >= " \ | 109 lecho " current ${sends_in_24hrs}send/24hrs >= " \ |
| 115 "max ${MAX_CRASH_RATE}send/24hrs" | 110 "max ${MAX_CRASH_RATE}send/24hrs" |
| 116 return 1 | 111 return 1 |
| 117 fi | 112 fi |
| 118 mktemp "${TIMESTAMPS_DIR}"/XXXX > /dev/null | 113 mktemp "${TIMESTAMPS_DIR}"/XXXX > /dev/null |
| 119 return 0 | 114 return 0 |
| 120 } | 115 } |
| 121 | 116 |
| 117 # Return if $1 is a .core file |
| 118 is_core_file() { |
| 119 local filename=$1 |
| 120 [ "${filename##*.}" = "core" ] |
| 121 } |
| 122 |
| 122 send_crash() { | 123 send_crash() { |
| 123 local sleep_time=$(generate_uniform_random $SECONDS_SEND_SPREAD) | 124 local sleep_time=$(generate_uniform_random $SECONDS_SEND_SPREAD) |
| 124 local url="${MINIDUMP_UPLOAD_STAGING_URL}" | 125 local url="${MINIDUMP_UPLOAD_STAGING_URL}" |
| 125 if is_official; then | 126 if is_official; then |
| 126 url="${MINIDUMP_UPLOAD_PROD_URL}" | 127 url="${MINIDUMP_UPLOAD_PROD_URL}" |
| 127 fi | 128 fi |
| 128 lecho "Sending crash:" | 129 lecho "Sending crash:" |
| 129 lecho " Scheduled to send in ${sleep_time}s" | 130 lecho " Scheduled to send in ${sleep_time}s" |
| 130 lecho " Minidump: ${minidump_path}" | 131 lecho " Minidump: ${minidump_path}" |
| 131 lecho " URL: ${url}" | 132 lecho " URL: ${url}" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 rm -f "${report_id}" "${output_file}" | 177 rm -f "${report_id}" "${output_file}" |
| 177 | 178 |
| 178 return ${curl_result} | 179 return ${curl_result} |
| 179 } | 180 } |
| 180 | 181 |
| 181 # Send all crashes from the given directory. The directory is currently | 182 # Send all crashes from the given directory. The directory is currently |
| 182 # expected to just contain a bunch of minidumps. | 183 # expected to just contain a bunch of minidumps. |
| 183 send_crashes() { | 184 send_crashes() { |
| 184 local dir="$1" | 185 local dir="$1" |
| 185 lecho "Considering crashes in ${dir}" | 186 lecho "Considering crashes in ${dir}" |
| 187 |
| 186 # Cycle through minidumps, most recent first. That way if we're about | 188 # Cycle through minidumps, most recent first. That way if we're about |
| 187 # to exceed the daily rate, we send the most recent minidumps. | 189 # to exceed the daily rate, we send the most recent minidumps. |
| 188 if [ ! -d "${dir}" ]; then | 190 if [ ! -d "${dir}" ]; then |
| 189 return | 191 return |
| 190 fi | 192 fi |
| 191 for file in $(ls -1t "${dir}"); do | 193 for file in $(ls -1t "${dir}"); do |
| 192 local minidump_path="${dir}/${file}" | 194 local minidump_path="${dir}/${file}" |
| 193 lecho "Considering crash ${minidump_path}" | 195 lecho "Considering file ${minidump_path}" |
| 196 if is_core_file "${minidump_path}"; then |
| 197 lecho "Ignoring core file." |
| 198 continue |
| 199 fi |
| 194 if ! check_rate; then | 200 if ! check_rate; then |
| 195 lecho "Sending ${minidump_path} would exceed rate. Leaving for later." | 201 lecho "Sending ${minidump_path} would exceed rate. Leaving for later." |
| 196 return 0 | 202 return 0 |
| 197 fi | 203 fi |
| 198 local chromeos_version=$(get_version) | 204 local chromeos_version=$(get_version) |
| 199 if is_feedback_disabled; then | 205 if is_feedback_disabled; then |
| 200 lecho "Uploading is disabled. Removing crash." | 206 lecho "Uploading is disabled. Removing crash." |
| 201 rm "${minidump_path}" | 207 rm "${minidump_path}" |
| 202 elif is_on_3g; then | 208 elif is_on_3g; then |
| 203 lecho "Not sending crash report while on 3G, saving for later." | 209 lecho "Not sending crash report while on 3G, saving for later." |
| 204 elif send_crash ${minidump_path}; then | 210 elif send_crash ${minidump_path}; then |
| 205 # Send was successful, now remove | 211 # Send was successful, now remove |
| 206 lecho "Successfully sent crash ${minidump_path} and removing" | 212 lecho "Successfully sent crash ${minidump_path} and removing" |
| 207 rm "${minidump_path}" | 213 rm "${minidump_path}" |
| 208 else | 214 else |
| 209 lecho "Problem sending ${minidump_path}, not removing" | 215 lecho "Problem sending ${minidump_path}, not removing" |
| 210 fi | 216 fi |
| 211 done | 217 done |
| 212 } | 218 } |
| 213 | 219 |
| 214 main() { | 220 main() { |
| 215 lecho "Starting" | |
| 216 trap log_done EXIT INT | |
| 217 | |
| 218 if [ -e "${PAUSE_CRASH_SENDING}" ]; then | 221 if [ -e "${PAUSE_CRASH_SENDING}" ]; then |
| 219 lecho "Exiting early due to ${PAUSE_CRASH_SENDING}" | 222 lecho "Exiting early due to ${PAUSE_CRASH_SENDING}" |
| 220 exit 1 | 223 exit 1 |
| 221 fi | 224 fi |
| 222 | 225 |
| 223 check_not_already_running | 226 check_not_already_running |
| 224 | 227 |
| 225 TMP_DIR="$(mktemp -d /tmp/crash_sender.XXXX)" | 228 TMP_DIR="$(mktemp -d /tmp/crash_sender.XXXX)" |
| 226 trap cleanup_tmp_dir EXIT INT | 229 trap cleanup_tmp_dir EXIT INT |
| 227 | 230 |
| 228 # Send system-wide crashes | 231 # Send system-wide crashes |
| 229 send_crashes "/var/spool/crash" | 232 send_crashes "/var/spool/crash" |
| 230 | 233 |
| 231 # Send user-specific crashes | 234 # Send user-specific crashes |
| 232 send_crashes "/home/chronos/user/crash" | 235 send_crashes "/home/chronos/user/crash" |
| 233 } | 236 } |
| 234 | 237 |
| 235 main | 238 main |
| OLD | NEW |