From d39057d242965b08ead49899bf5fa9429b163067 Mon Sep 17 00:00:00 2001 From: Chris Sosa Date: Tue, 1 Mar 2011 15:16:16 -0800 Subject: [PATCH] Wait until we can initiate contact with the update engine before starting update. Change-Id: I2f741d7866192300946299f9050717721c2a644d BUG=chromium-os:12605 TEST=Changed impl of check_status to return 1 and made sure timeout got inc'd correctly and aborted. Also checked to make sure if status returned 0 i.e. update_engine_client --status returned 0, we would continue. Review URL: http://codereview.chromium.org/6594089 --- image_to_live.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/image_to_live.sh b/image_to_live.sh index a7710dcfe6..a61726a35e 100755 --- a/image_to_live.sh +++ b/image_to_live.sh @@ -307,12 +307,30 @@ function status_thread { done } +# Pings the update_engine to see if it responds or a max timeout is reached. +# Returns 1 if max timeout is reached. +function wait_until_update_engine_is_ready { + local wait_timeout=1 + local max_timeout=60 + local time_elapsed=0 + while ! get_update_var CURRENT_OP > /dev/null; do + sleep ${wait_timeout} + time_elapsed=$(( time_elapsed + wait_timeout )) + echo -n "." + if [ ${time_elapsed} -gt ${max_timeout} ]; then + return 1 + fi + done +} function run_auto_update { # Truncate the update log so our log file is clean. truncate_update_log local update_args="$(get_update_args "$(get_devserver_url)")" + info "Waiting to initiate contact with the update_engine." + wait_until_update_engine_is_ready || die "Could not contact update engine." + info "Starting update using args ${update_args}" # Sets up a secondary thread to track the update progress.