From 39194d5fc584199fad690939b362e61b1aa4a12d Mon Sep 17 00:00:00 2001 From: Doug Anderson Date: Thu, 20 Mar 2014 14:12:12 -0700 Subject: [PATCH] flash_ec: Only kill -9 as a last resort When we use 'kill -9' to kill other users of the serial port then we end up with stale lockfile warnings. Try to use a normal kill first to be a little nicer. BRANCH=ToT BUG=None TEST=flash_ec and no longer get stale lockfile messages from cu. Change-Id: Idb39ca803a9c54b6fe972f6854515ea5a8bdab03 Signed-off-by: Doug Anderson Reviewed-on: https://chromium-review.googlesource.com/194190 Reviewed-by: Vincent Palatin Reviewed-by: Randall Spangler --- util/flash_ec | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/util/flash_ec b/util/flash_ec index 34ee8b4ea8..b016cae3d7 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -135,11 +135,28 @@ function servo_restore() { } function free_pty() { + local pids + pids=$(lsof -F p 2>/dev/null -- $1 | cut -d'p' -f2) - if [ "${pids}" != "" ]; then - kill -9 ${pids} - info "You'll need to re-launch console on $1" + if [ "${pids}" == "" ]; then + return fi + + # Try to kill nicely at first... + kill ${pids} + info "You'll need to re-launch console on $1" + + # Wait up to 3 seconds for them to die... + for i in $(seq 30); do + pids=$(lsof -F p 2>/dev/null -- $1 | cut -d'p' -f2) + if [ "${pids}" == "" ]; then + return + fi + sleep .1 + done + + # Forcibly kill + kill -9 ${pids} } # Board specific flashing scripts