Skip to content

Commit a34bc2b

Browse files
committed
Update containerd with temp console path
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent d0b84ce commit a34bc2b

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

containerd-shim/process.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,11 @@ func (p *process) initializeIO(rootuid, rootgid int) (i *IO, err error) {
284284
return i, nil
285285
}
286286
func (p *process) Close() error {
287-
return p.stdio.Close()
287+
err := p.stdio.Close()
288+
if p.socket != nil {
289+
p.socket.Close()
290+
}
291+
return err
288292
}
289293

290294
type stdio struct {

containerd-shim/process_linux.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ package main
55
import (
66
"fmt"
77
"io"
8-
"os"
98
"os/exec"
10-
"path/filepath"
119
"syscall"
1210
"time"
1311

@@ -35,11 +33,7 @@ func (p *process) openIO() error {
3533
p.stdinCloser = stdinCloser
3634

3735
if p.state.Terminal {
38-
cwd, err := os.Getwd()
39-
if err != nil {
40-
return err
41-
}
42-
socket, err := runc.NewConsoleSocket(filepath.Join(cwd, "pty.sock"))
36+
socket, err := runc.NewTempConsoleSocket()
4337
if err != nil {
4438
return err
4539
}

hack/vendor.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ clone git github.com/vdemeester/shakers 24d7f1d6a71aa5d9cbe7390e4afb66b7eef9e1b3
3232
clone git github.com/go-check/check a625211d932a2a643d0d17352095f03fb7774663 https://github.com/cpuguy83/check.git
3333

3434
clone git github.com/crosbymichael/console 8ea0f623ee22736eec36b4ec87664b1d82cf9d15
35-
clone git github.com/crosbymichael/go-runc cfdb00928e8216dc80be58981368f56e8ba01f8e
35+
clone git github.com/crosbymichael/go-runc 980b32fc0fe2280022206962a536657010d9e072
3636

3737
# dependencies of docker/pkg/listeners
3838
clone git github.com/docker/go-connections v0.2.0

vendor/src/github.com/crosbymichael/go-runc/console.go

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ package runc
44

55
import (
66
"fmt"
7+
"io/ioutil"
78
"net"
9+
"os"
810
"path/filepath"
911

1012
"github.com/crosbymichael/console"
@@ -28,10 +30,33 @@ func NewConsoleSocket(path string) (*Socket, error) {
2830
}, nil
2931
}
3032

33+
// NewTempConsoleSocket returns a temp console socket for use with a container
34+
// On Close(), the socket is deleted
35+
func NewTempConsoleSocket() (*Socket, error) {
36+
dir, err := ioutil.TempDir("", "pty")
37+
if err != nil {
38+
return nil, err
39+
}
40+
abs, err := filepath.Abs(filepath.Join(dir, "pty.sock"))
41+
if err != nil {
42+
return nil, err
43+
}
44+
l, err := net.Listen("unix", abs)
45+
if err != nil {
46+
return nil, err
47+
}
48+
return &Socket{
49+
l: l,
50+
rmdir: true,
51+
path: abs,
52+
}, nil
53+
}
54+
3155
// Socket is a unix socket that accepts the pty master created by runc
3256
type Socket struct {
33-
path string
34-
l net.Listener
57+
path string
58+
rmdir bool
59+
l net.Listener
3560
}
3661

3762
// Path returns the path to the unix socket on disk
@@ -63,5 +88,11 @@ func (c *Socket) ReceiveMaster() (console.Console, error) {
6388

6489
// Close closes the unix socket
6590
func (c *Socket) Close() error {
66-
return c.l.Close()
91+
err := c.l.Close()
92+
if c.rmdir {
93+
if rerr := os.RemoveAll(filepath.Dir(c.path)); err == nil {
94+
err = rerr
95+
}
96+
}
97+
return err
6798
}

0 commit comments

Comments
 (0)