diff options
author | Julius Werner <jwerner@chromium.org> | 2015-01-29 13:44:18 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-02-17 19:32:52 +0000 |
commit | 672d37789f6a9ba93550c229f72a56b0cc8e041d (patch) | |
tree | e7eb53b4b116bc93bdb7af608cf3022dcf4df8a8 /util | |
parent | 6c83a4d3a560c84e4f7030d3dcad583e92781f8b (diff) | |
download | chrome-ec-672d37789f6a9ba93550c229f72a56b0cc8e041d.tar.gz |
flash_ec: Add --no-ns-pid check and freeze instead of kill PTY clients
The switch to PID namespaces inside the chroot broke flash_ec's ability
to detect (and then kill) other processes that use the EC serial PTY
(leading to potential flashing failures). After a long discussion we
decided that users who need features like this should be forced to run
their chroot without PID namespacing (using cros_sdk --no-ns-pid). This
patch adds a hard check for this to flash_ec, so that using it in an
unsafe way becomes impossible.
In addition, this ports the more advanced SIGSTOP/SIGCONT logic to
flash_ec that was pioneered in fwgdb. With this, other processes
accessing that PTY will just freeze and become available again after
flash_ec finished.
BRANCH=none
BUG=chromium:444931
TEST=Ran on a Jerry with and without --no-ns-pid, with and without
an open EC terminal, all results as expected.
Change-Id: I45ffc3ec6cfe9c25a0b82b4d5288a41485c326c4
Signed-off-by: Julius Werner <jwerner@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/249835
Reviewed-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util')
-rwxr-xr-x | util/flash_ec | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/util/flash_ec b/util/flash_ec index a3ba191e12..1c0246ae92 100755 --- a/util/flash_ec +++ b/util/flash_ec @@ -199,12 +199,18 @@ ec_enable_boot0() { } # Put back the servo and the system in a clean state at exit +FROZEN_PIDS="" cleanup() { if [ -n "${save}" ]; then info "Restoring servo settings..." servo_restore "$save" fi + for pid in ${FROZEN_PIDS}; do + info "Sending SIGCONT to process ${pid}!" + kill -CONT ${pid} + done + ec_reset } trap cleanup EXIT @@ -301,29 +307,20 @@ function servo_restore() { done } -function free_pty() { - local pids - - pids=$(lsof -F p 2>/dev/null -- $1 | cut -d'p' -f2) - if [ "${pids}" == "" ]; then - return +function claim_pty() { + if grep -q cros_sdk /proc/1/cmdline; then + die "You must run this tool in a chroot that was entered with" \ + "'cros_sdk --no-ns-pid' (see crbug.com/444931 for details)" fi - # Try to kill nicely at first... - kill ${pids} - info "You'll need to re-launch console on $1" + FROZEN_PIDS=$(lsof -FR 2>/dev/null -- $1 | tr -d 'pR') - # 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 + # reverse order to SIGSTOP parents before children + for pid in $(echo ${FROZEN_PIDS} | tac -s " "); do + info "Sending SIGSTOP to process ${pid}!" + sleep 0.02 + kill -STOP ${pid} done - - # Forcibly kill - kill -9 ${pids} } # Board specific flashing scripts @@ -361,7 +358,7 @@ function flash_stm32() { fi info "Using serial flasher : ${STM32MON}" - free_pty ${EC_UART} + claim_pty ${EC_UART} if [ "${SERVO_TYPE}" = "servo" ] ; then dut_control ${MCU}_uart_en:on |