Clean up some stale comments and restore libc usage in flog_safe

flog_safe should be explicitly async-signal-safe functions; let's avoid
nix in that module for this reason.
This commit is contained in:
ridiculousfish 2024-01-21 11:54:26 -08:00
parent f3e8272c5d
commit 3ecd835f58
4 changed files with 5 additions and 4 deletions

View File

@ -1468,7 +1468,7 @@ fn can_be_encoded(wc: char) -> bool {
}
/// Call read, blocking and repeating on EINTR. Exits on EAGAIN.
/// \return the number of bytes read, or 0 on EOF. On EAGAIN, returns -1 if nothing was read.
/// \return the number of bytes read, or 0 on EOF, or an error.
pub fn read_blocked(fd: RawFd, buf: &mut [u8]) -> nix::Result<usize> {
loop {
let res = nix::unistd::read(fd, buf);

View File

@ -84,7 +84,9 @@ pub fn flog_impl_async_safe(fd: i32, s: impl FloggableDisplayAsyncSafe) {
let bytes: &[u8] = s.to_flog_str_async_safe(&mut storage);
// Note we deliberately do not retry on signals, etc.
// This is used to report error messages after fork() in the child process.
let _ = nix::unistd::write(fd, bytes);
unsafe {
let _ = libc::write(fd, bytes.as_ptr() as *const libc::c_void, bytes.len());
}
}
/// Variant of FLOG which is async-safe to use after fork().

View File

@ -228,7 +228,6 @@ fn should_mmap() -> bool {
}
/// Read from `fd` to fill `dest`, zeroing any unused space.
// Return true on success, false on failure.
fn read_from_fd(fd: RawFd, mut dest: &mut [u8]) -> nix::Result<()> {
while !dest.is_empty() {
match nix::unistd::read(fd, dest) {

View File

@ -684,7 +684,7 @@ fn read_ni(parser: &Parser, fd: RawFd, io: &IoChain) -> i32 {
return 1;
}
// Read all data into a std::string.
// Read all data into a vec.
let mut fd_contents = Vec::with_capacity(usize::try_from(buf.st_size).unwrap());
loop {
let mut buff = [0_u8; 4096];