check_ethernet: hold /run/autotest_pause_ethernet_hook for script duration

Locks aren't sufficient if only one side actually acquires them. Let's
acquire the lock for the duration of the script.

We also shouldn't be removing the lock file unless we really think it's
held by a hung task. Test jobs can handle updating the file modification
time.

Also, update /var/lock to /run/lock. /run/lock is bind-mounted to
/var/lock, so these are the same, but it's nice to use the same path
name. See also https://chromium-review.googlesource.com/473968.

Quirky shell note: POSIX only specifies fd redirection for single-digit
numbers, so '9' is the highest number I can use for 'exec 9>>${FOO}'.
This would be a little nicer if I could use bash...

BUG=chromium:966965
TEST=power_SuspendStress, see check_ethernet abort
TEST=manual, don't find check_ethernet running 'ping' tests, etc., while
     we hold the lock:
     `while :; do
       touch /run/autotest_pause_ethernet_hook
       flock /run/autotest_pause_ethernet_hook pgrep -l ping
       sleep 1
     done`

Cq-Depend: chromium:1637852
Change-Id: I07274519a72fb47fc5d64038649586c7d2b6a819
Reviewed-on: https://chromium-review.googlesource.com/1637489
Commit-Ready: Brian Norris <briannorris@chromium.org>
Tested-by: Brian Norris <briannorris@chromium.org>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Grant Grundler <grundler@chromium.org>
1 file changed