Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 <unistd.h> |
| 6 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 7 | #include <memory> |
| 8 | #include <utility> |
| 9 | |
| 10 | #include <base/files/scoped_file.h> |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 11 | #include <base/logging.h> |
| 12 | #include <brillo/flag_helper.h> |
| 13 | #include <brillo/syslog_logging.h> |
| 14 | |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 15 | #include "arc/network/helper_process.h" |
| 16 | #include "arc/network/ip_helper.h" |
| 17 | #include "arc/network/manager.h" |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 18 | |
| 19 | int main(int argc, char* argv[]) { |
| 20 | DEFINE_bool(log_to_stderr, false, "Log to both syslog and stderr"); |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 21 | DEFINE_int32( |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 22 | ip_helper_fd, -1, |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 23 | "Control socket for starting an IpHelper subprocess. Used internally."); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 24 | |
| 25 | brillo::FlagHelper::Init(argc, argv, "ARC network daemon"); |
| 26 | |
| 27 | int flags = brillo::kLogToSyslog | brillo::kLogHeader; |
| 28 | if (FLAGS_log_to_stderr) |
| 29 | flags |= brillo::kLogToStderr; |
| 30 | brillo::InitLog(flags); |
| 31 | |
Hugo Benichi | 935eca9 | 2018-07-03 13:47:24 +0900 | [diff] [blame] | 32 | LOG(INFO) << "Starting arc-networkd " |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame^] | 33 | << (FLAGS_ip_helper_fd >= 0 ? "helper" : "manager"); |
Hugo Benichi | 935eca9 | 2018-07-03 13:47:24 +0900 | [diff] [blame] | 34 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 35 | if (FLAGS_ip_helper_fd >= 0) { |
| 36 | base::ScopedFD fd(FLAGS_ip_helper_fd); |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame^] | 37 | arc_networkd::IpHelper ip_helper{std::move(fd)}; |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 38 | return ip_helper.Run(); |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 39 | } |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame^] | 40 | |
| 41 | auto ip_helper = std::make_unique<arc_networkd::HelperProcess>(); |
| 42 | ip_helper->Start(argc, argv, "--ip_helper_fd"); |
| 43 | |
| 44 | arc_networkd::Manager manager{std::move(ip_helper)}; |
| 45 | return manager.Run(); |
Kevin Cernekee | 95d4ae9 | 2016-06-19 10:26:29 -0700 | [diff] [blame] | 46 | } |