blob: 342533d4467f4c7a76c57d3731154e26e906d31d [file] [log] [blame]
Keshav Santhanamdc1aa7b2016-07-11 09:08:12 -07001// Copyright 2017 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#include "debugd/src/container_tool.h"
6
7#include <base/bind.h>
8#include <base/location.h>
9#include <base/process/launch.h>
10#include <base/process/process_iterator.h>
11#include <base/threading/thread_task_runner_handle.h>
12
13namespace {
14
15const char kRunOci[] = "/usr/bin/run_oci";
16
17}
18
19namespace debugd {
20
21void ContainerTool::ContainerStarted() {
22 if (device_jail_started_)
23 return;
24
25 LOG(INFO) << "Starting up device jail";
26 base::LaunchOptions options;
27 options.wait = true;
28 base::LaunchProcess({"start", "device-jail"}, options);
29 device_jail_started_ = true;
30}
31
32void ContainerTool::ContainerStopped() {
33 // If there are still active containers, ignore.
34 if (base::GetProcessCount(kRunOci, nullptr) > 0) {
35 LOG(INFO) << "Containers are present, deferring cleanup";
36 return;
37 }
38
39 LOG(INFO) << "Cleaning up device jail";
40 base::LaunchOptions options;
41 options.wait = true;
42 base::LaunchProcess({"stop", "device-jail"}, options);
43 device_jail_started_ = false;
44}
45
46} // namespace debugd