|
2 | 2 |
|
3 | 3 | use bitflags::bitflags;
|
4 | 4 | use linux_raw_sys::general::{
|
5 |
| - CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWTIME, |
6 |
| - CLONE_NEWUSER, CLONE_NEWUTS, |
| 5 | + CLONE_FILES, CLONE_FS, CLONE_NEWCGROUP, CLONE_NEWIPC, CLONE_NEWNET, CLONE_NEWNS, CLONE_NEWPID, |
| 6 | + CLONE_NEWTIME, CLONE_NEWUSER, CLONE_NEWUTS, CLONE_SYSVSEM, |
7 | 7 | };
|
8 | 8 |
|
9 | 9 | use crate::backend::c::c_int;
|
@@ -55,6 +55,32 @@ pub enum LinkNameSpaceType {
|
55 | 55 | Network = CLONE_NEWNET,
|
56 | 56 | }
|
57 | 57 |
|
| 58 | +bitflags! { |
| 59 | + /// `CLONE_*` for use with [`unshare`]. |
| 60 | + pub struct UnshareFlags: u32 { |
| 61 | + /// `CLONE_FILES`. |
| 62 | + const FILES = CLONE_FILES; |
| 63 | + /// `CLONE_FS`. |
| 64 | + const FS = CLONE_FS; |
| 65 | + /// `CLONE_NEWCGROUP`. |
| 66 | + const NWCGROUP = CLONE_NEWCGROUP; |
| 67 | + /// `CLONE_NEWIPC`. |
| 68 | + const NEWIPC = CLONE_NEWIPC; |
| 69 | + /// `CLONE_NEWNET`. |
| 70 | + const NEWNET = CLONE_NEWNET; |
| 71 | + /// `CLONE_NEWNS`. |
| 72 | + const NEWNS = CLONE_NEWNS; |
| 73 | + /// `CLONE_NEWPID`. |
| 74 | + const NEWPID = CLONE_NEWPID; |
| 75 | + /// `CLONE_NEWTIME`. |
| 76 | + const NEWTIME = CLONE_NEWTIME; |
| 77 | + /// `CLONE_NEWUSER`. |
| 78 | + const NEWUSER = CLONE_NEWUSER; |
| 79 | + /// `CLONE_SYSVSEM`. |
| 80 | + const SYSVSEM = CLONE_SYSVSEM; |
| 81 | + } |
| 82 | +} |
| 83 | + |
58 | 84 | /// Reassociate the calling thread with the namespace associated with link referred to by `fd`.
|
59 | 85 | ///
|
60 | 86 | /// `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(
|
87 | 113 | ) -> io::Result<()> {
|
88 | 114 | syscalls::setns(fd, allowed_types.bits() as c_int).map(|_r| ())
|
89 | 115 | }
|
| 116 | + |
| 117 | +/// `unshare(flags)`—Disassociate parts of the current thread's execution |
| 118 | +/// context with other threads. |
| 119 | +/// |
| 120 | +/// # References |
| 121 | +/// - [`unshare`] |
| 122 | +/// |
| 123 | +/// [`unshare`]: https://man7.org/linux/man-pages/man2/unshare.2.html |
| 124 | +pub fn unshare(flags: UnshareFlags) -> io::Result<()> { |
| 125 | + syscalls::unshare(flags) |
| 126 | +} |
0 commit comments