-
Notifications
You must be signed in to change notification settings - Fork 2
fix: cancel host process trees and scope daemon cleanup #83
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7f5c27d
fix: cancel host process trees and scope daemon cleanup
roodboi bd1c285
fix: cancel verified TTY command descendants
roodboi 1cc238d
fix: own terminal command groups before forwarding cancellation
roodboi 8091e3a
fix: skip CLI initialization in terminal supervisor
roodboi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,12 @@ | ||
| #!/usr/bin/env bun | ||
|
|
||
| import { runCli } from "./packages/cli/index.ts"; | ||
| import { | ||
| runTtySupervisor, | ||
| TTY_SUPERVISOR_ARGUMENT, | ||
| } from "./src/lib/tty-supervisor.ts"; | ||
|
|
||
| const exitCode = await runCli(Bun.argv.slice(2)); | ||
| process.exitCode = exitCode; | ||
| if (Bun.argv[2] === TTY_SUPERVISOR_ARGUMENT && process.send) { | ||
| process.exit(await runTtySupervisor()); | ||
| } | ||
| const { runCli } = await import("./packages/cli/index.ts"); | ||
| process.exitCode = await runCli(Bun.argv.slice(2)); |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| import { dlopen, FFIType, type Pointer } from "bun:ffi"; | ||
| import { constants } from "node:os"; | ||
|
|
||
| /** POSIX job control without a proxy PTY: all three command streams stay intact. */ | ||
| export function openTerminalControl() { | ||
| const symbols = { | ||
| setpgid: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 }, | ||
| getpgrp: { args: [], returns: FFIType.i32 }, | ||
| tcgetpgrp: { args: [FFIType.i32], returns: FFIType.i32 }, | ||
| tcsetpgrp: { args: [FFIType.i32, FFIType.i32], returns: FFIType.i32 }, | ||
| tcgetattr: { args: [FFIType.i32, FFIType.ptr], returns: FFIType.i32 }, | ||
| tcsetattr: { | ||
| args: [FFIType.i32, FFIType.i32, FFIType.ptr], | ||
| returns: FFIType.i32, | ||
| }, | ||
| signal: { args: [FFIType.i32, FFIType.ptr], returns: FFIType.ptr }, | ||
| } as const; | ||
| const library = | ||
| process.platform === "darwin" ? "/usr/lib/libSystem.B.dylib" : "libc.so.6"; | ||
| const libc = dlopen(library, symbols); | ||
| function withoutBackgroundStop<T>(operation: () => T): T { | ||
| const previous = libc.symbols.signal( | ||
| constants.signals.SIGTTOU, | ||
| 1 as Pointer | ||
| ); | ||
| try { | ||
| return operation(); | ||
| } finally { | ||
| libc.symbols.signal(constants.signals.SIGTTOU, previous); | ||
| } | ||
| } | ||
| return { | ||
| createGroup: () => libc.symbols.setpgid(0, 0) === 0, | ||
| group: () => libc.symbols.getpgrp(), | ||
| foreground: () => libc.symbols.tcgetpgrp(0), | ||
| setForeground: (group: number) => | ||
| withoutBackgroundStop(() => libc.symbols.tcsetpgrp(0, group) === 0), | ||
| attributes: () => { | ||
| // Opaque termios storage, larger than both Darwin and Linux structures. | ||
| const value = new Uint8Array(256); | ||
| return libc.symbols.tcgetattr(0, value) === 0 ? value : null; | ||
| }, | ||
| restoreAttributes: (value: Uint8Array | null) => { | ||
| if (value) { | ||
| withoutBackgroundStop(() => libc.symbols.tcsetattr(0, 0, value)); | ||
| } | ||
| }, | ||
| close: () => libc.close(), | ||
| }; | ||
| } | ||
|
|
||
| export function signalOwnedGroup(pid: number, signal: NodeJS.Signals): void { | ||
| try { | ||
| process.kill(-pid, signal); | ||
| } catch { | ||
| // The owned group may already have exited. | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.