shill: main: Test --help flag first

Handle the --help flag first, so it is dealt with (and we exit)
before any thought to daemonizing or setting up logging.

BUG=chromium-os:24059
TEST="shill --help" now works without "--foreground" flag

Change-Id: I410145e747519d412eb211a001ff5083aa81de66
Reviewed-on: https://gerrit.chromium.org/gerrit/12715
Reviewed-by: Thieu Le <thieule@chromium.org>
Tested-by: Paul Stewart <pstew@chromium.org>
Commit-Ready: Paul Stewart <pstew@chromium.org>
diff --git a/shill_main.cc b/shill_main.cc
index cdf241f..83c01ac 100644
--- a/shill_main.cc
+++ b/shill_main.cc
@@ -99,17 +99,16 @@
   CommandLine::Init(argc, argv);
   CommandLine* cl = CommandLine::ForCurrentProcess();
 
-  const int nochdir = 0, noclose = 0;
-  if (!cl->HasSwitch(switches::kForeground))
-    PLOG_IF(FATAL, daemon(nochdir, noclose) == -1 ) << "Failed to daemonize";
-
-  // If the help flag is set, force log in foreground.
-  SetupLogging(cl->HasSwitch(switches::kForeground) ||
-               cl->HasSwitch(switches::kHelp));
   if (cl->HasSwitch(switches::kHelp)) {
     LOG(INFO) << switches::kHelpMessage;
     return 0;
   }
+
+  const int nochdir = 0, noclose = 0;
+  if (!cl->HasSwitch(switches::kForeground))
+    PLOG_IF(FATAL, daemon(nochdir, noclose) == -1 ) << "Failed to daemonize";
+
+  SetupLogging(cl->HasSwitch(switches::kForeground));
   if (cl->HasSwitch(switches::kLogLevel)) {
     std::string log_level = cl->GetSwitchValueASCII(switches::kLogLevel);
     int level = 0;