Fix interactive shell job control by setting foreground process group#56
Merged
jy-tan merged 2 commits intoUse-Tusk:mainfrom Feb 24, 2026
Merged
Conversation
Two issues prevented job control in interactive shells (e.g. "fence bash"): 1. The macOS sandbox profile blocked file-ioctl on /dev/ttys* (the inherited PTY slave device) unless allowPty was enabled. This caused isatty(), tcgetpgrp(), and tcsetpgrp() to fail with ENOTTY inside the sandbox. Fix: always allow file-ioctl on /dev/ttys* since these are inherited terminal fds, not new PTY allocations. 2. The child process was not placed in its own process group, so bash could not call tcsetpgrp() to become the foreground group (EPERM). Fix: use Setpgid to give the child its own process group, then have the parent call tcsetpgrp() to hand terminal foreground to the child after Start(). After Wait(), the parent reclaims the foreground. SIGTTOU is ignored to prevent the parent from being stopped. Fixes Use-Tusk#55 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
0057cde to
c1e8d92
Compare
jy-tan
reviewed
Feb 24, 2026
Contributor
jy-tan
left a comment
There was a problem hiding this comment.
Thanks for the raising the issue and PR, overall looks good, just a comment.
- Save the terminal's actual foreground group via tcgetpgrp() instead of the parent's process group via Getpgrp(). More correct for restore. - Use Getpgid(childPid) to get the child's process group instead of assuming pid == pgid. - Add integration test that builds the fence binary and runs "fence bash" with a real PTY via creack/pty, verifying no "no job control" warning. The test fails without both fixes (sandbox profile + process group handoff) and passes with them. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jy-tan
approved these changes
Feb 24, 2026
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.
Summary
Fixes
fence bash(and other interactive shells) reporting "cannot set terminal process group" and "no job control in this shell".Two root causes:
Sandbox profile blocks terminal ioctl: The macOS sandbox profile only allows
file-ioctlon/dev/ttys*whenallowPtyis enabled. But the inherited stdin/stdout/stderr point to a PTY slave device (/dev/ttysNNN), and basic terminal operations likeisatty(),tcgetpgrp(), andtcsetpgrp()needfile-ioctlon that device. Without it, bash can't even detect it has a terminal. Fix: always allowfile-ioctlon/dev/ttys*— this permits ioctl on inherited terminal fds without enabling new PTY allocation (which remains gated byallowPty).No foreground process group handoff: The child process inherits fence's process group, so when bash creates its own process group and calls
tcsetpgrp(), it fails with EPERM (only the foreground group can calltcsetpgrp). Fix: place the child in its own process group viaSetpgid, then have the parent calltcsetpgrp()to hand terminal foreground to the child afterStart(). AfterWait(), the parent reclaims the foreground.SIGTTOUis ignored so the parent doesn't get stopped during reclaim.Fixes #55
Test plan
go build ./...succeedsgo test ./...all passfence bash— no "cannot set terminal process group" warning, job control works (Ctrl+Z,fg,bg)echo ls | fence bash— piped input still worksfence bash -c "echo hello"— non-interactive usage still worksfence --template code bash— works with explicit template🤖 Generated with Claude Code