v0.50.0 c4ec31f

proc_wait_linux.go RawHistoryFolder

1//go:build linux
2
3package mcp
4
5import (
6	"errors"
7	"os"
8	"strconv"
9	"strings"
10
11	"golang.org/x/sys/unix"
12)
13
14// waitLeaderExited blocks until pid (our direct child) has exited, leaving it
15// unreaped (a zombie) so its pid, and with it the process-group id, cannot be
16// reused. It reports false if the wait failed.
17func waitLeaderExited(pid int) bool {
18	var info unix.Siginfo
19	for {
20		err := unix.Waitid(unix.P_PID, pid, &info, unix.WEXITED|unix.WNOWAIT, nil)
21		if errors.Is(err, unix.EINTR) {
22			continue
23		}
24		return err == nil
25	}
26}
27
28// liveGroupMembers reports whether any non-zombie process is in process group
29// pgid, reading /proc. known is false when /proc or a member's stat cannot be
30// read. The scan is not atomic, so callers use it only as a hint.
31func liveGroupMembers(pgid int) (live, known bool) {
32	entries, err := os.ReadDir("/proc")
33	if err != nil {
34		return false, false
35	}
36	sawProc := false
37	for _, e := range entries {
38		if _, err := strconv.Atoi(e.Name()); err != nil {
39			continue
40		}
41		sawProc = true
42		raw, err := os.ReadFile("/proc/" + e.Name() + "/stat")
43		if errors.Is(err, os.ErrNotExist) || errors.Is(err, unix.ESRCH) {
44			continue // exited meanwhile
45		}
46		if err != nil {
47			return false, false
48		}
49		state, group, ok := parseProcStat(string(raw))
50		if !ok || group != pgid || state == 'Z' || state == 'X' {
51			continue
52		}
53		return true, true
54	}
55	return false, sawProc
56}
57
58// parseProcStat extracts the state and process-group fields of a
59// /proc/<pid>/stat line. The command name is parenthesised and may itself
60// contain spaces and parentheses, so fields are counted after the last ')'.
61func parseProcStat(stat string) (state byte, pgrp int, ok bool) {
62	i := strings.LastIndexByte(stat, ')')
63	if i < 0 {
64		return 0, 0, false
65	}
66	fields := strings.Fields(stat[i+1:]) // state ppid pgrp ...
67	if len(fields) < 3 || len(fields[0]) != 1 {
68		return 0, 0, false
69	}
70	pg, err := strconv.Atoi(fields[2])
71	if err != nil {
72		return 0, 0, false
73	}
74	return fields[0][0], pg, true
75}

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 477

↑↓ moveenter openesc close