Skip to content

Commit

Permalink
Clean up some stale comments and restore libc usage in flog_safe
Browse files Browse the repository at this point in the history
flog_safe should be explicitly async-signal-safe functions; let's avoid
nix in that module for this reason.
  • Loading branch information
ridiculousfish committed Jan 21, 2024
1 parent f3e8272 commit 3ecd835
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 3 additions & 1 deletion src/fork_exec/flog_safe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
1 change: 0 additions & 1 deletion src/history/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 3ecd835

Please sign in to comment.