Skip to content

Commit 0025177

Browse files
authored
Merge pull request #2443 from Rid/shorten-setkey-id
Shorten controller ID in exec-root to not hit UNIX_PATH_MAX
2 parents 10c7fb6 + 4cee383 commit 0025177

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

sandbox_externalkey_unix.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"os"
1313
"path/filepath"
1414

15+
"github.com/docker/docker/pkg/stringid"
1516
"github.com/docker/libnetwork/types"
1617
"github.com/opencontainers/runtime-spec/specs-go"
1718
"github.com/sirupsen/logrus"
@@ -24,7 +25,7 @@ const (
2425
)
2526

2627
// processSetKeyReexec is a private function that must be called only on an reexec path
27-
// It expects 3 args { [0] = "libnetwork-setkey", [1] = <container-id>, [2] = <controller-id> }
28+
// It expects 3 args { [0] = "libnetwork-setkey", [1] = <container-id>, [2] = <short-controller-id> }
2829
// It also expects specs.State as a json string in <stdin>
2930
// Refer to https://github.com/opencontainers/runc/pull/160/ for more information
3031
// The docker exec-root can be specified as "-exec-root" flag. The default value is "/run/docker".
@@ -41,14 +42,14 @@ func processSetKeyReexec() {
4142
execRoot := flag.String("exec-root", defaultExecRoot, "docker exec root")
4243
flag.Parse()
4344

44-
// expecting 3 os.Args {[0]="libnetwork-setkey", [1]=<container-id>, [2]=<controller-id> }
45+
// expecting 3 os.Args {[0]="libnetwork-setkey", [1]=<container-id>, [2]=<short-controller-id> }
4546
// (i.e. expecting 2 flag.Args())
4647
args := flag.Args()
4748
if len(args) < 2 {
4849
err = fmt.Errorf("Re-exec expects 2 args (after parsing flags), received : %d", len(args))
4950
return
5051
}
51-
containerID, controllerID := args[0], args[1]
52+
containerID, shortCtlrID := args[0], args[1]
5253

5354
// We expect specs.State as a json string in <stdin>
5455
stateBuf, err := ioutil.ReadAll(os.Stdin)
@@ -60,16 +61,16 @@ func processSetKeyReexec() {
6061
return
6162
}
6263

63-
err = SetExternalKey(controllerID, containerID, fmt.Sprintf("/proc/%d/ns/net", state.Pid), *execRoot)
64+
err = SetExternalKey(shortCtlrID, containerID, fmt.Sprintf("/proc/%d/ns/net", state.Pid), *execRoot)
6465
}
6566

6667
// SetExternalKey provides a convenient way to set an External key to a sandbox
67-
func SetExternalKey(controllerID string, containerID string, key string, execRoot string) error {
68+
func SetExternalKey(shortCtlrID string, containerID string, key string, execRoot string) error {
6869
keyData := setKeyData{
6970
ContainerID: containerID,
7071
Key: key}
7172

72-
uds := filepath.Join(execRoot, execSubdir, controllerID+".sock")
73+
uds := filepath.Join(execRoot, execSubdir, shortCtlrID+".sock")
7374
c, err := net.Dial("unix", uds)
7475
if err != nil {
7576
return err
@@ -120,7 +121,8 @@ func (c *controller) startExternalKeyListener() error {
120121
if err := os.MkdirAll(udsBase, 0600); err != nil {
121122
return err
122123
}
123-
uds := filepath.Join(udsBase, c.id+".sock")
124+
shortCtlrID := stringid.TruncateID(c.id)
125+
uds := filepath.Join(udsBase, shortCtlrID+".sock")
124126
l, err := net.Listen("unix", uds)
125127
if err != nil {
126128
return err

0 commit comments

Comments
 (0)