Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [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 | |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 5 | #ifndef ARC_NETWORK_HELPER_PROCESS_H_ |
| 6 | #define ARC_NETWORK_HELPER_PROCESS_H_ |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 7 | |
| 8 | #include <sys/types.h> |
| 9 | |
| 10 | #include <string> |
| 11 | |
| 12 | #include <base/files/scoped_file.h> |
| 13 | #include <base/macros.h> |
| 14 | #include <google/protobuf/message_lite.h> |
| 15 | |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 16 | namespace arc_networkd { |
| 17 | |
| 18 | // Tracks a helper subprocess. Handles forking, cleaning up on termination, |
| 19 | // and IPC. |
| 20 | // This object is used by the main Manager process. |
| 21 | class HelperProcess { |
| 22 | public: |
| 23 | HelperProcess() = default; |
| 24 | virtual ~HelperProcess() = default; |
| 25 | |
| 26 | // Re-execs arc-networkd with a new argument: "|fd_arg|=N", where N is the |
| 27 | // side of |control_fd|. This tells the subprocess to start up a different |
| 28 | // mainloop. |
| 29 | void Start(int argc, char* argv[], const std::string& fd_arg); |
| 30 | |
| 31 | // Serializes a protobuf and sends it to the helper process. |
Garrick Evans | 4987953 | 2018-12-03 13:15:36 +0900 | [diff] [blame^] | 32 | void SendMessage(const google::protobuf::MessageLite& proto) const; |
Kevin Cernekee | 27bcaa6 | 2016-12-03 11:16:26 -0800 | [diff] [blame] | 33 | |
| 34 | const pid_t pid() { return pid_; } |
| 35 | |
| 36 | protected: |
| 37 | pid_t pid_{0}; |
| 38 | base::ScopedFD control_fd_; |
| 39 | |
| 40 | private: |
| 41 | DISALLOW_COPY_AND_ASSIGN(HelperProcess); |
| 42 | }; |
| 43 | |
| 44 | } // namespace arc_networkd |
| 45 | |
Hidehiko Abe | 3a7e513 | 2018-02-15 13:07:50 +0900 | [diff] [blame] | 46 | #endif // ARC_NETWORK_HELPER_PROCESS_H_ |