mukesh agrawal | 4350006 | 2012-02-09 18:25:15 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 5 | #include <errno.h> |
Ben Chan | 03ed818 | 2012-04-19 20:39:27 -0700 | [diff] [blame] | 6 | #include <glib-unix.h> |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 7 | #include <stdio.h> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 8 | #include <time.h> |
Gaurav Shah | b893bed | 2011-11-28 19:37:16 -0800 | [diff] [blame] | 9 | #include <unistd.h> |
| 10 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 11 | #include <string> |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 12 | #include <vector> |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 13 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 14 | #include <base/at_exit.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 15 | #include <base/command_line.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 16 | #include <base/files/file_path.h> |
Garret Kelly | 782cdce | 2015-04-01 16:39:16 -0400 | [diff] [blame] | 17 | #include <base/strings/string_number_conversions.h> |
Ben Chan | a0ddf46 | 2014-02-06 11:32:42 -0800 | [diff] [blame] | 18 | #include <base/strings/string_split.h> |
Utkarsh Sanghi | 83bd64b | 2014-07-29 16:01:43 -0700 | [diff] [blame] | 19 | #include <chromeos/minijail/minijail.h> |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 20 | #include <chromeos/syslog_logging.h> |
| 21 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 22 | #include "shill/dbus_control.h" |
Jason Simmons | 5a2097c | 2015-02-10 18:03:08 -0800 | [diff] [blame] | 23 | #include "shill/error.h" |
Peter Qiu | 40a0148 | 2014-10-31 11:54:23 -0700 | [diff] [blame] | 24 | #include "shill/glib_io_handler_factory.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 25 | #include "shill/logging.h" |
Peter Qiu | 40a0148 | 2014-10-31 11:54:23 -0700 | [diff] [blame] | 26 | #include "shill/net/io_handler_factory_container.h" |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 27 | #include "shill/shared_dbus_connection.h" |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 28 | #include "shill/shill_config.h" |
Darin Petkov | d1b715b | 2011-06-02 21:21:22 -0700 | [diff] [blame] | 29 | #include "shill/shill_daemon.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 30 | |
Albert Chaulk | 0e1cdea | 2013-02-27 15:32:55 -0800 | [diff] [blame] | 31 | using base::FilePath; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 32 | using std::string; |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 33 | using std::vector; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 34 | |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 35 | namespace switches { |
| 36 | |
| 37 | // Don't daemon()ize; run in foreground. |
| 38 | static const char kForeground[] = "foreground"; |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 39 | // Don't attempt to manage these devices. |
| 40 | static const char kDeviceBlackList[] = "device-black-list"; |
Paul Stewart | 83d6256 | 2015-02-09 19:57:47 -0800 | [diff] [blame] | 41 | // Ignore Ethernet-like devices that don't have any driver information. |
| 42 | static const char kIgnoreUnknownEthernet[] = "ignore-unknown-ethernet"; |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 43 | // Technologies to enable for portal check at startup. |
| 44 | static const char kPortalList[] = "portal-list"; |
Peter Qiu | 1d499ed | 2015-01-30 16:01:27 -0800 | [diff] [blame] | 45 | // When in passive mode, Shill will not manage any devices by default. |
| 46 | // Remote service can instruct Shill to manage/unmanage devices through |
| 47 | // org.chromium.flimflam.Manager's ClaimInterface/ReleaseInterface APIs. |
| 48 | static const char kPassiveMode[] = "passive-mode"; |
Jason Simmons | 5a2097c | 2015-02-10 18:03:08 -0800 | [diff] [blame] | 49 | // Default priority order of the technologies. |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 50 | static const char kTechnologyOrder[] = "default-technology-order"; |
Garret Kelly | c5f89d1 | 2015-02-18 14:39:36 -0500 | [diff] [blame] | 51 | // Comma-separated list of DNS servers to prepend to the resolver list. |
| 52 | static const char kPrependDNSServers[] = "prepend-dns-servers"; |
Garret Kelly | 782cdce | 2015-04-01 16:39:16 -0400 | [diff] [blame] | 53 | // The minimum MTU value that will be respected in DHCP responses. |
| 54 | static const char kMinimumMTU[] = "minimum-mtu"; |
Matthew Wein | 08add48 | 2015-04-20 13:26:48 -0700 | [diff] [blame] | 55 | // Accept hostname from the DHCP server for the specified devices. |
| 56 | // eg. eth0 or eth* |
| 57 | static const char kAcceptHostnameFrom[] = "accept-hostname-from"; |
Peter Qiu | d48fa0c | 2015-06-10 12:20:48 -0700 | [diff] [blame] | 58 | #ifndef DISABLE_DHCPV6 |
| 59 | // List of devices to enable DHCPv6. |
| 60 | static const char kDhcpv6EnabledDevices[] = "dhcpv6-enabled-devices"; |
| 61 | #endif // DISABLE_DHCPV6 |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 62 | // Flag that causes shill to show the help message and exit. |
| 63 | static const char kHelp[] = "help"; |
| 64 | |
| 65 | // The help message shown if help flag is passed to the program. |
| 66 | static const char kHelpMessage[] = "\n" |
| 67 | "Available Switches: \n" |
| 68 | " --foreground\n" |
| 69 | " Don\'t daemon()ize; run in foreground.\n" |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 70 | " --device-black-list=device1,device2\n" |
| 71 | " Do not manage devices named device1 or device2\n" |
Paul Stewart | 83d6256 | 2015-02-09 19:57:47 -0800 | [diff] [blame] | 72 | " --ignore-unknown-ethernet\n" |
| 73 | " Ignore Ethernet-like devices that do not report a driver\n" |
Chris Masone | 7ccc819 | 2011-05-24 14:54:49 -0700 | [diff] [blame] | 74 | " --log-level=N\n" |
Ben Chan | 156e73f | 2012-04-20 12:02:10 -0700 | [diff] [blame] | 75 | " Logging level:\n" |
| 76 | " 0 = LOG(INFO), 1 = LOG(WARNING), 2 = LOG(ERROR),\n" |
| 77 | " -1 = SLOG(..., 1), -2 = SLOG(..., 2), etc.\n" |
| 78 | " --log-scopes=\"*scope1+scope2\".\n" |
| 79 | " Scopes to enable for SLOG()-based logging.\n" |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 80 | " --portal-list=technology1,technology2\n" |
Peter Qiu | 1d499ed | 2015-01-30 16:01:27 -0800 | [diff] [blame] | 81 | " Specify technologies to perform portal detection on at startup.\n" |
| 82 | " --passive-mode\n" |
Jason Simmons | 5a2097c | 2015-02-10 18:03:08 -0800 | [diff] [blame] | 83 | " Do not manage any devices by default\n" |
| 84 | " --default-technology-order=technology1,technology2\n" |
Garret Kelly | c5f89d1 | 2015-02-18 14:39:36 -0500 | [diff] [blame] | 85 | " Specify the default priority order of the technologies.\n" |
| 86 | " --prepend-dns-servers=server1,server2,...\n" |
Garret Kelly | 782cdce | 2015-04-01 16:39:16 -0400 | [diff] [blame] | 87 | " Prepend the provided DNS servers to the resolver list.\n" |
Matthew Wein | 08add48 | 2015-04-20 13:26:48 -0700 | [diff] [blame] | 88 | " --accept-hostname-from=eth0 or --accept-hostname-from=eth*\n" |
| 89 | " Accept a hostname from the DHCP server for the matching devices.\n" |
Peter Qiu | d48fa0c | 2015-06-10 12:20:48 -0700 | [diff] [blame] | 90 | #ifndef DISABLE_DHCPV6 |
| 91 | " --dhcpv6-enabled-devices=device1,device2\n" |
| 92 | " Enable DHCPv6 for devices named device1 and device2\n" |
| 93 | #endif // DISABLE_DHCPV6 |
Garret Kelly | 782cdce | 2015-04-01 16:39:16 -0400 | [diff] [blame] | 94 | " --minimum-mtu=mtu\n" |
| 95 | " Set the minimum value to respect as the MTU from DHCP responses.\n"; |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 96 | } // namespace switches |
| 97 | |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 98 | namespace { |
| 99 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 100 | const char* kLoggerCommand = "/usr/bin/logger"; |
| 101 | const char* kLoggerUser = "syslog"; |
| 102 | const char* kDefaultTechnologyOrder = "vpn,ethernet,wifi,wimax,cellular"; |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 103 | |
| 104 | } // namespace |
| 105 | |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 106 | // Always logs to the syslog and logs to stderr if |
| 107 | // we are running in the foreground. |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 108 | void SetupLogging(bool foreground, char* daemon_name) { |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 109 | int log_flags = 0; |
| 110 | log_flags |= chromeos::kLogToSyslog; |
mukesh agrawal | 4350006 | 2012-02-09 18:25:15 -0800 | [diff] [blame] | 111 | log_flags |= chromeos::kLogHeader; |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 112 | if (foreground) { |
| 113 | log_flags |= chromeos::kLogToStderr; |
| 114 | } |
| 115 | chromeos::InitLog(log_flags); |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 116 | |
| 117 | if (!foreground) { |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 118 | vector<char*> logger_command_line; |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 119 | int logger_stdin_fd; |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 120 | logger_command_line.push_back(const_cast<char*>(kLoggerCommand)); |
| 121 | logger_command_line.push_back(const_cast<char*>("--priority")); |
| 122 | logger_command_line.push_back(const_cast<char*>("daemon.err")); |
| 123 | logger_command_line.push_back(const_cast<char*>("--tag")); |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 124 | logger_command_line.push_back(daemon_name); |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 125 | logger_command_line.push_back(nullptr); |
Jorge Lucangeli Obes | 8c1706f | 2012-08-30 15:30:48 -0700 | [diff] [blame] | 126 | |
Paul Stewart | 1a212a6 | 2015-06-16 13:13:10 -0700 | [diff] [blame] | 127 | chromeos::Minijail* minijail = chromeos::Minijail::GetInstance(); |
| 128 | struct minijail* jail = minijail->New(); |
Utkarsh Sanghi | e4c6aff | 2014-07-30 14:49:03 -0700 | [diff] [blame] | 129 | minijail->DropRoot(jail, kLoggerUser, kLoggerUser); |
Jorge Lucangeli Obes | 8c1706f | 2012-08-30 15:30:48 -0700 | [diff] [blame] | 130 | |
Ben Chan | cc225ef | 2014-09-30 13:26:51 -0700 | [diff] [blame] | 131 | if (!minijail->RunPipeAndDestroy(jail, logger_command_line, nullptr, |
| 132 | &logger_stdin_fd)) { |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 133 | LOG(ERROR) << "Unable to spawn logger. " |
| 134 | << "Writes to stderr will be discarded."; |
| 135 | return; |
| 136 | } |
| 137 | |
| 138 | // Note that we don't set O_CLOEXEC here. This means that stderr |
| 139 | // from any child processes will, by default, be logged to syslog. |
| 140 | if (dup2(logger_stdin_fd, fileno(stderr)) != fileno(stderr)) { |
Alex Deymo | af19870 | 2015-04-09 10:06:31 -0700 | [diff] [blame] | 141 | PLOG(ERROR) << "Failed to redirect stderr to syslog"; |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 142 | } |
| 143 | close(logger_stdin_fd); |
| 144 | } |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 147 | gboolean ExitSigHandler(gpointer data) { |
Paul Stewart | 63864b6 | 2012-11-07 15:10:55 -0800 | [diff] [blame] | 148 | LOG(INFO) << "Shutting down due to received signal."; |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 149 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 150 | shill::Daemon* daemon = reinterpret_cast<shill::Daemon*>(data); |
| 151 | daemon->Quit(); |
| 152 | return TRUE; |
| 153 | } |
| 154 | |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 155 | |
| 156 | int main(int argc, char** argv) { |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 157 | base::AtExitManager exit_manager; |
Alex Vakulenko | 127f256 | 2015-04-02 14:31:10 -0700 | [diff] [blame] | 158 | base::CommandLine::Init(argc, argv); |
| 159 | base::CommandLine* cl = base::CommandLine::ForCurrentProcess(); |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 160 | |
Chris Masone | ee929b7 | 2011-05-10 10:02:18 -0700 | [diff] [blame] | 161 | if (cl->HasSwitch(switches::kHelp)) { |
| 162 | LOG(INFO) << switches::kHelpMessage; |
| 163 | return 0; |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 164 | } |
Paul Stewart | b716325 | 2011-12-09 16:21:30 -0800 | [diff] [blame] | 165 | |
| 166 | const int nochdir = 0, noclose = 0; |
| 167 | if (!cl->HasSwitch(switches::kForeground)) |
Wade Guthrie | bb5d4a6 | 2013-06-07 09:41:51 -0700 | [diff] [blame] | 168 | PLOG_IF(FATAL, daemon(nochdir, noclose) == -1) << "Failed to daemonize"; |
Paul Stewart | b716325 | 2011-12-09 16:21:30 -0800 | [diff] [blame] | 169 | |
mukesh agrawal | 7eb0289 | 2012-05-29 11:22:37 -0700 | [diff] [blame] | 170 | SetupLogging(cl->HasSwitch(switches::kForeground), argv[0]); |
Prathmesh Prabhu | f002cdb | 2014-09-17 22:41:05 -0700 | [diff] [blame] | 171 | shill::SetLogLevelFromCommandLine(cl); |
Ben Chan | 156e73f | 2012-04-20 12:02:10 -0700 | [diff] [blame] | 172 | |
Peter Qiu | 40a0148 | 2014-10-31 11:54:23 -0700 | [diff] [blame] | 173 | // Overwrite default IOHandlerFactory with the glib version of it. This needs |
| 174 | // to be placed before any reference to the IOHandlerFactory. |
| 175 | shill::IOHandlerFactoryContainer::GetInstance()->SetIOHandlerFactory( |
| 176 | new shill::GlibIOHandlerFactory()); |
| 177 | |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 178 | // TODO(pstew): This should be chosen based on config |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 179 | shill::SharedDBusConnection::GetInstance()->Init(); |
Thieu Le | b52d6ff | 2011-11-02 18:21:51 +0000 | [diff] [blame] | 180 | shill::DBusControl* dbus_control = new shill::DBusControl(); |
Darin Petkov | aceede3 | 2011-07-18 15:32:38 -0700 | [diff] [blame] | 181 | dbus_control->Init(); |
| 182 | |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 183 | shill::Daemon::Settings settings; |
| 184 | if (cl->HasSwitch(switches::kTechnologyOrder)) { |
Jason Simmons | 5a2097c | 2015-02-10 18:03:08 -0800 | [diff] [blame] | 185 | shill::Error error; |
| 186 | string order_flag = cl->GetSwitchValueASCII( |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 187 | switches::kTechnologyOrder); |
| 188 | vector<shill::Technology::Identifier> test_order_vector; |
| 189 | if (shill::Technology::GetTechnologyVectorFromString( |
| 190 | order_flag, &test_order_vector, &error)) { |
| 191 | settings.default_technology_order = order_flag; |
| 192 | } else { |
Jason Simmons | 5a2097c | 2015-02-10 18:03:08 -0800 | [diff] [blame] | 193 | LOG(ERROR) << "Invalid default technology order: [" << order_flag |
| 194 | << "] Error: " << error.message(); |
| 195 | } |
| 196 | } |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 197 | if (settings.default_technology_order.empty()) { |
| 198 | settings.default_technology_order = kDefaultTechnologyOrder; |
Jason Simmons | 5a2097c | 2015-02-10 18:03:08 -0800 | [diff] [blame] | 199 | } |
| 200 | |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 201 | if (cl->HasSwitch(switches::kDeviceBlackList)) { |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 202 | base::SplitString(cl->GetSwitchValueASCII(switches::kDeviceBlackList), |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 203 | ',', &settings.device_blacklist); |
mukesh agrawal | 8f317b6 | 2011-07-15 11:53:23 -0700 | [diff] [blame] | 204 | } |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 205 | |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 206 | settings.ignore_unknown_ethernet = |
| 207 | cl->HasSwitch(switches::kIgnoreUnknownEthernet); |
Paul Stewart | 83d6256 | 2015-02-09 19:57:47 -0800 | [diff] [blame] | 208 | |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 209 | if (cl->HasSwitch(switches::kPortalList)) { |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 210 | settings.use_portal_list = true; |
| 211 | settings.portal_list = cl->GetSwitchValueASCII(switches::kPortalList); |
Paul Stewart | 10e9e4e | 2012-04-26 19:46:28 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 214 | settings.passive_mode = cl->HasSwitch(switches::kPassiveMode); |
Peter Qiu | 1d499ed | 2015-01-30 16:01:27 -0800 | [diff] [blame] | 215 | |
Garret Kelly | c5f89d1 | 2015-02-18 14:39:36 -0500 | [diff] [blame] | 216 | if (cl->HasSwitch(switches::kPrependDNSServers)) { |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 217 | settings.prepend_dns_servers = |
| 218 | cl->GetSwitchValueASCII(switches::kPrependDNSServers); |
Garret Kelly | c5f89d1 | 2015-02-18 14:39:36 -0500 | [diff] [blame] | 219 | } |
| 220 | |
Garret Kelly | 782cdce | 2015-04-01 16:39:16 -0400 | [diff] [blame] | 221 | if (cl->HasSwitch(switches::kMinimumMTU)) { |
| 222 | int mtu; |
| 223 | std::string value = cl->GetSwitchValueASCII(switches::kMinimumMTU); |
| 224 | if (!base::StringToInt(value, &mtu)) { |
| 225 | LOG(FATAL) << "Could not convert '" << value << "' to integer."; |
| 226 | } |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 227 | settings.minimum_mtu = mtu; |
Garret Kelly | 782cdce | 2015-04-01 16:39:16 -0400 | [diff] [blame] | 228 | } |
| 229 | |
Matthew Wein | 08add48 | 2015-04-20 13:26:48 -0700 | [diff] [blame] | 230 | if (cl->HasSwitch(switches::kAcceptHostnameFrom)) { |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 231 | settings.accept_hostname_from = |
| 232 | cl->GetSwitchValueASCII(switches::kAcceptHostnameFrom); |
Matthew Wein | 08add48 | 2015-04-20 13:26:48 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Peter Qiu | d48fa0c | 2015-06-10 12:20:48 -0700 | [diff] [blame] | 235 | #ifndef DISABLE_DHCPV6 |
| 236 | if (cl->HasSwitch(switches::kDhcpv6EnabledDevices)) { |
Peter Qiu | d48fa0c | 2015-06-10 12:20:48 -0700 | [diff] [blame] | 237 | base::SplitString(cl->GetSwitchValueASCII(switches::kDhcpv6EnabledDevices), |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 238 | ',', &settings.dhcpv6_enabled_devices); |
Peter Qiu | d48fa0c | 2015-06-10 12:20:48 -0700 | [diff] [blame] | 239 | } |
| 240 | #endif // DISABLE_DHCPV6 |
| 241 | |
Paul Stewart | 1ce231c | 2015-06-12 19:44:22 -0700 | [diff] [blame] | 242 | shill::Config config; |
| 243 | |
| 244 | // Passes ownership of dbus_control. |
| 245 | shill::Daemon daemon(&config, dbus_control); |
| 246 | daemon.ApplySettings(settings); |
| 247 | |
Thieu Le | 1271d68 | 2011-11-02 22:48:19 +0000 | [diff] [blame] | 248 | g_unix_signal_add(SIGINT, ExitSigHandler, &daemon); |
| 249 | g_unix_signal_add(SIGTERM, ExitSigHandler, &daemon); |
| 250 | |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 251 | // Catch but ignore SIGPIPE signals we receive if we write to the logger |
| 252 | // process after it exits. GLib cannot handle this signal number, so use |
| 253 | // signal() directly. |
| 254 | signal(SIGPIPE, SIG_IGN); |
| 255 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 256 | daemon.Run(); |
| 257 | |
Paul Stewart | 8dc5e7b | 2014-12-11 19:24:50 -0800 | [diff] [blame] | 258 | LOG(INFO) << "Process exiting."; |
| 259 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 260 | return 0; |
| 261 | } |