check_ethernet: fix ${paused_time} for first-run

Example error scenario:
  ## When first run at bootup, the lock does not exist:
  rm /run/autotest_pause_ethernet_hook
  ## So first-time run, sees errors:
  /usr/local/libexec/recover-duts/hooks/check_ethernet.hook

  recover_duts.log:
    2020-07-21 23:24:15,087 - DEBUG - Running of /usr/local/libexec/recover-duts/hooks/check_ethernet.hook succeeded with output: stat: cannot stat '/run/autotest_pause_ethernet_hook': No such file or directory
    2020-07-21 23:24:15-07:00  Last locked 0 seconds ago; skipping

Problems and fixes:
paused_time is both global and local. I didn't notice that [ -n
"${paused_time}" ] doesn't work properly, because it's already
initialized to 0.

Drop the global initialization and fix the subsequent bugs:

 * the '-a' operator is apparently not recommended in POSIX shell, and
   it isn't short-circuiting the way I'd like, even if it still
   functions decently:
     $ bash -c 'a=""; [ -n "${a}" -a "${a}" -lt 30 ] && echo true'
     bash: line 0: [: : integer expression expected
     $ dash -c 'a=""; [ -n "${a}" -a "${a}" -lt 30 ] && echo true'
     dash: 1: [: Illegal number:
     $ bash -c 'a="1"; [ -n "${a}" -a "${a}" -lt 30 ] && echo true'
     true
     $ dash -c 'a="1"; [ -n "${a}" -a "${a}" -lt 30 ] && echo true'
     true
 * It's technically possible to fall through without grabbing the lock
   but still leaving ${paused_time} empty. Let's handle that to be extra
   safe.

BUG=none
TEST=`rm /run/autotest_pause_ethernet_hook;
      /usr/local/libexec/recover-duts/hooks/check_ethernet.hook`
      --> Still see this error:
      stat: cannot stat '/run/autotest_pause_ethernet_hook': No such file or directory
      ---> But not this:
      Last locked 0 seconds ago; skipping

Change-Id: Ic39c93c4769f9b055a863bea5aa4ebe747622554
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crostestutils/+/2323710
Tested-by: Brian Norris <briannorris@chromium.org>
Reviewed-by: Grant Grundler <grundler@chromium.org>
Commit-Queue: Brian Norris <briannorris@chromium.org>
1 file changed