libnetwork: don't register "libnetwork-setkey" re-exec on non-unix

It's a no-op on Windows and other non-Linux, non-FreeBSD platforms,
so there's no need to register the re-exec.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-04-28 10:56:38 +02:00
parent 881fff1a2f
commit a813d7e961
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
4 changed files with 24 additions and 59 deletions

View file

@ -1,12 +0,0 @@
package libnetwork
import "github.com/docker/docker/pkg/reexec"
type setKeyData struct {
ContainerID string
Key string
}
func init() {
reexec.Register("libnetwork-setkey", processSetKeyReexec)
}

View file

@ -13,6 +13,7 @@ import (
"path/filepath"
"github.com/docker/docker/libnetwork/types"
"github.com/docker/docker/pkg/reexec"
"github.com/docker/docker/pkg/stringid"
"github.com/opencontainers/runtime-spec/specs-go"
"github.com/sirupsen/logrus"
@ -24,6 +25,16 @@ const (
success = "success"
)
func init() {
// TODO(thaJeztah): should this actually be registered on FreeBSD, or only on Linux?
reexec.Register("libnetwork-setkey", processSetKeyReexec)
}
type setKeyData struct {
ContainerID string
Key string
}
// processSetKeyReexec is a private function that must be called only on an reexec path
// It expects 3 args { [0] = "libnetwork-setkey", [1] = <container-id>, [2] = <short-controller-id> }
// It also expects specs.State as a json string in <stdin>
@ -65,7 +76,8 @@ func setKey() error {
func SetExternalKey(shortCtlrID string, containerID string, key string, execRoot string) error {
keyData := setKeyData{
ContainerID: containerID,
Key: key}
Key: key,
}
uds := filepath.Join(execRoot, execSubdir, shortCtlrID+".sock")
c, err := net.Dial("unix", uds)

View file

@ -0,0 +1,11 @@
//go:build !linux && !freebsd
// +build !linux,!freebsd
package libnetwork
// no-op on non linux systems
func (c *Controller) startExternalKeyListener() error {
return nil
}
func (c *Controller) stopExternalKeyListener() {}

View file

@ -1,46 +0,0 @@
//go:build windows
// +build windows
package libnetwork
import (
"io"
"net"
"github.com/docker/docker/libnetwork/types"
)
// processSetKeyReexec is a private function that must be called only on an reexec path
// It expects 3 args { [0] = "libnetwork-setkey", [1] = <container-id>, [2] = <controller-id> }
// It also expects configs.HookState as a json string in <stdin>
// Refer to https://github.com/opencontainers/runc/pull/160/ for more information
func processSetKeyReexec() {
}
// SetExternalKey provides a convenient way to set an External key to a sandbox
func SetExternalKey(controllerID string, containerID string, key string) error {
return types.NotImplementedErrorf("SetExternalKey isn't supported on non linux systems")
}
func sendKey(c net.Conn, data setKeyData) error {
return types.NotImplementedErrorf("sendKey isn't supported on non linux systems")
}
func processReturn(r io.Reader) error {
return types.NotImplementedErrorf("processReturn isn't supported on non linux systems")
}
// no-op on non linux systems
func (c *Controller) startExternalKeyListener() error {
return nil
}
func (c *Controller) acceptClientConnections(sock string, l net.Listener) {
}
func (c *Controller) processExternalKey(conn net.Conn) error {
return types.NotImplementedErrorf("processExternalKey isn't supported on non linux systems")
}
func (c *Controller) stopExternalKeyListener() {
}