blob: 50cd2cef4e96289256b9986abad7ccb2f4f5adb9 [file] [log] [blame]
Elly Jonesa44d22d2012-01-05 18:05:56 -05001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Elly Jones0c016cc2011-12-19 16:19:22 -05002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Vakulenko262be3f2014-07-30 15:25:50 -07005#ifndef DEBUGD_SRC_SUBPROCESS_TOOL_H_
6#define DEBUGD_SRC_SUBPROCESS_TOOL_H_
Elly Jones0c016cc2011-12-19 16:19:22 -05007
8#include <map>
Ben Chan23142892017-02-15 12:34:13 -08009#include <memory>
Elly Jones0c016cc2011-12-19 16:19:22 -050010#include <string>
Mike Frysinger56379d72019-02-19 16:03:03 -050011#include <vector>
Elly Jones0c016cc2011-12-19 16:19:22 -050012
Ben Chan657bed82014-09-02 20:40:51 -070013#include <base/macros.h>
Eric Carusocc7106c2017-04-27 14:22:42 -070014#include <brillo/errors/error.h>
Elly Jones0c016cc2011-12-19 16:19:22 -050015
Ben Chan23142892017-02-15 12:34:13 -080016#include "debugd/src/process_with_id.h"
Elly Jones0c016cc2011-12-19 16:19:22 -050017
Ben Chan23142892017-02-15 12:34:13 -080018namespace debugd {
Elly Jones0c016cc2011-12-19 16:19:22 -050019
20class SubprocessTool {
21 public:
Ben Chan78f89532014-08-29 09:35:09 -070022 SubprocessTool() = default;
Qijiang Fan6bc59e12020-11-11 02:51:06 +090023 SubprocessTool(const SubprocessTool&) = delete;
24 SubprocessTool& operator=(const SubprocessTool&) = delete;
25
Ben Chan78f89532014-08-29 09:35:09 -070026 virtual ~SubprocessTool() = default;
Elly Jones0c016cc2011-12-19 16:19:22 -050027
Ben Chan0d840a72018-09-27 00:24:48 -070028 virtual ProcessWithId* CreateProcess(bool sandboxed,
29 bool allow_root_mount_ns);
Mike Frysinger56379d72019-02-19 16:03:03 -050030 virtual ProcessWithId* CreateProcess(
Tom Hughesd6c2d392020-08-24 18:12:11 -070031 bool sandboxed,
32 bool allow_root_mount_ns,
Mike Frysinger56379d72019-02-19 16:03:03 -050033 const std::vector<std::string>& minijail_extra_args);
Jorge Lucangeli Obes623f8ca2014-09-18 10:50:06 -070034
Mike Frysingerf9da3d32017-09-19 23:41:27 -040035 // TODO(vapier): Rework sandboxing so we can re-internalize this function.
36 bool RecordProcess(std::unique_ptr<ProcessWithId> process);
37
Eric Carusocc7106c2017-04-27 14:22:42 -070038 virtual bool Stop(const std::string& handle, brillo::ErrorPtr* error);
Ben Chana0011d82014-05-13 00:19:29 -070039
Elly Jones0c016cc2011-12-19 16:19:22 -050040 private:
Ben Chan23142892017-02-15 12:34:13 -080041 std::map<std::string, std::unique_ptr<ProcessWithId>> processes_;
Elly Jones0c016cc2011-12-19 16:19:22 -050042};
43
Ben Chana0011d82014-05-13 00:19:29 -070044} // namespace debugd
Elly Jones0c016cc2011-12-19 16:19:22 -050045
Alex Vakulenko262be3f2014-07-30 15:25:50 -070046#endif // DEBUGD_SRC_SUBPROCESS_TOOL_H_