turbo-editors/turbo-corepublic Fork 0
v1.0.1
Commits
Clone
git clone https://git.rickub.com/turbo-editors/turbo-core.git
git clone ssh://git@rickub.com/turbo-editors/turbo-core.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

🛟 Updated. 28d5985 · on v1.0.1 · k33g · 13h ago
shell_unix.go · 47 lines · 1.6 KBGo Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
//go:build unix

package tools

import (
	"os"
	"os/exec"
	"syscall"
)

// shellProgram is the shell every Unix has.
func shellProgram() string { return "/bin/sh" }

// shellArgs makes the shell run one command line and exit.
func shellArgs(command string) []string { return []string{"-c", command} }

// childAttributes puts a command in a process group of its own.
//
// Without it, stopping a command kills only the shell. `go test ./...` spawns a
// test binary per package, `make` spawns compilers: those keep running, and —
// worse — they inherit the output pipe, so the goroutine reading it blocks
// until they finish rather than when the command was stopped.
func childAttributes(*exec.Cmd, string) *syscall.SysProcAttr {
	return &syscall.SysProcAttr{Setpgid: true}
}

// processGroup is the group a Unix command runs in, addressed by its
// leader's pid.
type processGroup struct{ process *os.Process }

// newGroup returns the group a started command belongs to.
func newGroup(process *os.Process) group { return processGroup{process: process} }

// kill stops the process and everything it started.
//
// The negative pid is what makes it the group rather than the one process. A
// group that has already gone gives an error nobody can act on, so it is
// dropped: stopping something twice, or stopping something that just ended, is
// not a failure.
func (g processGroup) kill() {
	if err := syscall.Kill(-g.process.Pid, syscall.SIGKILL); err != nil {
		_ = g.process.Kill() // it may not have got its own group; kill it alone
	}
}

// release has nothing to give back: a process group is not a resource.
func (processGroup) release() {}