Keshav Santhanam | dc1aa7b | 2016-07-11 09:08:12 -0700 | [diff] [blame] | 1 | // 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 | |
| 13 | namespace { |
| 14 | |
| 15 | const char kRunOci[] = "/usr/bin/run_oci"; |
| 16 | |
| 17 | } |
| 18 | |
| 19 | namespace debugd { |
| 20 | |
| 21 | void 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 | |
| 32 | void 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 |