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;
impl PidFd {
pub fn current() -> io::Result<Self> {
- let fd = c_try!(unsafe {
- libc::open(
- b"/proc/self\0".as_ptr() as _,
- libc::O_DIRECTORY | libc::O_CLOEXEC,
- )
- });
-
- Ok(Self(fd, unsafe { libc::getpid() }))
+ Self::open(unsafe { libc::getpid() })
}
pub fn open(pid: pid_t) -> io::Result<Self> {
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());
}
}
}