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

Commit c712fa0

Browse files
author
John Howard
committed
Windows: Initial compilation enablement
Signed-off-by: John Howard <[email protected]>
1 parent a37b2a4 commit c712fa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+281
-146
lines changed

Diff for: apparmor/gen.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package apparmor
24

35
import (

Diff for: apparmor/setup.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package apparmor
24

35
import (

Diff for: cgroups/cgroups.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package cgroups
24

35
import (

Diff for: cgroups/cgroups_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package cgroups
24

35
import (

Diff for: cgroups/cgroups_unsupported.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// +build !linux
2+
3+
package cgroups

Diff for: cgroups/fs/apply_raw.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/blkio.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/blkio_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/cpu.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/cpu_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/cpuacct.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/cpuset.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/cpuset_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/devices.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/devices_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/freezer.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/fs_unsupported.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// +build !linux
2+
3+
package fs

Diff for: cgroups/fs/hugetlb.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/memory.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/memory_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/perf_event.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/stats_util_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/util_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
/*
24
Utility for testing cgroup operations.
35

Diff for: cgroups/fs/utils.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/fs/utils_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package fs
24

35
import (

Diff for: cgroups/stats.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package cgroups
24

35
type ThrottlingData struct {

Diff for: cgroups/utils.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package cgroups
24

35
import (

Diff for: configs/cgroup.go

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ const (
88
Thawed FreezerState = "THAWED"
99
)
1010

11+
// TODO Windows: This can be factored out in the future as Cgroups are not
12+
// supported on the Windows platform.
13+
1114
type Cgroup struct {
1215
Name string `json:"name"`
1316

Diff for: configs/config.go

+3-48
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package configs
22

3-
import "fmt"
4-
53
type Rlimit struct {
64
Type int `json:"type"`
75
Hard uint64 `json:"hard"`
@@ -15,6 +13,9 @@ type IDMap struct {
1513
Size int `json:"size"`
1614
}
1715

16+
// TODO Windows. Many of these fields should be factored out into those parts
17+
// which are common across platforms, and those which are platform specific.
18+
1819
// Config defines configuration options for executing a process inside a contained environment.
1920
type Config struct {
2021
// NoPivotRoot will use MS_MOVE and a chroot to jail the process into the container's rootfs
@@ -104,49 +105,3 @@ type Config struct {
104105
// sysctl -w my.property.name value in Linux.
105106
SystemProperties map[string]string `json:"system_properties"`
106107
}
107-
108-
// Gets the root uid for the process on host which could be non-zero
109-
// when user namespaces are enabled.
110-
func (c Config) HostUID() (int, error) {
111-
if c.Namespaces.Contains(NEWUSER) {
112-
if c.UidMappings == nil {
113-
return -1, fmt.Errorf("User namespaces enabled, but no user mappings found.")
114-
}
115-
id, found := c.hostIDFromMapping(0, c.UidMappings)
116-
if !found {
117-
return -1, fmt.Errorf("User namespaces enabled, but no root user mapping found.")
118-
}
119-
return id, nil
120-
}
121-
// Return default root uid 0
122-
return 0, nil
123-
}
124-
125-
// Gets the root uid for the process on host which could be non-zero
126-
// when user namespaces are enabled.
127-
func (c Config) HostGID() (int, error) {
128-
if c.Namespaces.Contains(NEWUSER) {
129-
if c.GidMappings == nil {
130-
return -1, fmt.Errorf("User namespaces enabled, but no gid mappings found.")
131-
}
132-
id, found := c.hostIDFromMapping(0, c.GidMappings)
133-
if !found {
134-
return -1, fmt.Errorf("User namespaces enabled, but no root user mapping found.")
135-
}
136-
return id, nil
137-
}
138-
// Return default root uid 0
139-
return 0, nil
140-
}
141-
142-
// Utility function that gets a host ID for a container ID from user namespace map
143-
// if that ID is present in the map.
144-
func (c Config) hostIDFromMapping(containerID int, uMap []IDMap) (int, bool) {
145-
for _, m := range uMap {
146-
if (containerID >= m.ContainerID) && (containerID <= (m.ContainerID + m.Size - 1)) {
147-
hostID := m.HostID + (containerID - m.ContainerID)
148-
return hostID, true
149-
}
150-
}
151-
return -1, false
152-
}

Diff for: configs/config_linux.go

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package configs
2+
3+
import "fmt"
4+
5+
// Gets the root uid for the process on host which could be non-zero
6+
// when user namespaces are enabled.
7+
func (c Config) HostUID() (int, error) {
8+
if c.Namespaces.Contains(NEWUSER) {
9+
if c.UidMappings == nil {
10+
return -1, fmt.Errorf("User namespaces enabled, but no user mappings found.")
11+
}
12+
id, found := c.hostIDFromMapping(0, c.UidMappings)
13+
if !found {
14+
return -1, fmt.Errorf("User namespaces enabled, but no root user mapping found.")
15+
}
16+
return id, nil
17+
}
18+
// Return default root uid 0
19+
return 0, nil
20+
}
21+
22+
// Gets the root uid for the process on host which could be non-zero
23+
// when user namespaces are enabled.
24+
func (c Config) HostGID() (int, error) {
25+
if c.Namespaces.Contains(NEWUSER) {
26+
if c.GidMappings == nil {
27+
return -1, fmt.Errorf("User namespaces enabled, but no gid mappings found.")
28+
}
29+
id, found := c.hostIDFromMapping(0, c.GidMappings)
30+
if !found {
31+
return -1, fmt.Errorf("User namespaces enabled, but no root user mapping found.")
32+
}
33+
return id, nil
34+
}
35+
// Return default root uid 0
36+
return 0, nil
37+
}
38+
39+
// Utility function that gets a host ID for a container ID from user namespace map
40+
// if that ID is present in the map.
41+
func (c Config) hostIDFromMapping(containerID int, uMap []IDMap) (int, bool) {
42+
for _, m := range uMap {
43+
if (containerID >= m.ContainerID) && (containerID <= (m.ContainerID + m.Size - 1)) {
44+
hostID := m.HostID + (containerID - m.ContainerID)
45+
return hostID, true
46+
}
47+
}
48+
return -1, false
49+
}

Diff for: configs/device.go

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const (
99
Wildcard = -1
1010
)
1111

12+
// TODO Windows: This can be factored out in the future
13+
1214
type Device struct {
1315
// Device type, block, char, etc.
1416
Type rune `json:"type"`

Diff for: configs/device_defaults.go

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build linux
2+
13
package configs
24

35
var (

Diff for: configs/namespaces.go

-86
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,5 @@
11
package configs
22

3-
import "fmt"
4-
53
type NamespaceType string
64

7-
const (
8-
NEWNET NamespaceType = "NEWNET"
9-
NEWPID NamespaceType = "NEWPID"
10-
NEWNS NamespaceType = "NEWNS"
11-
NEWUTS NamespaceType = "NEWUTS"
12-
NEWIPC NamespaceType = "NEWIPC"
13-
NEWUSER NamespaceType = "NEWUSER"
14-
)
15-
16-
func NamespaceTypes() []NamespaceType {
17-
return []NamespaceType{
18-
NEWNET,
19-
NEWPID,
20-
NEWNS,
21-
NEWUTS,
22-
NEWIPC,
23-
NEWUSER,
24-
}
25-
}
26-
27-
// Namespace defines configuration for each namespace. It specifies an
28-
// alternate path that is able to be joined via setns.
29-
type Namespace struct {
30-
Type NamespaceType `json:"type"`
31-
Path string `json:"path"`
32-
}
33-
34-
func (n *Namespace) GetPath(pid int) string {
35-
if n.Path != "" {
36-
return n.Path
37-
}
38-
return fmt.Sprintf("/proc/%d/ns/%s", pid, n.file())
39-
}
40-
41-
func (n *Namespace) file() string {
42-
file := ""
43-
switch n.Type {
44-
case NEWNET:
45-
file = "net"
46-
case NEWNS:
47-
file = "mnt"
48-
case NEWPID:
49-
file = "pid"
50-
case NEWIPC:
51-
file = "ipc"
52-
case NEWUSER:
53-
file = "user"
54-
case NEWUTS:
55-
file = "uts"
56-
}
57-
return file
58-
}
59-
605
type Namespaces []Namespace
61-
62-
func (n *Namespaces) Remove(t NamespaceType) bool {
63-
i := n.index(t)
64-
if i == -1 {
65-
return false
66-
}
67-
*n = append((*n)[:i], (*n)[i+1:]...)
68-
return true
69-
}
70-
71-
func (n *Namespaces) Add(t NamespaceType, path string) {
72-
i := n.index(t)
73-
if i == -1 {
74-
*n = append(*n, Namespace{Type: t, Path: path})
75-
return
76-
}
77-
(*n)[i].Path = path
78-
}
79-
80-
func (n *Namespaces) index(t NamespaceType) int {
81-
for i, ns := range *n {
82-
if ns.Type == t {
83-
return i
84-
}
85-
}
86-
return -1
87-
}
88-
89-
func (n *Namespaces) Contains(t NamespaceType) bool {
90-
return n.index(t) != -1
91-
}

0 commit comments

Comments
 (0)