Merge pull request #258 from balopat/fix_247_daemons

Kill grandchildren spun up by child processes
This commit is contained in:
Balint Pato 2018-07-26 14:49:53 -07:00 committed by GitHub
commit ba4c7f4b57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 2 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
out/
.idea

View File

@ -0,0 +1,3 @@
FROM busybox
RUN while true; do dd if=/dev/zero of=file`date +%s`.txt count=16000 bs=256 > /dev/null 2>&1; done &
RUN echo "wait a second..." && sleep 2 && ls -lrat file*.txt || echo "test passed."

View File

@ -27,6 +27,7 @@ import (
"github.com/GoogleContainerTools/kaniko/pkg/util"
"github.com/docker/docker/builder/dockerfile/instructions"
"github.com/google/go-containerregistry/pkg/v1"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
)
@ -88,10 +89,29 @@ 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")
}
//it's not an error if there are no grandchildren
if err := syscall.Kill(-pgid, syscall.SIGKILL); err != nil && err.Error() != "no such process" {
return err
}
return nil
}
// FilesToSnapshot returns nil for this command because we don't know which files