periodic_scheduler: move timeout value to the jobs themselves

Rather than clamp the runtime of the job to 5 minutes, let the job
declare its max timeout value.  Some jobs want to run for more than
5 minutes (like crash_sender).

BUG=chromium:377981
TEST=`./periodic_scheduler_unittest` passes
CQ-DEPEND=CL:201404

Change-Id: If411bf01e96007ee8a4a83e144f5b8306c48103c
Reviewed-on: https://chromium-review.googlesource.com/201719
Commit-Queue: Mike Frysinger <vapier@chromium.org>
Tested-by: Mike Frysinger <vapier@chromium.org>
Reviewed-by: Gaurav Shah <gauravsh@chromium.org>
diff --git a/log-rotate.conf b/log-rotate.conf
index c465959..dc6448e 100644
--- a/log-rotate.conf
+++ b/log-rotate.conf
@@ -2,10 +2,10 @@
 # Use of this source code is governed by a BSD-style license that can be
 # found in the LICENSE file.
 
-description     "Run the crash sender periodically"
+description     "Rotate the system logs"
 author          "chromium-os-dev@chromium.org"
 
 start on starting system-services
 stop on stopping system-services
 
-exec periodic_scheduler 86400 cleanup_logs /usr/sbin/chromeos-cleanup-logs
+exec periodic_scheduler 86400 600 cleanup_logs /usr/sbin/chromeos-cleanup-logs
diff --git a/periodic_scheduler b/periodic_scheduler
index 73fe94c..a6589bf 100755
--- a/periodic_scheduler
+++ b/periodic_scheduler
@@ -5,7 +5,7 @@
 # found in the LICENSE file.
 
 # Run tasks periodically.
-# Usage: $0  <delay_seconds> <task_name> <task_binary>
+# Usage: $0 <delay_seconds> <timeout_seconds> <task_name> <task_binary>
 #
 # Executes task <task_name> by running <task_binary> every <delay_seconds>.
 
@@ -35,11 +35,13 @@
 
 main() {
   local delay="$1"
-  local name="$2"
+  local timeout="$2"
+  local name="$3"
   local spool_file="${SPOOL_DIR}/${name}"
-  shift 2
+  shift 3
 
   [ -z "${delay}" ] && exit 1
+  [ -z "${timeout}" ] && exit 1
   [ -z "${name}" ] && exit 1
   [ $# -eq 0 ] && exit 1
   check_and_fix_spool_paths
@@ -57,15 +59,9 @@
     if [ ${time_diff} -gt ${delay} ]; then
       rm "${spool_file}" || true
       touch "${spool_file}"
-      # Make sure to reclaim status info about background processes.
-      # At this point, all background processes should be dead.
-      # We don't actually care about the result though.
-      wait || true
       log "${name}: running $*"
-      (
-        timeout -k ${KILL_DELAY} ${CHECK_DELAY} "$@" || true
-        log "${name}: job completed"
-      ) &
+      timeout -k ${KILL_DELAY} ${timeout} "$@" || true
+      log "${name}: job completed"
     fi
   done
 }