Repository navigation
Keeping errno for HAL messages logged to a file or pipe - #74
Merged
Merged
Conversation
The HAL_* macros pick their colours with isatty(STDERR_FILENO) before a message's arguments are evaluated. When stderr is not a terminal (a log file, a pipe, a service manager), isatty() sets errno to ENOTTY, so every message that reports strerror(errno) printed "Not a tty" (musl) or "Inappropriate ioctl for device" (glibc) instead of the failure it was about. The colour test now keeps errno. Found while running the Ambarella S3L backend (OpenIPC#71) with its log redirected: a refused ioctl that returned EPERM was reported as "Not a tty". Tested with a HAL_DANGER(..., strerror(errno)) after errno = EPERM: stderr to a file printed "Inappropriate ioctl for device" before and "Operation not permitted" after; on a terminal both print the latter.
PR Summary by QodoPreserve errno when HAL logs to a file or pipe
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
HAL_*macros pick their colours withisatty(STDERR_FILENO)before the message's arguments are evaluated. When stderr isn't a terminal (a log file, a pipe, a service manager),isatty()setserrnotoENOTTY. So every HAL message that reportsstrerror(errno)printed "Not a tty" (musl) or "Inappropriate ioctl for device" (glibc) instead of the actual failure. The colour test now saves and restoreserrno(hal_stderr_is_tty()insrc/hal/macros.h).Found by openipc-ai while running the S3L backend (#71) with its log redirected: an ioctl that returned
EPERMwas reported as "Not a tty".Tested with
errno = EPERM; HAL_DANGER("test", "ioctl failed: %s\n", strerror(errno));:ioctl failed: Inappropriate ioctl for deviceioctl failed: Operation not permittedioctl failed: Operation not permittedioctl failed: Operation not permittedDivinus also builds with it for S3L (VFPv3 musl toolchain) and on the host. It touches only the header, so every platform picks it up.