blob: e8c91bf1fa22d3d887a3ee2e9a43e2191b6576bf (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
// 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.
#ifndef LIBBRILLO_BRILLO_SCOPED_MOUNT_NAMESPACE_H_
#define LIBBRILLO_BRILLO_SCOPED_MOUNT_NAMESPACE_H_
#include <memory>
#include <base/macros.h>
#include <base/files/scoped_file.h>
#include <brillo/brillo_export.h>
namespace brillo {
// A class that restores a mount namespace when it goes out of scope. This can
// be done by entering another process' mount namespace by using
// CreateForPid(), or by supplying a mount namespace FD directly.
class BRILLO_EXPORT ScopedMountNamespace {
public:
// Enters the process identified by |pid|'s mount namespace and returns a
// unique_ptr that restores the original mount namespace when it goes out of
// scope.
static std::unique_ptr<ScopedMountNamespace> CreateForPid(pid_t pid);
explicit ScopedMountNamespace(base::ScopedFD mount_namespace_fd);
~ScopedMountNamespace();
private:
base::ScopedFD mount_namespace_fd_;
DISALLOW_COPY_AND_ASSIGN(ScopedMountNamespace);
};
} // namespace brillo
#endif // LIBBRILLO_BRILLO_SCOPED_MOUNT_NAMESPACE_H_
|