]> git.proxmox.com Git - pve-lxc-syscalld.git/blobdiff - src/process/pid_fd.rs
support pure cgroupv2 environments
[pve-lxc-syscalld.git] / src / process / pid_fd.rs
index d3253b6864c4c28e3229a05e56545619dcead1c8..1caf8f262bd8c381c274db90771a7ba0b98e8734 100644 (file)
@@ -6,7 +6,7 @@ use std::os::raw::c_int;
 use std::os::unix::ffi::OsStringExt;
 use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
 
-use failure::{bail, Error};
+use anyhow::{bail, Error};
 use libc::pid_t;
 
 use crate::capability::Capabilities;
@@ -18,15 +18,9 @@ use super::{CGroups, IdMap, IdMapEntry, ProcStatus, Uids, UserCaps};
 pub struct PidFd(RawFd, pid_t);
 file_descriptor_impl!(PidFd);
 
-pub const SYS_pidfd_open: libc::c_long = 434; // asm-generic
-
 impl PidFd {
     pub fn current() -> io::Result<Self> {
-        let pid = unsafe { libc::getpid() };
-        let fd = c_try!(unsafe {
-            libc::syscall(SYS_pidfd_open, pid, 0)
-        });
-        Ok(Self(fd, pid))
+        Self::open(unsafe { libc::getpid() })
     }
 
     pub fn open(pid: pid_t) -> io::Result<Self> {
@@ -228,7 +222,10 @@ impl PidFd {
                 cgroups.v2 = Some(path);
             } else {
                 for entry in name.split(',') {
-                    cgroups.v1.insert(entry.to_string(), path.clone());
+                    cgroups
+                        .v1
+                        .get_or_insert_with(Default::default)
+                        .insert(entry.to_string(), path.clone());
                 }
             }
         }