init: fix startup check logic

In my zeal to kill off pointless processes, I missed that this code needs
to wait around for daisydog to return when checking for the previous boot
status.  Rework the env vars so that we don't pass -i during the check
phase.

BUG=chromium:667075
TEST=added some debugging and saw that the pre-script check phase processed output

Change-Id: I005abffd4de489f8d0136491cb11b8515e60824a
Reviewed-on: https://chromium-review.googlesource.com/419195
Commit-Ready: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/daisydog.conf b/daisydog.conf
index a026f7f..76d015f 100644
--- a/daisydog.conf
+++ b/daisydog.conf
@@ -10,16 +10,22 @@
 respawn
 expect fork
 
-env wdt_cmd="/sbin/minijail0 -i -I -p -e -l -r -v \
+env minijail_common_args="-I -p -e -l -r -v \
   -u watchdog -g watchdog \
   -- /usr/sbin/daisydog"
 
 pre-start script
+  # We need the check command to *not* background/exit early, so do not pass
+  # in the -i flag to it.  This way we can capture its output and exit status.
+  check_cmd() {
+    /sbin/minijail0 ${minijail_common_args} -c
+  }
+
   # Run in "check" mode to determine if the last reset was because
   # of a watchdog timeout.
-  if ${wdt_cmd} -c | grep -Fq "watchdog-timeout"; then
+  if check_cmd | grep -Fq "watchdog-timeout"; then
     metrics_client -v HwWatchdogReboot
   fi
 end script
 
-exec chrt -r 99 ${wdt_cmd}
+exec chrt -r 99 /sbin/minijail0 -i ${minijail_common_args}