luet/vendor/github.com/moby/buildkit/source/git/gitsource_unix.go
Ettore Di Giacinto 92e18d5782 Support priv/unpriv image extraction
Optionally add back privileged extraction which can be enabled with
LUET_PRIVILEGED_EXTRACT=true

Signed-off-by: Ettore Di Giacinto <mudler@sabayon.org>
2021-06-16 23:30:28 +02:00

36 lines
622 B
Go

// +build !windows
package git
import (
"context"
"os/exec"
"syscall"
"time"
)
func runProcessGroup(ctx context.Context, cmd *exec.Cmd) error {
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
if err := cmd.Start(); err != nil {
return err
}
waitDone := make(chan struct{})
go func() {
select {
case <-ctx.Done():
syscall.Kill(-cmd.Process.Pid, syscall.SIGTERM)
go func() {
select {
case <-waitDone:
case <-time.After(10 * time.Second):
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL)
}
}()
case <-waitDone:
}
}()
err := cmd.Wait()
close(waitDone)
return err
}