Show error message when trace feature fails on fork#2013
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughSummaryTwo small, focused changes fix issue
Implementation qualityClean, minimal, and idiomatic: preserves errno with the standard pattern, avoids clobbering errors during cleanup, and ensures the UI always presents immediate feedback. Changes are narrowly scoped, no public API changes, and follow conventional C error-handling. Commit split is logical and in-scope (UI/path handling in Action.c; error-preservation and robustness in TraceScreen.c). TestsBuild and unit checks pass (./autogen.sh && ./configure && make; make check). Manual test guidance included (e.g., ulimit -u 0 or seccomp to simulate fork failure) to verify the visible error message. Fixes WalkthroughTraceScreen_forkTracer() now preserves errno during its error-cleanup. actionStrace includes <errno.h>, captures strerror(errno) on fork failure, appends that message to the TraceScreen/InfoScreen, and runs InfoScreen regardless of success. TraceScreen_updateTrace() now initializes fd_strace to -1, only calls fileno(this->strace) when non-NULL, and gates readiness/FD_ISSET checks on fd_strace >= 0 and this->strace_alive. Assessment against linked issues
Out-of-scope changes
Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 Infer (1.2.0)TraceScreen.cTraceScreen.c:8:10: fatal error: 'config.h' file not found ... [truncated 689 characters] ... Action.cAction.c:8:10: fatal error: 'config.h' file not found ... [truncated 670 characters] ... tem" Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
In the second commit you accidentally deleted |
| close(fdpair[1]); | ||
| close(fdpair[0]); | ||
| errno = saved_errno; | ||
| } while (0); |
There was a problem hiding this comment.
I think the do and while(0) keywords can be omitted here without violating the C99 spec. Just keep the { } braces for this code block.
I know the do and while(0) keywords would be necessary when defining the code block as a macro, or there are break statements inside the block that effectively serve as goto jumps.
There was a problem hiding this comment.
Fixed in d66df1f — replaced do { ... } while(0) with plain { ... } braces since there are no break statements inside the block.
When TraceScreen_forkTracer() fails (e.g. OOM, PID quota exceeded, seccomp/AppArmor restrictions), the TraceScreen was not displayed and users received no feedback. The UI appeared unresponsive. - Show error message in TraceScreen when forkTracer fails - Preserve errno across cleanup in error path for accurate reporting - Use plain snprintf (not xSnprintf) to avoid fail() on truncation - Guard NULL strace before fileno() to prevent crash - Guard all fd_strace usage with fd_strace >= 0 checks Fixes htop-dev#1991 Assisted-by: Claude (Anthropic)
41e7977 to
d66df1f
Compare
Summary
TraceScreen_forkTracer()failsProblem
When the trace feature (strace/truss) fails during the fork phase (e.g., out of memory, PID quota exceeded, seccomp/AppArmor restrictions), the TraceScreen was not displayed and users received no feedback. The UI appeared unresponsive even when pressing the
skey multiple times.Solution
actionStrace()to always run the InfoScreen, adding an error message line whenforkTracerfailsTraceScreen_forkTracer()to preserve errno across cleanup operations for accurate error reportingChanges
Action.cTraceScreen.cTest Plan
./autogen.sh && ./configure && makemake checkpassesulimit -u 0or use seccomp) and verify error message appears in TraceScreenAI disclosure
Assisted-by: Claude (Anthropic)
Fixes #1991