Skip to content

Commit

Permalink
fixes GoogleContainerTools#247 killing grandchildren processes
Browse files Browse the repository at this point in the history
  • Loading branch information
balopat committed Jul 26, 2018
1 parent 8cad6d0 commit cbc12ac
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/pkg/v1"
"github.com/sirupsen/logrus"
"github.com/pkg/errors"
)

type RunCommand struct {
Expand Down Expand Up @@ -88,10 +89,23 @@ func (r *RunCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bui
}
gid = uint32(gid64)
}
cmd.SysProcAttr = &syscall.SysProcAttr{}
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
}
return cmd.Run()

if err := cmd.Start(); err != nil {
return errors.Wrap(err, "starting command")
}
pgid, err := syscall.Getpgid(cmd.Process.Pid)
if err != nil {
return errors.Wrap(err, "getting group id for process")
}

if err := cmd.Wait(); err != nil {
return errors.Wrap(err, "waiting for process to exit")
}

return syscall.Kill(-pgid, syscall.SIGKILL)
}

// FilesToSnapshot returns nil for this command because we don't know which files
Expand Down

0 comments on commit cbc12ac

Please sign in to comment.