Registered signal handlers for joysticks and control loops

This *should* prevent us from leeking messages.  I'm still seeing
leaks, so I bet we aren't fully set up to handle that yet.

Change-Id: Id4a8c5c1741db3e70a3d0a836667b957aba8165a
diff --git a/aos/common/controls/control_loop-tmpl.h b/aos/common/controls/control_loop-tmpl.h
index 474c5ce..d6813fb 100644
--- a/aos/common/controls/control_loop-tmpl.h
+++ b/aos/common/controls/control_loop-tmpl.h
@@ -102,10 +102,23 @@
 
 template <class T>
 void ControlLoop<T>::Run() {
-  while (true) {
+  struct sigaction action;
+  action.sa_handler = &ControlLoop<T>::Quit;
+  sigemptyset(&action.sa_mask);
+  action.sa_flags = SA_RESETHAND;
+
+  PCHECK(sigaction(SIGTERM, &action, nullptr));
+  PCHECK(sigaction(SIGQUIT, &action, nullptr));
+  PCHECK(sigaction(SIGINT, &action, nullptr));
+
+  while (run_) {
     Iterate();
   }
+  LOG(INFO, "Shutting down\n");
 }
 
+template <class T>
+::std::atomic<bool> ControlLoop<T>::run_{true};
+
 }  // namespace controls
 }  // namespace aos