| 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 |
| 13 # to always remove it since it may be for pre-existing crash_sender |
| 14 # process. |
| 15 CLEAN_UP_RUN_FILE=0 |
| 16 |
| 12 # File whose existence implies crash reports may be sent, and whose | 17 # File whose existence implies crash reports may be sent, and whose |
| 13 # contents includes our machine's anonymized guid. | 18 # contents includes our machine's anonymized guid. |
| 14 CONSENT_ID="/home/chronos/Consent To Send Stats" | 19 CONSENT_ID="/home/chronos/Consent To Send Stats" |
| 15 | 20 |
| 16 # Path to find which is required for computing the crash rate. | 21 # Path to find which is required for computing the crash rate. |
| 17 FIND="/usr/bin/find" | 22 FIND="/usr/bin/find" |
| 18 | 23 |
| 19 # Send up to 8 crashes per day. | 24 # Send up to 8 crashes per day. |
| 20 MAX_CRASH_RATE=8 | 25 MAX_CRASH_RATE=8 |
| 21 | 26 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 # Maximum time to sleep between sends. | 44 # Maximum time to sleep between sends. |
| 40 SECONDS_SEND_SPREAD=${SECONDS_SEND_SPREAD:-600} | 45 SECONDS_SEND_SPREAD=${SECONDS_SEND_SPREAD:-600} |
| 41 | 46 |
| 42 # The syslog tag for all logging we emit. | 47 # The syslog tag for all logging we emit. |
| 43 TAG="$(basename $0)[$$]" | 48 TAG="$(basename $0)[$$]" |
| 44 | 49 |
| 45 # Directory to store timestamp files indicating the uploads in the past 24 | 50 # Directory to store timestamp files indicating the uploads in the past 24 |
| 46 # hours. | 51 # hours. |
| 47 TIMESTAMPS_DIR="/var/lib/crash_sender" | 52 TIMESTAMPS_DIR="/var/lib/crash_sender" |
| 48 | 53 |
| 54 # Temp directory for this process. |
| 55 TMP_DIR="" |
| 56 |
| 49 lecho() { | 57 lecho() { |
| 50 logger -t "${TAG}" "$@" | 58 logger -t "${TAG}" "$@" |
| 51 } | 59 } |
| 52 | 60 |
| 53 cleanup_tmp_dir() { | 61 cleanup() { |
| 54 rm -rf "${TMP_DIR}" | 62 if [ -n "${TMP_DIR}" ]; then |
| 55 } | 63 rm -rf "${TMP_DIR}" |
| 56 | 64 fi |
| 57 cleanup_run_file_and_tmp_dir() { | 65 if [ ${CLEAN_UP_RUN_FILE} -eq 1 ]; then |
| 58 rm -f "${RUN_FILE}" | 66 rm -f "${RUN_FILE}" |
| 59 cleanup_tmp_dir | 67 fi |
| 60 } | 68 } |
| 61 | 69 |
| 62 check_not_already_running() { | 70 check_not_already_running() { |
| 63 if [ ! -f "${RUN_FILE}" ]; then | 71 set -o noclobber |
| 72 if echo $$ 2>/dev/null > "${RUN_FILE}"; then |
| 73 # Able to write RUN_FILE without contention. |
| 74 CLEAN_UP_RUN_FILE=1 |
| 75 set +o noclobber |
| 64 return | 76 return |
| 65 fi | 77 fi |
| 78 set +o noclobber |
| 66 local last_pid=$(cat "${RUN_FILE}") | 79 local last_pid=$(cat "${RUN_FILE}") |
| 67 if [ ! -f "/proc/${last_pid}/cmdline" ]; then | 80 if [ ! -f "/proc/${last_pid}/cmdline" ]; then |
| 68 trap cleanup_run_file_and_tmp_dir EXIT INT | 81 CLEAN_UP_RUN_FILE=1 |
| 82 # Note that this write may be executed by two crash_senders who |
| 83 # simulataneously reap the existing dangling run file |
| 69 echo $$ > "${RUN_FILE}" | 84 echo $$ > "${RUN_FILE}" |
| 70 return | 85 return |
| 71 fi | 86 fi |
| 72 # This could just be an unrelated process, but it's ok to be conservative. | 87 # This could just be an unrelated process, but it's ok to be conservative. |
| 73 lecho "Already running. Exiting now." | 88 lecho "Already running. Exiting now." |
| 74 exit 1 | 89 exit 1 |
| 75 } | 90 } |
| 76 | 91 |
| 77 get_version() { | 92 get_version() { |
| 78 grep ^CHROMEOS_RELEASE_VERSION /etc/lsb-release | cut -d = -f 2- | 93 grep ^CHROMEOS_RELEASE_VERSION /etc/lsb-release | cut -d = -f 2- |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 # Send was successful, now remove | 241 # Send was successful, now remove |
| 227 lecho "Successfully sent crash ${report_path} and removing" | 242 lecho "Successfully sent crash ${report_path} and removing" |
| 228 rm "${report_path}" | 243 rm "${report_path}" |
| 229 else | 244 else |
| 230 lecho "Problem sending ${report_path}, not removing" | 245 lecho "Problem sending ${report_path}, not removing" |
| 231 fi | 246 fi |
| 232 done | 247 done |
| 233 } | 248 } |
| 234 | 249 |
| 235 main() { | 250 main() { |
| 251 trap cleanup EXIT INT TERM |
| 236 if [ -e "${PAUSE_CRASH_SENDING}" ]; then | 252 if [ -e "${PAUSE_CRASH_SENDING}" ]; then |
| 237 lecho "Exiting early due to ${PAUSE_CRASH_SENDING}" | 253 lecho "Exiting early due to ${PAUSE_CRASH_SENDING}" |
| 238 exit 1 | 254 exit 1 |
| 239 fi | 255 fi |
| 240 | 256 |
| 241 check_not_already_running | 257 check_not_already_running |
| 242 | 258 |
| 243 if [ ! -x "${FIND}" ]; then | 259 if [ ! -x "${FIND}" ]; then |
| 244 lecho "Fatal: Crash sending disabled: ${FIND} not found." | 260 lecho "Fatal: Crash sending disabled: ${FIND} not found." |
| 245 exit 1 | 261 exit 1 |
| 246 fi | 262 fi |
| 247 | 263 |
| 248 TMP_DIR="$(mktemp -d /tmp/crash_sender.XXXX)" | 264 TMP_DIR="$(mktemp -d /tmp/crash_sender.XXXX)" |
| 249 trap cleanup_tmp_dir EXIT INT | |
| 250 | 265 |
| 251 # Send system-wide crashes | 266 # Send system-wide crashes |
| 252 send_crashes "/var/spool/crash" | 267 send_crashes "/var/spool/crash" |
| 253 | 268 |
| 254 # Send user-specific crashes | 269 # Send user-specific crashes |
| 255 send_crashes "/home/chronos/user/crash" | 270 send_crashes "/home/chronos/user/crash" |
| 256 } | 271 } |
| 257 | 272 |
| 258 main | 273 main |
| OLD | NEW |