@@ -4,14 +4,17 @@ use linux_raw_sys::general::{
4
4
CLONE_NEWTIME , CLONE_NEWUSER , CLONE_NEWUTS , CLONE_SYSVSEM ,
5
5
} ;
6
6
7
- use crate :: backend:: c:: { c_int, NS_GET_NSTYPE , NS_GET_OWNER_UID , NS_GET_PARENT , NS_GET_USERNS } ;
7
+ use crate :: backend:: c:: {
8
+ c_int, NS_GET_NSTYPE , NS_GET_OWNER_UID , NS_GET_PARENT , NS_GET_PID_FROM_PIDNS ,
9
+ NS_GET_PID_IN_PIDNS , NS_GET_TGID_FROM_PIDNS , NS_GET_TGID_IN_PIDNS , NS_GET_USERNS ,
10
+ } ;
8
11
use crate :: backend:: thread:: syscalls;
9
12
use crate :: fd:: BorrowedFd ;
10
13
use crate :: fd:: { AsFd , FromRawFd , OwnedFd } ;
11
- use crate :: io;
14
+ use crate :: io:: { self , Errno } ;
12
15
use crate :: ioctl;
13
16
14
- use super :: { RawUid , Uid } ;
17
+ use super :: { Pid , RawUid , Uid } ;
15
18
16
19
bitflags ! {
17
20
/// Namespace type.
@@ -213,7 +216,7 @@ pub fn unshare(flags: UnshareFlags) -> io::Result<()> {
213
216
///
214
217
/// # Safety
215
218
///
216
- /// `fd` must refer to a `/proc/pid/ns/*` file.
219
+ /// `fd` must refer to a `/proc/{ pid} /ns/*` file.
217
220
#[ inline]
218
221
#[ doc( alias = "NS_GET_USERNS" ) ]
219
222
pub fn ioctl_ns_get_userns < FD : AsFd > ( fd : FD ) -> io:: Result < OwnedFd > {
@@ -228,7 +231,7 @@ pub fn ioctl_ns_get_userns<FD: AsFd>(fd: FD) -> io::Result<OwnedFd> {
228
231
///
229
232
/// # Safety
230
233
///
231
- /// `fd` must refer to a `/proc/pid/ns/*` file.
234
+ /// `fd` must refer to a `/proc/{ pid} /ns/*` file.
232
235
#[ inline]
233
236
#[ doc( alias = "NS_GET_PARENT" ) ]
234
237
pub fn ioctl_ns_get_parent < FD : AsFd > ( fd : FD ) -> io:: Result < OwnedFd > {
@@ -243,7 +246,7 @@ pub fn ioctl_ns_get_parent<FD: AsFd>(fd: FD) -> io::Result<OwnedFd> {
243
246
///
244
247
/// # Safety
245
248
///
246
- /// `fd` must refer to a `/proc/pid/ns/*` file.
249
+ /// `fd` must refer to a `/proc/{ pid} /ns/*` file.
247
250
#[ inline]
248
251
#[ doc( alias = "NS_GET_NSTYPE" ) ]
249
252
pub fn ioctl_ns_get_nstype < FD : AsFd > ( fd : FD ) -> io:: Result < NamespaceType > {
@@ -258,7 +261,7 @@ pub fn ioctl_ns_get_nstype<FD: AsFd>(fd: FD) -> io::Result<NamespaceType> {
258
261
///
259
262
/// # Safety
260
263
///
261
- /// `fd` must refer to a `/proc/pid/ns/*` file.
264
+ /// `fd` must refer to a `/proc/{ pid} /ns/*` file.
262
265
#[ inline]
263
266
#[ doc( alias = "NS_GET_OWNER_UID" ) ]
264
267
pub fn ioctl_ns_get_owner_uid < FD : AsFd > ( fd : FD ) -> io:: Result < Uid > {
@@ -268,3 +271,71 @@ pub fn ioctl_ns_get_owner_uid<FD: AsFd>(fd: FD) -> io::Result<Uid> {
268
271
ioctl:: ioctl ( fd, ctl) . map ( Uid :: from_raw)
269
272
}
270
273
}
274
+
275
+ /// `ioctl(ns_fd, NS_GET_PID_FROM_PIDNS, pid)`
276
+ ///
277
+ /// # Safety
278
+ ///
279
+ /// `fd` must refer to a `/proc/{pid}/ns/pid` file.
280
+ #[ inline]
281
+ #[ doc( alias = "NS_GET_PID_FROM_PIDNS" ) ]
282
+ pub fn ioctl_ns_get_pid_from_pidns < FD : AsFd > ( fd : FD , pid : Pid ) -> io:: Result < Pid > {
283
+ #[ allow( unsafe_code) ]
284
+ unsafe {
285
+ let ctl = ioctl:: ParameterizedReturnGetter :: < { NS_GET_PID_FROM_PIDNS } > :: new (
286
+ pid. as_raw_pid ( ) as usize ,
287
+ ) ;
288
+ ioctl:: ioctl ( fd, ctl) . and_then ( |pid| Pid :: from_raw ( pid) . ok_or ( Errno :: INVAL ) )
289
+ }
290
+ }
291
+
292
+ /// `ioctl(ns_fd, NS_GET_TGID_FROM_PIDNS, tgid)`
293
+ ///
294
+ /// # Safety
295
+ ///
296
+ /// `fd` must refer to a `/proc/{pid}/ns/pid` file.
297
+ #[ inline]
298
+ #[ doc( alias = "NS_GET_TGID_FROM_PIDNS" ) ]
299
+ pub fn ioctl_ns_get_tgid_from_pidns < FD : AsFd > ( fd : FD , tgid : Pid ) -> io:: Result < Pid > {
300
+ #[ allow( unsafe_code) ]
301
+ unsafe {
302
+ let ctl = ioctl:: ParameterizedReturnGetter :: < { NS_GET_TGID_FROM_PIDNS } > :: new (
303
+ tgid. as_raw_pid ( ) as usize ,
304
+ ) ;
305
+ ioctl:: ioctl ( fd, ctl) . and_then ( |tgid| Pid :: from_raw ( tgid) . ok_or ( Errno :: INVAL ) )
306
+ }
307
+ }
308
+
309
+ /// `ioctl(ns_fd, NS_GET_PID_IN_PIDNS, pid)`
310
+ ///
311
+ /// # Safety
312
+ ///
313
+ /// `fd` must refer to a `/proc/{pid}/ns/pid` file.
314
+ #[ inline]
315
+ #[ doc( alias = "NS_GET_PID_IN_PIDNS" ) ]
316
+ pub fn ioctl_ns_get_pid_in_pidns < FD : AsFd > ( fd : FD , pid : Pid ) -> io:: Result < Pid > {
317
+ #[ allow( unsafe_code) ]
318
+ unsafe {
319
+ let ctl = ioctl:: ParameterizedReturnGetter :: < { NS_GET_PID_IN_PIDNS } > :: new (
320
+ pid. as_raw_pid ( ) as usize ,
321
+ ) ;
322
+ ioctl:: ioctl ( fd, ctl) . and_then ( |pid| Pid :: from_raw ( pid) . ok_or ( Errno :: INVAL ) )
323
+ }
324
+ }
325
+
326
+ /// `ioctl(ns_fd, NS_GET_TGID_IN_PIDNS, tgid)`
327
+ ///
328
+ /// # Safety
329
+ ///
330
+ /// `fd` must refer to a `/proc/{pid}/ns/pid` file.
331
+ #[ inline]
332
+ #[ doc( alias = "NS_GET_TGID_IN_PIDNS" ) ]
333
+ pub fn ioctl_ns_get_tgid_in_pidns < FD : AsFd > ( fd : FD , tgid : Pid ) -> io:: Result < Pid > {
334
+ #[ allow( unsafe_code) ]
335
+ unsafe {
336
+ let ctl = ioctl:: ParameterizedReturnGetter :: < { NS_GET_TGID_IN_PIDNS } > :: new (
337
+ tgid. as_raw_pid ( ) as usize ,
338
+ ) ;
339
+ ioctl:: ioctl ( fd, ctl) . and_then ( |tgid| Pid :: from_raw ( tgid) . ok_or ( Errno :: INVAL ) )
340
+ }
341
+ }
0 commit comments