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:

    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'
     $ dash -c 'a="1"; [ -n "${a}" -a "${a}" -lt 30 ] && echo 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

TEST=`rm /run/autotest_pause_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
Tested-by: Brian Norris <>
Reviewed-by: Grant Grundler <>
Commit-Queue: Brian Norris <>
1 file changed