Repository navigation
Fix o.shell_succeeds() always returning false inside Hyprland - #6939
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes Hyprland NVIDIA detection by deriving shell success from a stdout marker instead of an unavailable child exit status.
Changes:
- Replaces
os.execute()status handling withio.popen(). - Detects successful commands through an
OKmarker.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| function o.shell_succeeds(command) | ||
| local ok, _, code = os.execute(command .. " >/dev/null 2>&1") | ||
| return ok == true or ok == 0 or code == 0 | ||
| local pipe = io.popen(command .. " >/dev/null 2>&1 && echo OK") |
There was a problem hiding this comment.
Good catch, and it reproduced exactly as described — o.shell_succeeds("printf OK; false") returned true, because the redirection bound only to false and printf wrote the marker straight into the pipe.
Fixed by running the command in a subshell, so the redirection covers all of it and only the helper's own marker can reach stdout:
local pipe = io.popen("( " .. command .. " ) >/dev/null 2>&1 && echo OK")A subshell rather than a { ...; } group so a command ending in & stays valid. Re-tested against printf OK; false, echo OK && false, sh -c "exit 3", true & and a missing command, all correct now, and re-confirmed inside the running compositor.
No live caller was affected — the only callers are the simple commands in hypr/nvidia.lua — but the helper is general and the flaw was real.
— 🤖 Claude, posting on behalf of @dhh
Hyprland reaps its own children, so os.execute() gets ECHILD from waitpid and never sees an exit status. Every call reported failure, which meant the NVIDIA env detection in hypr/nvidia.lua never set NVD_BACKEND, LIBVA_DRIVER_NAME or __GLX_VENDOR_LIBRARY_NAME. Read a marker off stdout instead. Closes #6914 Co-Authored-By: Claude Opus 5 <[email protected]>
5bb3ce4 to
0965ac2
Compare
Hyprland reaps its own children, so
os.execute()gets ECHILD fromwaitpidand never sees an exit status. Every call reported failure. Confirmed against the running compositor:The only callers are
default/hypr/nvidia.lua, soNVD_BACKEND,LIBVA_DRIVER_NAMEand__GLX_VENDOR_LIBRARY_NAMEwere never set on NVIDIA hardware.Reads a marker off stdout instead, which does not depend on reaping the child.
io.popen's own close status is unreliable for the same reason, so it is deliberately not checked.Verified inside the running compositor (
true→ true,false→ false) and standalone, where a command that writes its own output to stdout still reports correctly.Note this cannot be caught by a unit test:
test/shell.d/hyprland-default-config-test.shruns under standalonelua, whereos.executebehaves normally.Closes #6914
— 🤖 Claude, posting on behalf of @dhh