blob: 17b7e39be83e5a16ea55af4e6bcddae450eb5a5a [file] [log] [blame]
Andreea Costinasc7d5ad02020-03-09 09:41:51 +01001// Copyright 2020 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#ifndef SYSTEM_PROXY_SANDBOXED_WORKER_H_
5#define SYSTEM_PROXY_SANDBOXED_WORKER_H_
6
7#include <array>
8#include <memory>
9#include <string>
10
11#include <gtest/gtest_prod.h> // for FRIEND_TEST
12
13#include <base/files/file_descriptor_watcher_posix.h>
14#include <base/files/scoped_file.h>
15#include <chromeos/scoped_minijail.h>
16#include <patchpanel/proto_bindings/patchpanel_service.pb.h>
17
18namespace system_proxy {
19
20class SandboxedWorker {
21 public:
22 SandboxedWorker();
23 SandboxedWorker(const SandboxedWorker&) = delete;
24 SandboxedWorker& operator=(const SandboxedWorker&) = delete;
25 virtual ~SandboxedWorker() = default;
26
27 // Starts a sandboxed worker with pipes.
28 virtual void Start();
29
30 // Terminates the child process by sending a SIGTERM signal.
31 virtual bool Stop();
32
33 virtual bool IsRunning();
34
35 pid_t pid() { return pid_; }
36
37 private:
38 void OnMessageReceived();
39 void OnErrorReceived();
40
41 bool is_being_terminated_ = false;
42 ScopedMinijail jail_;
43 base::ScopedFD stdin_pipe_;
44 base::ScopedFD stdout_pipe_;
45 base::ScopedFD stderr_pipe_;
46
47 std::unique_ptr<base::FileDescriptorWatcher::Controller> stdout_watcher_;
48 std::unique_ptr<base::FileDescriptorWatcher::Controller> stderr_watcher_;
49
50 pid_t pid_;
51};
52
53} // namespace system_proxy
54
55#endif // SYSTEM_PROXY_SANDBOXED_WORKER_H_