aboutsummaryrefslogtreecommitdiff
path: root/brillo/scoped_mount_namespace.cc
diff options
context:
space:
mode:
Diffstat (limited to 'brillo/scoped_mount_namespace.cc')
-rw-r--r--brillo/scoped_mount_namespace.cc66
1 files changed, 0 insertions, 66 deletions
diff --git a/brillo/scoped_mount_namespace.cc b/brillo/scoped_mount_namespace.cc
deleted file mode 100644
index 09f3c75..0000000
--- a/brillo/scoped_mount_namespace.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2019 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 "brillo/scoped_mount_namespace.h"
-
-#include <fcntl.h>
-#include <sched.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <string>
-#include <utility>
-
-#include <base/posix/eintr_wrapper.h>
-#include <base/strings/stringprintf.h>
-
-namespace {
-constexpr char kCurrentMountNamespacePath[] = "/proc/self/ns/mnt";
-} // anonymous namespace
-
-namespace brillo {
-
-ScopedMountNamespace::ScopedMountNamespace(base::ScopedFD mount_namespace_fd)
- : mount_namespace_fd_(std::move(mount_namespace_fd)) {}
-
-ScopedMountNamespace::~ScopedMountNamespace() {
- PLOG_IF(ERROR, setns(mount_namespace_fd_.get(), CLONE_NEWNS) != 0)
- << "Ignoring failure to restore original mount namespace";
-}
-
-// static
-std::unique_ptr<ScopedMountNamespace> ScopedMountNamespace::CreateForPid(
- pid_t pid) {
- std::string ns_path = base::StringPrintf("/proc/%d/ns/mnt", pid);
- return CreateFromPath(base::FilePath(ns_path));
-}
-
-// static
-std::unique_ptr<ScopedMountNamespace> ScopedMountNamespace::CreateFromPath(
- const base::FilePath& ns_path) {
- base::ScopedFD original_mount_namespace_fd(
- HANDLE_EINTR(open(kCurrentMountNamespacePath, O_RDONLY)));
- if (!original_mount_namespace_fd.is_valid()) {
- PLOG(ERROR) << "Failed to open original mount namespace FD at "
- << kCurrentMountNamespacePath;
- return nullptr;
- }
-
- base::ScopedFD mount_namespace_fd(
- HANDLE_EINTR(open(ns_path.value().c_str(), O_RDONLY)));
- if (!mount_namespace_fd.is_valid()) {
- PLOG(ERROR) << "Failed to open mount namespace FD at " << ns_path.value();
- return nullptr;
- }
-
- if (setns(mount_namespace_fd.get(), CLONE_NEWNS) != 0) {
- PLOG(ERROR) << "Failed to enter mount namespace at " << ns_path.value();
- return nullptr;
- }
-
- return std::make_unique<ScopedMountNamespace>(
- std::move(original_mount_namespace_fd));
-}
-
-} // namespace brillo