blob: b446f7ae7bfc7b83088db835f04c6c6f0738e593 [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 Masoneee929b72011-05-10 10:02:18 -07008#include <base/command_line.h>
9#include <base/file_path.h>
10#include <base/logging.h>
11#include <chromeos/syslog_logging.h>
12
Paul Stewart75897df2011-04-27 09:05:53 -070013#include "shill/shill_daemon.h"
14#include "shill/dbus_control.h"
15
16using std::string;
17
Chris Masoneee929b72011-05-10 10:02:18 -070018namespace switches {
19
20// Don't daemon()ize; run in foreground.
21static const char kForeground[] = "foreground";
22// Directory to read confguration settings.
23static const char kConfigDir[] = "config-dir";
24// Directory to read default configuration settings (Read Only).
25static const char kDefaultConfigDir[] = "default-config-dir";
26// Flag that causes shill to show the help message and exit.
27static const char kHelp[] = "help";
28
29// The help message shown if help flag is passed to the program.
30static const char kHelpMessage[] = "\n"
31 "Available Switches: \n"
32 " --foreground\n"
33 " Don\'t daemon()ize; run in foreground.\n"
34 " --config_dir\n"
35 " Directory to read confguration settings.\n"
36 " --default_config_dir\n"
37 " Directory to read default configuration settings (Read Only).";
38} // namespace switches
39
40// Always logs to the syslog and logs to stderr if
41// we are running in the foreground.
42void SetupLogging(bool foreground) {
43 int log_flags = 0;
44 log_flags |= chromeos::kLogToSyslog;
45 if (foreground) {
46 log_flags |= chromeos::kLogToStderr;
47 }
48 chromeos::InitLog(log_flags);
49}
50
51
52int main(int argc, char** argv) {
53 CommandLine::Init(argc, argv);
54 CommandLine* cl = CommandLine::ForCurrentProcess();
55
56 // If the help flag is set, force log in foreground.
57 SetupLogging(cl->HasSwitch(switches::kForeground) ||
58 cl->HasSwitch(switches::kHelp));
59 if (cl->HasSwitch(switches::kHelp)) {
60 LOG(INFO) << switches::kHelpMessage;
61 return 0;
Paul Stewart75897df2011-04-27 09:05:53 -070062 }
63
Chris Masoneee929b72011-05-10 10:02:18 -070064 FilePath config_dir(cl->GetSwitchValueASCII(switches::kConfigDir));
65 FilePath default_config_dir(
66 !cl->HasSwitch(switches::kDefaultConfigDir) ?
67 shill::Config::kShillDefaultPrefsDir :
68 cl->GetSwitchValueASCII(switches::kDefaultConfigDir));
Paul Stewart75897df2011-04-27 09:05:53 -070069
Paul Stewart75897df2011-04-27 09:05:53 -070070 shill::Config config; /* (config_dir, default_config_dir) */
71
72 // TODO(pstew): This should be chosen based on config
73 shill::ControlInterface *control_interface = new shill::DBusControl();
74
75 shill::Daemon daemon(&config, control_interface);
Paul Stewart75897df2011-04-27 09:05:53 -070076 daemon.Run();
77
78 return 0;
79}