Register Subprocess timer callbacks prior to OnRun()

This prevents dangling pointers in cases where a Subprocess instance is
created/destroyed prior to EventLoop creation.

Change-Id: Id3a6db20353955da59b912ca555ab561ee18b4c1
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/starter/subprocess.cc b/aos/starter/subprocess.cc
index f5563e6..faa1873 100644
--- a/aos/starter/subprocess.cc
+++ b/aos/starter/subprocess.cc
@@ -151,13 +151,11 @@
           event_loop_->AddTimer([this]() { MaybeHandleSignal(); })),
       on_change_({on_change}),
       quiet_flag_(quiet_flag) {
-  event_loop_->OnRun([this]() {
-    // Every second poll to check if the child is dead. This is used as a
-    // default for the case where the user is not directly catching SIGCHLD and
-    // calling MaybeHandleSignal for us.
-    child_status_handler_->Schedule(event_loop_->monotonic_now(),
-                                    std::chrono::seconds(1));
-  });
+  // Every second poll to check if the child is dead. This is used as a
+  // default for the case where the user is not directly catching SIGCHLD and
+  // calling MaybeHandleSignal for us.
+  child_status_handler_->Schedule(event_loop_->monotonic_now(),
+                                  std::chrono::seconds(1));
 }
 
 Application::Application(const aos::Application *application,
diff --git a/aos/starter/subprocess.h b/aos/starter/subprocess.h
index 6de5cb8..784c544 100644
--- a/aos/starter/subprocess.h
+++ b/aos/starter/subprocess.h
@@ -102,8 +102,12 @@
 
   void Start() { HandleCommand(aos::starter::Command::START); }
 
+  // Stops the command by sending a SIGINT first, followed by a SIGKILL if it's
+  // still alive in 1s.
   void Stop() { HandleCommand(aos::starter::Command::STOP); }
 
+  // Stops the command the same way as Stop() does, but updates internal state
+  // to reflect that the application was terminated.
   void Terminate();
 
   // Adds a callback which gets notified when the application changes state.