Retry some writes on EINTR again

I guess?
Fixes f0e007c439 (Relocate tty metadata and protocols and clean it up,
2025-06-19).
This commit is contained in:
Johannes Altmanninger
2025-07-24 16:04:21 +02:00
parent eaa837effa
commit 5970f34a60
2 changed files with 5 additions and 5 deletions

View File

@@ -1355,7 +1355,7 @@ pub fn valid_func_name(name: &wstr) -> bool {
/// A rusty port of the C++ `write_loop()` function from `common.cpp`. This should be deprecated in
/// favor of native rust read/write methods at some point.
pub fn write_loop<Fd: AsRawFd>(fd: &Fd, buf: &[u8]) -> std::io::Result<()> {
pub fn safe_write_loop<Fd: AsRawFd>(fd: &Fd, buf: &[u8]) -> std::io::Result<()> {
let fd = fd.as_raw_fd();
let mut total = 0;
while total < buf.len() {
@@ -1374,6 +1374,8 @@ pub fn write_loop<Fd: AsRawFd>(fd: &Fd, buf: &[u8]) -> std::io::Result<()> {
Ok(())
}
pub use safe_write_loop as write_loop;
// Output writes always succeed; this adapter allows us to use it in a write-like macro.
struct OutputWriteAdapter<'a, T: Output>(&'a mut T);

View File

@@ -1,7 +1,7 @@
//! Utility for transferring the tty to a child process in a scoped way,
//! and reclaiming it after.
use crate::common;
use crate::common::{self, safe_write_loop};
use crate::flog::{FLOG, FLOGF};
use crate::global_safety::RelaxedAtomicBool;
use crate::job_group::JobGroup;
@@ -18,7 +18,6 @@
use crate::wutil::perror;
use libc::{EINVAL, ENOTTY, EPERM, STDIN_FILENO, WNOHANG};
use std::mem::MaybeUninit;
use std::os::fd::BorrowedFd;
use std::sync::atomic::{AtomicBool, AtomicPtr, AtomicU8, Ordering};
// Facts about our environment, which inform how we handle the tty.
@@ -316,8 +315,7 @@ pub fn safe_deactivate_tty_protocols() {
let commands = protocols.safe_get_commands(false);
// Safety: just writing data to stdout.
let stdout_fd = unsafe { BorrowedFd::borrow_raw(libc::STDOUT_FILENO) };
let _ = nix::unistd::write(stdout_fd, commands);
let _ = safe_write_loop(&libc::STDOUT_FILENO, commands);
TTY_PROTOCOLS_ACTIVE.store(false, Ordering::Release);
}