periodic_scheduler: fix timeout invocation

The current code forgets to pass a time spec to the -k param leading
it to barf whenever it tries to run a job:
 + timeout -k 300 sh -c "$@" -- /sbin/crash_sender
 timeout: invalid time interval 'sh'
 Try 'timeout --help' for more information.

Set the kill fallback to 10 seconds.  This will fire after the main
timeout has been sent to the code.

While we're here, drop the shell indirection.  None of our jobs are
using it, and it's not clear whether we want to let people run shell
code directly rather than just invoke a program.  This saves us from
spawning the shell and leaving it running for the life of the job.

BUG=chromium:375989
TEST=manual; loaded onto a dev device and watched crash_sender get run

Change-Id: I4cb6dc752c415803047bb4c3eb310589ab444d0d
Reviewed-on: https://chromium-review.googlesource.com/201350
Reviewed-by: Ben Chan <benchan@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
diff --git a/periodic_scheduler b/periodic_scheduler
index e17a478..73fe94c 100755
--- a/periodic_scheduler
+++ b/periodic_scheduler
@@ -13,6 +13,7 @@
 
 SCRIPT_NAME="$(basename "$0")"
 CHECK_DELAY=300  # Check every 5 minutes.
+KILL_DELAY=10    # How long to let the job clean up after a timeout.
 SPOOL_DIR=/var/spool/cron-lite
 
 log() {
@@ -45,7 +46,7 @@
 
   while true; do
     # Allow the sleep to be killed manually without terminating the handler.
-    sleep "${CHECK_DELAY}" || true
+    sleep $(( CHECK_DELAY + KILL_DELAY )) || true
 
     [ ! -e "${spool_file}" ] && touch "${spool_file}"
 
@@ -62,7 +63,7 @@
       wait || true
       log "${name}: running $*"
       (
-        timeout -k ${CHECK_DELAY} sh -c '"$@"' -- "$@" || true
+        timeout -k ${KILL_DELAY} ${CHECK_DELAY} "$@" || true
         log "${name}: job completed"
       ) &
     fi