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 | |
| 5 | #ifndef ARC_NETWORKD_HELPER_PROCESS_H_ |
| 6 | #define ARC_NETWORKD_HELPER_PROCESS_H_ |
| 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 | |
| 16 | #include "arc-networkd/options.h" |
| 17 | |
| 18 | namespace arc_networkd { |
| 19 | |
| 20 | // Tracks a helper subprocess. Handles forking, cleaning up on termination, |
| 21 | // and IPC. |
| 22 | // This object is used by the main Manager process. |
| 23 | class HelperProcess { |
| 24 | public: |
| 25 | HelperProcess() = default; |
| 26 | virtual ~HelperProcess() = default; |
| 27 | |
| 28 | // Re-execs arc-networkd with a new argument: "|fd_arg|=N", where N is the |
| 29 | // side of |control_fd|. This tells the subprocess to start up a different |
| 30 | // mainloop. |
| 31 | void Start(int argc, char* argv[], const std::string& fd_arg); |
| 32 | |
| 33 | // Serializes a protobuf and sends it to the helper process. |
| 34 | void SendMessage(const google::protobuf::MessageLite& proto); |
| 35 | |
| 36 | const pid_t pid() { return pid_; } |
| 37 | |
| 38 | protected: |
| 39 | pid_t pid_{0}; |
| 40 | base::ScopedFD control_fd_; |
| 41 | |
| 42 | private: |
| 43 | DISALLOW_COPY_AND_ASSIGN(HelperProcess); |
| 44 | }; |
| 45 | |
| 46 | } // namespace arc_networkd |
| 47 | |
| 48 | #endif // ARC_NETWORKD_HELPER_PROCESS_H_ |