Init: Start Update Engine at startup

Also related AU Fixes:

- daemonize() for upstart

- remember success in updating across runs of the process.

- bug fixes: don't try to update if an update is in progress, clear
  actions out in Update Attempter when updating is complete.

BUG=None
TEST=on device testing

Review URL: http://codereview.chromium.org/2055008
diff --git a/main.cc b/main.cc
index b2f14c4..ed2fcf5 100644
--- a/main.cc
+++ b/main.cc
@@ -19,6 +19,8 @@
 
 DEFINE_bool(logtostderr, false,
             "Write logs to stderr instead of to a file in log_dir.");
+DEFINE_bool(foreground, false,
+            "Don't daemon()ize; run in foreground.");
 
 using std::string;
 using std::tr1::shared_ptr;
@@ -92,6 +94,9 @@
                         logging::LOG_ONLY_TO_FILE),
                        logging::DONT_LOCK_LOG_FILE,
                        logging::APPEND_TO_OLD_LOG_FILE);
+  if (!FLAGS_foreground)
+    PLOG_IF(FATAL, daemon(0, 0) == 1) << "daemon() failed";
+
   LOG(INFO) << "Chrome OS Update Engine starting";
   
   // Create the single GMainLoop