blob: 2dc5dbbff76e361e7fe65fb56da53e9a609bba8b [file] [log] [blame]
Kevin Cernekee27bcaa62016-12-03 11:16:26 -08001// 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 Abe3a7e5132018-02-15 13:07:50 +09005#ifndef ARC_NETWORK_HELPER_PROCESS_H_
6#define ARC_NETWORK_HELPER_PROCESS_H_
Kevin Cernekee27bcaa62016-12-03 11:16:26 -08007
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 Cernekee27bcaa62016-12-03 11:16:26 -080016namespace 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.
21class 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 Evans49879532018-12-03 13:15:36 +090032 void SendMessage(const google::protobuf::MessageLite& proto) const;
Kevin Cernekee27bcaa62016-12-03 11:16:26 -080033
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 Abe3a7e5132018-02-15 13:07:50 +090046#endif // ARC_NETWORK_HELPER_PROCESS_H_