-
Notifications
You must be signed in to change notification settings - Fork 12
Fix hang in source <(lets completion -s zsh) under job control #383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package util | ||
|
|
||
| import ( | ||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| // IsForegroundProcess reports whether this process belongs to the foreground | ||
| // process group of the terminal referred to by fd. Reading or reconfiguring a | ||
| // terminal from a background process group suspends the process with | ||
| // SIGTTIN/SIGTTOU — e.g. inside process substitution: | ||
| // `source <(lets completion -s zsh)`. | ||
| func IsForegroundProcess(fd uintptr) bool { | ||
| pgrp, err := unix.IoctlGetInt(int(fd), unix.TIOCGPGRP) | ||
| if err != nil { | ||
| return false | ||
| } | ||
|
|
||
| return pgrp == unix.Getpgrp() | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,3 +51,13 @@ setup() { | |
| assert_line --index 0 "--debug[Run with debug]" | ||
| assert_line --index 1 "--env[Set env]" | ||
| } | ||
|
|
||
| # Regression: querying the terminal background color from a background process | ||
| # group suspends the process with SIGTTOU, so `source <(lets completion -s zsh)` | ||
| # in an interactive (job-control) shell hung forever. `script` allocates a PTY, | ||
| # `set -m` enables job control like an interactive shell. | ||
| @test "completion: source <(lets completion -s zsh) must not hang under job control" { | ||
| run timeout 10 script -qec "zsh -c 'set -m; source <(lets completion -s zsh); echo SOURCED_OK'" /dev/null | ||
| assert_success | ||
| assert_output --partial "SOURCED_OK" | ||
|
Comment on lines
+59
to
+62
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Guard the regression test with skips when This test will fail on systems without |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Differentiate ioctl failures from true background status to avoid disabling detection on non-tty fds.
Because any
unix.IoctlGetInterror is treated as "not foreground", non-tty fds (e.g., when stdout is a file/pipe orEBADF) are incorrectly handled as background, forcing callers to skip detection. SinceSIGTTIN/SIGTTOUonly apply to ttys, it would be better to treatENOTTY(and possibly other ioctl failures) as "safe" and either returntrueor at least distinguish them from a real background process-group indication, so non-tty outputs retain normal detection behavior.