Skip to content

Keeping errno for HAL messages logged to a file or pipe - #74

Merged
wberube merged 1 commit into
OpenIPC:masterfrom
DeathCamel58:hal-errno
Nov 8, 2026
Merged

wberube merged 1 commit into
OpenIPC:masterfrom
DeathCamel58:hal-errno

Conversation

@DeathCamel58

Copy link
Copy Markdown
Contributor

The HAL_* macros pick their colours with isatty(STDERR_FILENO) before the message's arguments are evaluated. When stderr isn't a terminal (a log file, a pipe, a service manager), isatty() sets errno to ENOTTY. So every HAL message that reports strerror(errno) printed "Not a tty" (musl) or "Inappropriate ioctl for device" (glibc) instead of the actual failure. The colour test now saves and restores errno (hal_stderr_is_tty() in src/hal/macros.h).

Found by openipc-ai while running the S3L backend (#71) with its log redirected: an ioctl that returned EPERM was reported as "Not a tty".

Tested with errno = EPERM; HAL_DANGER("test", "ioctl failed: %s\n", strerror(errno));:

stderr to a file stderr on a terminal
before ioctl failed: Inappropriate ioctl for device ioctl failed: Operation not permitted
after ioctl failed: Operation not permitted ioctl failed: Operation not permitted

Divinus also builds with it for S3L (VFPv3 musl toolchain) and on the host. It touches only the header, so every platform picks it up.

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.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Preserve errno when HAL logs to a file or pipe

🐞 Bug fix 🕐 Less than 10 minutes

Grey Divider

AI Description

• Preserve the original errno across HAL's terminal check so redirected logs report the actual
 failure.
• Keep terminal color behavior unchanged for all HAL logging macros.
Diagram

graph TD
    A["Original errno"] --> B["HAL logging macro"] --> C["HAL_COLOR"] --> D["Terminal check"] --> E["Restore errno"] --> F["Format message"]
Loading
High-Level Assessment

Keeping errno preservation in the shared terminal-check helper is the narrowest fix: it protects every HAL_COLOR use without changing the logging macros' formatting or color behavior. Wrapping each logging macro separately would duplicate the fix.

Files changed (1) +10 / -1

Bug fix (1) +10 / -1
macros.hPreserve errno during HAL terminal detection +10/-1

Preserve errno during HAL terminal detection

• Adds an inline helper that saves errno, calls isatty on stderr, and restores errno before returning the result. HAL_COLOR now uses the helper, preventing redirected logging from replacing an error reported through strerror(errno) with ENOTTY.

src/hal/macros.h

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@wberube
wberube merged commit b28c348 into OpenIPC:master Nov 8, 2026
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