blob: ea458591b6277bb2fe82587ce4303c99ce41ef65 [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <time.h>
6#include <string>
Paul Stewart75897df2011-04-27 09:05:53 -07007
Chris Masone0e1d1042011-05-09 18:07:03 -07008#include <base/at_exit.h>
Chris Masoneee929b72011-05-10 10:02:18 -07009#include <base/command_line.h>
10#include <base/file_path.h>
11#include <base/logging.h>
12#include <chromeos/syslog_logging.h>
13
Paul Stewart75897df2011-04-27 09:05:53 -070014#include "shill/shill_daemon.h"
15#include "shill/dbus_control.h"
16
17using std::string;
18
Chris Masoneee929b72011-05-10 10:02:18 -070019namespace switches {
20
21// Don't daemon()ize; run in foreground.
22static const char kForeground[] = "foreground";
23// Directory to read confguration settings.
24static const char kConfigDir[] = "config-dir";
25// Directory to read default configuration settings (Read Only).
26static const char kDefaultConfigDir[] = "default-config-dir";
27// Flag that causes shill to show the help message and exit.
28static const char kHelp[] = "help";
29
30// The help message shown if help flag is passed to the program.
31static const char kHelpMessage[] = "\n"
32 "Available Switches: \n"
33 " --foreground\n"
34 " Don\'t daemon()ize; run in foreground.\n"
35 " --config_dir\n"
36 " Directory to read confguration settings.\n"
37 " --default_config_dir\n"
38 " Directory to read default configuration settings (Read Only).";
39} // namespace switches
40
41// Always logs to the syslog and logs to stderr if
42// we are running in the foreground.
43void SetupLogging(bool foreground) {
44 int log_flags = 0;
45 log_flags |= chromeos::kLogToSyslog;
46 if (foreground) {
47 log_flags |= chromeos::kLogToStderr;
48 }
49 chromeos::InitLog(log_flags);
50}
51
52
53int main(int argc, char** argv) {
Chris Masone0e1d1042011-05-09 18:07:03 -070054 base::AtExitManager exit_manager;
Chris Masoneee929b72011-05-10 10:02:18 -070055 CommandLine::Init(argc, argv);
56 CommandLine* cl = CommandLine::ForCurrentProcess();
57
58 // If the help flag is set, force log in foreground.
59 SetupLogging(cl->HasSwitch(switches::kForeground) ||
60 cl->HasSwitch(switches::kHelp));
61 if (cl->HasSwitch(switches::kHelp)) {
62 LOG(INFO) << switches::kHelpMessage;
63 return 0;
Paul Stewart75897df2011-04-27 09:05:53 -070064 }
65
Chris Masoneee929b72011-05-10 10:02:18 -070066 FilePath config_dir(cl->GetSwitchValueASCII(switches::kConfigDir));
67 FilePath default_config_dir(
68 !cl->HasSwitch(switches::kDefaultConfigDir) ?
69 shill::Config::kShillDefaultPrefsDir :
70 cl->GetSwitchValueASCII(switches::kDefaultConfigDir));
Paul Stewart75897df2011-04-27 09:05:53 -070071
Paul Stewart75897df2011-04-27 09:05:53 -070072 shill::Config config; /* (config_dir, default_config_dir) */
73
74 // TODO(pstew): This should be chosen based on config
75 shill::ControlInterface *control_interface = new shill::DBusControl();
76
77 shill::Daemon daemon(&config, control_interface);
Paul Stewart75897df2011-04-27 09:05:53 -070078 daemon.Run();
79
80 return 0;
81}