You can use File and permissions methods operating on uds_path directly.
Alternatively, if you're worried about race conditions, you can use AsRawFd in std::os::unix::io - Rust to get the file descriptor from the socket, and change permissions through it.
Hi @kornel,
thanks for the hint, but I don't understand how the AsRawFd should be used. listener.as_raw_fd() returns nothing more than an i32.
Could you point me to any sample code?
let file = File::from_raw_fd(listener.as_raw_fd())?;
let mut perms = file.metadata()?.permissions();
perms.set_readonly(true);
file.set_permissions(perms)?;
let _ = file.into_raw_fd(); // don't close the file
This fd-dance is needed only when you're paranoid that a rogue process on the same machine could hijack the socket before you change the permissions. If you're not worried, then use File::open(uds_path).
@kornel
I am still not able to make it work... File::from_raw_fd(...) is an unsafe function which is not an option in my case and File.open(uds_path) returns a "file not found error" which is quite strange since the file is definitely there and the path is definitely correct
Can it be caused to the fact that the file is a socket?