blob: 73c71dd9ffc05ff411c2052fa8ae4d5c6a33666a [file] [log] [blame] [edit]
// Copyright 2017 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "debugd/src/container_tool.h"
#include <base/bind.h>
#include <base/location.h>
#include <base/logging.h>
#include <base/process/launch.h>
#include <base/process/process_iterator.h>
#include <base/threading/thread_task_runner_handle.h>
namespace {
const char kRunOci[] = "/usr/bin/run_oci";
}
namespace debugd {
void ContainerTool::ContainerStarted() {
if (device_jail_started_)
return;
LOG(INFO) << "Starting up device jail";
base::LaunchOptions options;
options.wait = true;
base::LaunchProcess({"start", "device-jail"}, options);
device_jail_started_ = true;
}
void ContainerTool::ContainerStopped() {
// If there are still active containers, ignore.
if (base::GetProcessCount(kRunOci, nullptr) > 0) {
LOG(INFO) << "Containers are present, deferring cleanup";
return;
}
LOG(INFO) << "Cleaning up device jail";
base::LaunchOptions options;
options.wait = true;
base::LaunchProcess({"stop", "device-jail"}, options);
device_jail_started_ = false;
}
} // namespace debugd