Merge pull request #5791 from bernerdschaefer/nsinit-exec-forwards-signals
"nsinit exec ..." forwards signals to container
This commit is contained in:
commit
b2ccfae5c4
|
@ -5,6 +5,8 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
@ -39,7 +41,7 @@ func main() {
|
||||||
exitCode, err = nsinit.ExecIn(container, nspid, os.Args[2:])
|
exitCode, err = nsinit.ExecIn(container, nspid, os.Args[2:])
|
||||||
} else {
|
} else {
|
||||||
term := nsinit.NewTerminal(os.Stdin, os.Stdout, os.Stderr, container.Tty)
|
term := nsinit.NewTerminal(os.Stdin, os.Stdout, os.Stderr, container.Tty)
|
||||||
exitCode, err = nsinit.Exec(container, term, "", dataPath, os.Args[2:], nsinit.DefaultCreateCommand, nil)
|
exitCode, err = startContainer(container, term, dataPath, os.Args[2:])
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -95,3 +97,31 @@ func readPid() (int, error) {
|
||||||
}
|
}
|
||||||
return pid, nil
|
return pid, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// startContainer starts the container. Returns the exit status or -1 and an
|
||||||
|
// error.
|
||||||
|
//
|
||||||
|
// Signals sent to the current process will be forwarded to container.
|
||||||
|
func startContainer(container *libcontainer.Container, term nsinit.Terminal, dataPath string, args []string) (int, error) {
|
||||||
|
var (
|
||||||
|
cmd *exec.Cmd
|
||||||
|
sigc = make(chan os.Signal, 10)
|
||||||
|
)
|
||||||
|
|
||||||
|
signal.Notify(sigc)
|
||||||
|
|
||||||
|
createCommand := func(container *libcontainer.Container, console, rootfs, dataPath, init string, pipe *os.File, args []string) *exec.Cmd {
|
||||||
|
cmd = nsinit.DefaultCreateCommand(container, console, rootfs, dataPath, init, pipe, args)
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
startCallback := func() {
|
||||||
|
go func() {
|
||||||
|
for sig := range sigc {
|
||||||
|
cmd.Process.Signal(sig)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
return nsinit.Exec(container, term, "", dataPath, args, createCommand, startCallback)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue