Skip to content

Commit

Permalink
attach: fix attach when cuid is too long
Browse files Browse the repository at this point in the history
conmon creates a symlink to avoid using a too long UNIX path.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1641800

There is still one issue when the path length of the symlink has the
same length of the attach socket parent directory since conmon fails
to create the symlink, but that must be addressed in conmon first.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
  • Loading branch information
giuseppe committed Oct 26, 2018
1 parent f6e7807 commit 3cd27a6
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions libpod/container_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ import (
"k8s.io/client-go/tools/remotecommand"
)

//#include <sys/un.h>
// extern int unix_path_length(){struct sockaddr_un addr; return sizeof(addr.sun_path) - 1;}
import "C"

/* Sync with stdpipe_t in conmon.c */
const (
AttachPipeStdin = 1
Expand Down Expand Up @@ -81,11 +85,15 @@ func (c *Container) attachContainerSocket(resize <-chan remotecommand.TerminalSi
logrus.Warnf("Failed to write to control file to resize terminal: %v", err)
}
})
logrus.Debug("connecting to socket ", c.AttachSocketPath())

conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: c.AttachSocketPath(), Net: "unixpacket"})
maxUnixLength := int(C.unix_path_length())
socketPath := c.AttachSocketPath()[0:maxUnixLength]

logrus.Debug("connecting to socket ", socketPath)

conn, err := net.DialUnix("unixpacket", nil, &net.UnixAddr{Name: socketPath, Net: "unixpacket"})
if err != nil {
return errors.Wrapf(err, "failed to connect to container's attach socket: %v", c.AttachSocketPath())
return errors.Wrapf(err, "failed to connect to container's attach socket: %v", socketPath)
}
defer conn.Close()

Expand Down

0 comments on commit 3cd27a6

Please sign in to comment.