lazy_static = "1.4"
libc = "0.2.107"
log = "0.4.17"
-nix = "0.19.1"
+nix = "0.24.1"
regex = "1.2"
serde_json = "1.0"
serde = { version = "1.0", features = [ "derive" ] }
use std::io;
use nix::errno::Errno;
-use nix::Error;
use proxmox_lang::error::io_err_other;
impl SysError for nix::Error {
#[inline]
fn is_errno(&self, value: Errno) -> bool {
- *self == Error::Sys(value)
+ *self == value
}
#[inline]
fn into_io_error(self) -> io::Error {
match self {
- Error::Sys(raw) => io::Error::from_raw_os_error(raw as _),
- other => io::Error::new(io::ErrorKind::Other, other.to_string()),
+ Errno::UnknownErrno => {
+ io::Error::new(io::ErrorKind::Other, "unknown error".to_string())
+ }
+ other => io::Error::from_raw_os_error(other as _),
}
}
}
.unwrap_or(stat::Mode::from_bits_truncate(0o755));
created = match stat::mkdirat(at.as_raw_fd(), path, mode) {
- Err(nix::Error::Sys(Errno::EEXIST)) => false,
+ Err(Errno::EEXIST) => false,
Err(e) => return Err(e.into()),
Ok(_) => true,
};
new_path.as_ptr(),
libc::RENAME_NOREPLACE,
)) {
- Err(nix::Error::Sys(Errno::EINVAL)) => (), // dumb file system, try `link`+`unlink`
+ Err(Errno::EINVAL) => (), // dumb file system, try `link`+`unlink`
other => return other,
};
// but some file systems don't support `RENAME_NOREPLACE`
+use std::os::unix::ffi::OsStrExt;
+
pub mod command;
pub mod crypt;
pub mod email;
pub fn nodename() -> &'static str {
lazy_static::lazy_static! {
static ref NODENAME: String = {
- nix::sys::utsname::uname()
- .nodename()
- .split('.')
- .next()
- .unwrap()
- .to_owned()
+ std::str::from_utf8(
+ nix::sys::utsname::uname()
+ .expect("failed to get nodename")
+ .nodename()
+ .as_bytes(),
+ )
+ .expect("non utf-8 nodename not supported")
+ .split('.')
+ .next()
+ .unwrap()
+ .to_owned()
};
}
use std::os::unix::io::{AsRawFd, RawFd};
-use nix::errno::Errno::EINVAL;
use nix::fcntl::OFlag;
use nix::pty::{grantpt, posix_openpt, ptsname_r, unlockpt, PtyMaster};
use nix::sys::stat::Mode;
impl std::io::Read for PTY {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
- match nix::unistd::read(self.primary.as_raw_fd(), buf) {
- Ok(val) => Ok(val),
- Err(err) => Err(err.as_errno().unwrap_or(EINVAL).into()),
- }
+ Ok(nix::unistd::read(self.primary.as_raw_fd(), buf)?)
}
}
impl std::io::Write for PTY {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
- match nix::unistd::write(self.primary.as_raw_fd(), buf) {
- Ok(size) => Ok(size),
- Err(err) => Err(err.as_errno().unwrap_or(EINVAL).into()),
- }
+ Ok(nix::unistd::write(self.primary.as_raw_fd(), buf)?)
}
fn flush(&mut self) -> std::io::Result<()> {
use proxmox_lang::try_block;
use crate::c_try;
-use crate::error::SysError;
use crate::fd::Fd;
/// Get the current size of the terminal (for stdout).
Mode::empty(),
) {
Ok(fd) => Ok(Some(TtyOutput::DevTty(fd))),
- Err(nix::Error::Sys(nix::errno::Errno::ENXIO)) => Ok(None),
- Err(err) => Err(err.into_io_error()),
+ Err(nix::errno::Errno::ENXIO) => Ok(None),
+ Err(err) => Err(err.into()),
}
}
}