Skip to content

Conversation

@yuki0iq
Copy link
Contributor

@yuki0iq yuki0iq commented Nov 21, 2025

Error::other allocates memory (see rust-lang/rust#148971). This is bad in multi-threaded programs, and teletypewriter is a library which can be used in such. If the fork occurs while the allocator lock is held by another thread, deadlocks can occur, since there's no one left in the new process to unlock the mutex. I do not believe this is UB, and modern libc offer protections against this issue, but this isn't POSIX-compliant and should preferably be avoided.

Non-allocating std::io::Error::last_os_error can be used instead. This doesn't allow an additional message to be added, but since error messages aren't transmitted across pre_exec boundary anyway, this doesn't make visible behavior any worse. On the flip side, this ensures that the correct error code is forwarded to the parent process, instead of the default -EINVAL.

Copy link
Owner

@raphamorim raphamorim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

regardless the allocation i think even the error message should be better that way. thanks!

@raphamorim raphamorim merged commit ee3545e into raphamorim:main Nov 21, 2025
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants