Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit c2403c3

Browse files
committed
Add GetPath on namespace config
Signed-off-by: Michael Crosby <[email protected]>
1 parent 91a3f16 commit c2403c3

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

configs/namespaces.go

+27
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package configs
22

33
import (
4+
"fmt"
45
"syscall"
56
)
67

@@ -26,6 +27,32 @@ func (n *Namespace) Syscall() int {
2627
return namespaceInfo[n.Type]
2728
}
2829

30+
func (n *Namespace) GetPath(pid int) string {
31+
if n.Path != "" {
32+
return n.Path
33+
}
34+
return fmt.Sprintf("/proc/%d/ns/%s", pid, n.file())
35+
}
36+
37+
func (n *Namespace) file() string {
38+
file := ""
39+
switch n.Type {
40+
case NEWNET:
41+
file = "net"
42+
case NEWNS:
43+
file = "mnt"
44+
case NEWPID:
45+
file = "pid"
46+
case NEWIPC:
47+
file = "ipc"
48+
case NEWUSER:
49+
file = "user"
50+
case NEWUTS:
51+
file = "uts"
52+
}
53+
return file
54+
}
55+
2956
type Namespaces []Namespace
3057

3158
func (n *Namespaces) Remove(t NamespaceType) bool {

console.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package libcontainer
22

33
import "io"
44

5-
// Console represents a psuedo TTY.
5+
// Console represents a pseudo TTY.
66
type Console interface {
77
io.ReadWriter
88
io.Closer

linux_container.go

+1-20
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,7 @@ func (c *linuxContainer) State() (*State, error) {
7272
NamespacePaths: make(map[string]string),
7373
}
7474
for _, ns := range c.config.Namespaces {
75-
if ns.Path != "" {
76-
state.NamespacePaths[string(ns.Type)] = ns.Path
77-
continue
78-
}
79-
file := ""
80-
switch ns.Type {
81-
case configs.NEWNET:
82-
file = "net"
83-
case configs.NEWNS:
84-
file = "mnt"
85-
case configs.NEWPID:
86-
file = "pid"
87-
case configs.NEWIPC:
88-
file = "ipc"
89-
case configs.NEWUSER:
90-
file = "user"
91-
case configs.NEWUTS:
92-
file = "uts"
93-
}
94-
state.NamespacePaths[string(ns.Type)] = fmt.Sprintf("/proc/%d/ns/%s", c.initProcess.pid(), file)
75+
state.NamespacePaths[string(ns.Type)] = ns.GetPath(c.initProcess.pid())
9576
}
9677
return state, nil
9778
}

nsinit/config.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
)
1414

1515
var createFlags = []cli.Flag{
16-
cli.IntFlag{Name: "parent-death-signal", Usage: "set the signal that will be delivered to the process incase the parent dies"},
16+
cli.IntFlag{Name: "parent-death-signal", Usage: "set the signal that will be delivered to the process in case the parent dies"},
1717
cli.BoolFlag{Name: "read-only", Usage: "set the container's rootfs as read-only"},
1818
cli.StringSliceFlag{Name: "bind", Value: &cli.StringSlice{}, Usage: "add bind mounts to the container"},
1919
cli.StringSliceFlag{Name: "tmpfs", Value: &cli.StringSlice{}, Usage: "add tmpfs mounts to the container"},

0 commit comments

Comments
 (0)