summaryrefslogtreecommitdiffstats
path: root/vendor/rustix/src/thread/setns.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:18:58 +0000
commita4b7ed7a42c716ab9f05e351f003d589124fd55d (patch)
treeb620cd3f223850b28716e474e80c58059dca5dd4 /vendor/rustix/src/thread/setns.rs
parentAdding upstream version 1.67.1+dfsg1. (diff)
downloadrustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.tar.xz
rustc-a4b7ed7a42c716ab9f05e351f003d589124fd55d.zip
Adding upstream version 1.68.2+dfsg1.upstream/1.68.2+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/rustix/src/thread/setns.rs')
-rw-r--r--vendor/rustix/src/thread/setns.rs41
1 files changed, 39 insertions, 2 deletions
diff --git a/vendor/rustix/src/thread/setns.rs b/vendor/rustix/src/thread/setns.rs
index 0a5564ae1..5295bab94 100644
--- a/vendor/rustix/src/thread/setns.rs
+++ b/vendor/rustix/src/thread/setns.rs
@@ -2,8 +2,8 @@
use bitflags::bitflags;
use linux_raw_sys::general::{
- CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWTIME,
- CLONE_NEWUSER, CLONE_NEWUTS,
+ CLONE_FILES, CLONE_FS, CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWPID,
+ CLONE_NEWTIME, CLONE_NEWUSER, CLONE_NEWUTS, CLONE_SYSVSEM,
};
use crate::backend::c::c_int;
@@ -55,6 +55,32 @@ pub enum LinkNameSpaceType {
Network = CLONE_NEWNET,
}
+bitflags! {
+ /// `CLONE_*` for use with [`unshare`].
+ pub struct UnshareFlags: u32 {
+ /// `CLONE_FILES`.
+ const FILES = CLONE_FILES;
+ /// `CLONE_FS`.
+ const FS = CLONE_FS;
+ /// `CLONE_NEWCGROUP`.
+ const NWCGROUP = CLONE_NEWCGROUP;
+ /// `CLONE_NEWIPC`.
+ const NEWIPC = CLONE_NEWIPC;
+ /// `CLONE_NEWNET`.
+ const NEWNET = CLONE_NEWNET;
+ /// `CLONE_NEWNS`.
+ const NEWNS = CLONE_NEWNS;
+ /// `CLONE_NEWPID`.
+ const NEWPID = CLONE_NEWPID;
+ /// `CLONE_NEWTIME`.
+ const NEWTIME = CLONE_NEWTIME;
+ /// `CLONE_NEWUSER`.
+ const NEWUSER = CLONE_NEWUSER;
+ /// `CLONE_SYSVSEM`.
+ const SYSVSEM = CLONE_SYSVSEM;
+ }
+}
+
/// Reassociate the calling thread with the namespace associated with link referred to by `fd`.
///
/// `fd` must refer to one of the magic links in a `/proc/[pid]/ns/` directory, or a bind mount
@@ -87,3 +113,14 @@ pub fn move_into_thread_name_spaces(
) -> io::Result<()> {
syscalls::setns(fd, allowed_types.bits() as c_int).map(|_r| ())
}
+
+/// `unshare(flags)`—Disassociate parts of the current thread's execution
+/// context with other threads.
+///
+/// # References
+/// - [`unshare`]
+///
+/// [`unshare`]: https://man7.org/linux/man-pages/man2/unshare.2.html
+pub fn unshare(flags: UnshareFlags) -> io::Result<()> {
+ syscalls::unshare(flags)
+}