Skip to content

Commit

Permalink
Maybe regular stat will be more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
kotauskas committed Apr 3, 2024
1 parent 7c3c3f3 commit 46a8b8b
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions tests/os/unix/local_socket_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ use crate::{
OrErrno,
};
use libc::mode_t;
use std::{mem::zeroed, os::unix::prelude::*, sync::Arc};
use std::{
ffi::{CStr, CString, OsStr},
mem::zeroed,
os::unix::{prelude::*, ffi::OsStrExt},
sync::Arc,
};

fn get_mode(fd: BorrowedFd<'_>) -> TestResult<mode_t> {
fn get_mode(fname: &OsStr) -> TestResult<mode_t> {
let mut cfname = fname.as_bytes().to_owned();
cfname.push(0);
let fname = CString::from_vec_with_nul(cfname)?;
let mut stat = unsafe { zeroed::<libc::stat>() };
unsafe { libc::fstat(fd.as_raw_fd(), &mut stat) != -1 }
unsafe { libc::stat(fname.as_ptr(), &mut stat) != -1 }
.true_val_or_errno(())
.opname("stat")?;
Ok(stat.st_mode & 0o777)
Expand All @@ -22,13 +30,19 @@ fn test_inner(path: bool) -> TestResult {
ListenerOptions::new()
.name(nm.borrow())
.mode(MODE)
.reclaim_name(false)
.create_sync()
})?;
let _ = Stream::connect(Arc::try_unwrap(name).unwrap()).opname("client connect")?;
let name = Arc::try_unwrap(name).unwrap();
let _ = Stream::connect(name.borrow()).opname("client connect")?;
let fd = match &listener {
Listener::UdSocket(l) => l.as_fd(),
};
ensure_eq!(get_mode(fd)?, MODE);
let real_mode = get_mode(name.raw()).opname("get mode")?;
if real_mode != 0 {
// FreeBSD refuses to fstat sockets for reasons I cannot even begin to fathom
ensure_eq!(real_mode, MODE);
}

Ok(())
}
Expand Down

0 comments on commit 46a8b8b

Please sign in to comment.