2015-02-19 17:21:42 -08:00
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
|
2015-02-19 17:44:48 -08:00
|
|
|
dre "github.com/docker/docker/pkg/reexec"
|
2015-02-19 17:21:42 -08:00
|
|
|
)
|
|
|
|
|
2015-02-19 17:44:48 -08:00
|
|
|
type reexecCommand int
|
2015-02-19 17:21:42 -08:00
|
|
|
|
|
|
|
const (
|
2015-02-19 17:44:48 -08:00
|
|
|
reexecCreateNamespace reexecCommand = iota
|
|
|
|
reexecMoveInterface
|
2015-02-19 17:21:42 -08:00
|
|
|
)
|
|
|
|
|
2015-02-19 17:44:48 -08:00
|
|
|
var reexecCommands = map[reexecCommand]struct {
|
2015-02-19 17:21:42 -08:00
|
|
|
Key string
|
|
|
|
Entrypoint func()
|
|
|
|
}{
|
2015-02-19 17:44:48 -08:00
|
|
|
reexecCreateNamespace: {"netns-create", createNetworkNamespace},
|
|
|
|
reexecMoveInterface: {"netns-moveif", namespaceMoveInterface},
|
2015-02-19 17:21:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2015-02-19 17:44:48 -08:00
|
|
|
for _, reexecCmd := range reexecCommands {
|
|
|
|
dre.Register(reexecCmd.Key, reexecCmd.Entrypoint)
|
2015-02-19 17:21:42 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-19 17:44:48 -08:00
|
|
|
func reexec(command reexecCommand, params ...string) error {
|
|
|
|
reexecCommand, ok := reexecCommands[command]
|
2015-02-19 17:21:42 -08:00
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("unknown reexec command %q", command)
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd := &exec.Cmd{
|
2015-02-19 17:44:48 -08:00
|
|
|
Path: dre.Self(),
|
2015-02-19 17:21:42 -08:00
|
|
|
Args: append([]string{reexecCommand.Key}, params...),
|
|
|
|
Stdout: os.Stdout,
|
|
|
|
Stderr: os.Stderr,
|
|
|
|
}
|
|
|
|
return cmd.Run()
|
|
|
|
}
|