v0.10.0 8a8e2b3

process_unix.go RawHistoryFolder

1//go:build !windows
2
3package subagents
4
5import (
6	"io"
7	"os/exec"
8	"sync"
9	"syscall"
10	"time"
11)
12
13// configureWorkerProcess makes cancellation target the worker's process
14// group rather than only the worker itself. CommandContext calls cmd.Cancel
15// from its context watcher, so descendants that inherited the worker's group
16// are terminated before execRunner waits for their output pipes to close.
17func configureWorkerProcess(cmd *exec.Cmd, pipes ...io.Closer) {
18	setProcessGroup(cmd)
19	cmd.WaitDelay = workerProcessWaitDelay
20	var closePipes sync.Once
21	cmd.Cancel = func() error {
22		err := killProcessGroup(cmd)
23		closePipes.Do(func() { closeWorkerPipes(pipes) })
24		return err
25	}
26}
27
28const workerProcessWaitDelay = 5 * time.Second
29
30// closeWorkerPipes closes the parent-side readers returned by StdoutPipe and
31// StderrPipe. Closing these descriptors lets the custom reader goroutines exit
32// if a descendant has outlived the worker process.
33func closeWorkerPipes(pipes []io.Closer) {
34	for _, pipe := range pipes {
35		if pipe != nil {
36			_ = pipe.Close()
37		}
38	}
39}
40
41// setProcessGroup puts a worker in a process group of its own. This keeps a
42// canceled worker from sharing a group with the supervising zut process.
43func setProcessGroup(cmd *exec.Cmd) {
44	cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
45}
46
47// killProcessGroup forcefully terminates the worker group. Cancellation is a
48// forceful path: the supervisor already offers a graceful shutdown through
49// the worker inbox, while SIGKILL ensures a descendant cannot keep the
50// worker's stdout or stderr pipe open indefinitely.
51func killProcessGroup(cmd *exec.Cmd) error {
52	if cmd == nil || cmd.Process == nil {
53		return nil
54	}
55	return forceKillProcess(cmd.Process.Pid)
56}
57
58func forceKillProcess(pid int) error {
59	if pid <= 0 {
60		return nil
61	}
62	// With Setpgid, the worker's PID is also the process-group ID. A negative
63	// PID addresses the whole group rather than just the worker process.
64	err := syscall.Kill(-pid, syscall.SIGKILL)
65	if err == syscall.ESRCH {
66		return nil
67	}
68	return err
69}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close