Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
07bd42a1
Commit
07bd42a1
authored
Oct 10, 2016
by
derekwaynecarr
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update libcontainer,gocapability,cadvisor
parent
160adc38
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
40 changed files
with
461 additions
and
327 deletions
+461
-327
Godeps.json
Godeps/Godeps.json
+0
-0
config.go
vendor/github.com/google/cadvisor/collector/config.go
+10
-10
generic_collector.go
...github.com/google/cadvisor/collector/generic_collector.go
+9
-9
prometheus_collector.go
...hub.com/google/cadvisor/collector/prometheus_collector.go
+131
-84
helpers.go
...hub.com/google/cadvisor/container/libcontainer/helpers.go
+1
-1
handler.go
vendor/github.com/google/cadvisor/container/rkt/handler.go
+1
-1
container.go
vendor/github.com/google/cadvisor/info/v1/container.go
+12
-12
metric.go
vendor/github.com/google/cadvisor/info/v1/metric.go
+3
-3
assets.go
vendor/github.com/google/cadvisor/pages/static/assets.go
+0
-0
templates.go
vendor/github.com/google/cadvisor/pages/templates.go
+1
-1
azure.go
vendor/github.com/google/cadvisor/utils/cloudinfo/azure.go
+1
-1
cloudinfo.go
...r/github.com/google/cadvisor/utils/cloudinfo/cloudinfo.go
+1
-1
tail.go
vendor/github.com/google/cadvisor/utils/tail/tail.go
+1
-1
README.md
vendor/github.com/opencontainers/runc/libcontainer/README.md
+2
-1
SPEC.md
vendor/github.com/opencontainers/runc/libcontainer/SPEC.md
+0
-1
capabilities_linux.go
...om/opencontainers/runc/libcontainer/capabilities_linux.go
+1
-1
cgroups.go
...b.com/opencontainers/runc/libcontainer/cgroups/cgroups.go
+1
-1
apply_raw.go
.../opencontainers/runc/libcontainer/cgroups/fs/apply_raw.go
+11
-40
cpu.go
...ub.com/opencontainers/runc/libcontainer/cgroups/fs/cpu.go
+41
-10
memory.go
...com/opencontainers/runc/libcontainer/cgroups/fs/memory.go
+9
-12
apply_systemd.go
...ainers/runc/libcontainer/cgroups/systemd/apply_systemd.go
+60
-11
utils.go
...hub.com/opencontainers/runc/libcontainer/cgroups/utils.go
+10
-6
cgroup_unix.go
...m/opencontainers/runc/libcontainer/configs/cgroup_unix.go
+1
-1
config.go
...ub.com/opencontainers/runc/libcontainer/configs/config.go
+24
-15
device_defaults.go
...encontainers/runc/libcontainer/configs/device_defaults.go
+1
-15
container.go
.../github.com/opencontainers/runc/libcontainer/container.go
+8
-8
container_linux.go
...b.com/opencontainers/runc/libcontainer/container_linux.go
+9
-9
factory_linux.go
...hub.com/opencontainers/runc/libcontainer/factory_linux.go
+15
-40
generic_error.go
...hub.com/opencontainers/runc/libcontainer/generic_error.go
+0
-3
init_linux.go
...github.com/opencontainers/runc/libcontainer/init_linux.go
+1
-1
label_selinux.go
...m/opencontainers/runc/libcontainer/label/label_selinux.go
+5
-2
process_linux.go
...hub.com/opencontainers/runc/libcontainer/process_linux.go
+2
-2
rootfs_linux.go
...thub.com/opencontainers/runc/libcontainer/rootfs_linux.go
+13
-8
standard_init_linux.go
...m/opencontainers/runc/libcontainer/standard_init_linux.go
+1
-1
syscall_linux_386.go
...ncontainers/runc/libcontainer/system/syscall_linux_386.go
+1
-1
utils.go
...ithub.com/opencontainers/runc/libcontainer/utils/utils.go
+5
-0
capability.go
...r/github.com/syndtr/gocapability/capability/capability.go
+10
-10
capability_linux.go
...ub.com/syndtr/gocapability/capability/capability_linux.go
+46
-4
enum.go
vendor/github.com/syndtr/gocapability/capability/enum.go
+4
-0
syscall_linux.go
...ithub.com/syndtr/gocapability/capability/syscall_linux.go
+9
-0
No files found.
Godeps/Godeps.json
View file @
07bd42a1
This diff is collapsed.
Click to expand it.
vendor/github.com/google/cadvisor/collector/config.go
View file @
07bd42a1
...
@@ -22,43 +22,43 @@ import (
...
@@ -22,43 +22,43 @@ import (
)
)
type
Config
struct
{
type
Config
struct
{
//the endpoint to hit to scrape metrics
//
the endpoint to hit to scrape metrics
Endpoint
EndpointConfig
`json:"endpoint"`
Endpoint
EndpointConfig
`json:"endpoint"`
//holds information about different metrics that can be collected
//
holds information about different metrics that can be collected
MetricsConfig
[]
MetricConfig
`json:"metrics_config"`
MetricsConfig
[]
MetricConfig
`json:"metrics_config"`
}
}
// metricConfig holds information extracted from the config file about a metric
// metricConfig holds information extracted from the config file about a metric
type
MetricConfig
struct
{
type
MetricConfig
struct
{
//the name of the metric
//
the name of the metric
Name
string
`json:"name"`
Name
string
`json:"name"`
//enum type for the metric type
//
enum type for the metric type
MetricType
v1
.
MetricType
`json:"metric_type"`
MetricType
v1
.
MetricType
`json:"metric_type"`
// metric units to display on UI and in storage (eg: MB, cores)
// metric units to display on UI and in storage (eg: MB, cores)
// this is only used for display.
// this is only used for display.
Units
string
`json:"units"`
Units
string
`json:"units"`
//data type of the metric (eg: int, float)
//
data type of the metric (eg: int, float)
DataType
v1
.
DataType
`json:"data_type"`
DataType
v1
.
DataType
`json:"data_type"`
//the frequency at which the metric should be collected
//
the frequency at which the metric should be collected
PollingFrequency
time
.
Duration
`json:"polling_frequency"`
PollingFrequency
time
.
Duration
`json:"polling_frequency"`
//the regular expression that can be used to extract the metric
//
the regular expression that can be used to extract the metric
Regex
string
`json:"regex"`
Regex
string
`json:"regex"`
}
}
type
Prometheus
struct
{
type
Prometheus
struct
{
//the endpoint to hit to scrape metrics
//
the endpoint to hit to scrape metrics
Endpoint
EndpointConfig
`json:"endpoint"`
Endpoint
EndpointConfig
`json:"endpoint"`
//the frequency at which metrics should be collected
//
the frequency at which metrics should be collected
PollingFrequency
time
.
Duration
`json:"polling_frequency"`
PollingFrequency
time
.
Duration
`json:"polling_frequency"`
//holds names of different metrics that can be collected
//
holds names of different metrics that can be collected
MetricsConfig
[]
string
`json:"metrics_config"`
MetricsConfig
[]
string
`json:"metrics_config"`
}
}
...
...
vendor/github.com/google/cadvisor/collector/generic_collector.go
View file @
07bd42a1
...
@@ -29,13 +29,13 @@ import (
...
@@ -29,13 +29,13 @@ import (
)
)
type
GenericCollector
struct
{
type
GenericCollector
struct
{
//name of the collector
//
name of the collector
name
string
name
string
//holds information extracted from the config file for a collector
//
holds information extracted from the config file for a collector
configFile
Config
configFile
Config
//holds information necessary to extract metrics
//
holds information necessary to extract metrics
info
*
collectorInfo
info
*
collectorInfo
// The Http client to use when connecting to metric endpoints
// The Http client to use when connecting to metric endpoints
...
@@ -43,10 +43,10 @@ type GenericCollector struct {
...
@@ -43,10 +43,10 @@ type GenericCollector struct {
}
}
type
collectorInfo
struct
{
type
collectorInfo
struct
{
//minimum polling frequency among all metrics
//
minimum polling frequency among all metrics
minPollingFrequency
time
.
Duration
minPollingFrequency
time
.
Duration
//regular expresssions for all metrics
//
regular expresssions for all metrics
regexps
[]
*
regexp
.
Regexp
regexps
[]
*
regexp
.
Regexp
// Limit for the number of srcaped metrics. If the count is higher,
// Limit for the number of srcaped metrics. If the count is higher,
...
@@ -54,7 +54,7 @@ type collectorInfo struct {
...
@@ -54,7 +54,7 @@ type collectorInfo struct {
metricCountLimit
int
metricCountLimit
int
}
}
//Returns a new collector using the information extracted from the configfile
//
Returns a new collector using the information extracted from the configfile
func
NewCollector
(
collectorName
string
,
configFile
[]
byte
,
metricCountLimit
int
,
containerHandler
container
.
ContainerHandler
,
httpClient
*
http
.
Client
)
(
*
GenericCollector
,
error
)
{
func
NewCollector
(
collectorName
string
,
configFile
[]
byte
,
metricCountLimit
int
,
containerHandler
container
.
ContainerHandler
,
httpClient
*
http
.
Client
)
(
*
GenericCollector
,
error
)
{
var
configInJSON
Config
var
configInJSON
Config
err
:=
json
.
Unmarshal
(
configFile
,
&
configInJSON
)
err
:=
json
.
Unmarshal
(
configFile
,
&
configInJSON
)
...
@@ -64,7 +64,7 @@ func NewCollector(collectorName string, configFile []byte, metricCountLimit int,
...
@@ -64,7 +64,7 @@ func NewCollector(collectorName string, configFile []byte, metricCountLimit int,
configInJSON
.
Endpoint
.
configure
(
containerHandler
)
configInJSON
.
Endpoint
.
configure
(
containerHandler
)
//TODO : Add checks for validity of config file (eg : Accurate JSON fields)
//
TODO : Add checks for validity of config file (eg : Accurate JSON fields)
if
len
(
configInJSON
.
MetricsConfig
)
==
0
{
if
len
(
configInJSON
.
MetricsConfig
)
==
0
{
return
nil
,
fmt
.
Errorf
(
"No metrics provided in config"
)
return
nil
,
fmt
.
Errorf
(
"No metrics provided in config"
)
...
@@ -109,7 +109,7 @@ func NewCollector(collectorName string, configFile []byte, metricCountLimit int,
...
@@ -109,7 +109,7 @@ func NewCollector(collectorName string, configFile []byte, metricCountLimit int,
},
nil
},
nil
}
}
//Returns name of the collector
//
Returns name of the collector
func
(
collector
*
GenericCollector
)
Name
()
string
{
func
(
collector
*
GenericCollector
)
Name
()
string
{
return
collector
.
name
return
collector
.
name
}
}
...
@@ -132,7 +132,7 @@ func (collector *GenericCollector) GetSpec() []v1.MetricSpec {
...
@@ -132,7 +132,7 @@ func (collector *GenericCollector) GetSpec() []v1.MetricSpec {
return
specs
return
specs
}
}
//Returns collected metrics and the next collection time of the collector
//
Returns collected metrics and the next collection time of the collector
func
(
collector
*
GenericCollector
)
Collect
(
metrics
map
[
string
][]
v1
.
MetricVal
)
(
time
.
Time
,
map
[
string
][]
v1
.
MetricVal
,
error
)
{
func
(
collector
*
GenericCollector
)
Collect
(
metrics
map
[
string
][]
v1
.
MetricVal
)
(
time
.
Time
,
map
[
string
][]
v1
.
MetricVal
,
error
)
{
currentTime
:=
time
.
Now
()
currentTime
:=
time
.
Now
()
nextCollectionTime
:=
currentTime
.
Add
(
time
.
Duration
(
collector
.
info
.
minPollingFrequency
))
nextCollectionTime
:=
currentTime
.
Add
(
time
.
Duration
(
collector
.
info
.
minPollingFrequency
))
...
...
vendor/github.com/google/cadvisor/collector/prometheus_collector.go
View file @
07bd42a1
...
@@ -15,27 +15,30 @@
...
@@ -15,27 +15,30 @@
package
collector
package
collector
import
(
import
(
"bytes"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"io/ioutil"
"io"
"math"
"net/http"
"net/http"
"strconv"
"sort"
"strings"
"time"
"time"
rawmodel
"github.com/prometheus/client_model/go"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/model"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/container"
"github.com/google/cadvisor/info/v1"
"github.com/google/cadvisor/info/v1"
)
)
type
PrometheusCollector
struct
{
type
PrometheusCollector
struct
{
//name of the collector
//
name of the collector
name
string
name
string
//rate at which metrics are collected
//
rate at which metrics are collected
pollingFrequency
time
.
Duration
pollingFrequency
time
.
Duration
//holds information extracted from the config file for a collector
//
holds information extracted from the config file for a collector
configFile
Prometheus
configFile
Prometheus
// the metrics to gather (uses a map as a set)
// the metrics to gather (uses a map as a set)
...
@@ -49,7 +52,7 @@ type PrometheusCollector struct {
...
@@ -49,7 +52,7 @@ type PrometheusCollector struct {
httpClient
*
http
.
Client
httpClient
*
http
.
Client
}
}
//Returns a new collector using the information extracted from the configfile
//
Returns a new collector using the information extracted from the configfile
func
NewPrometheusCollector
(
collectorName
string
,
configFile
[]
byte
,
metricCountLimit
int
,
containerHandler
container
.
ContainerHandler
,
httpClient
*
http
.
Client
)
(
*
PrometheusCollector
,
error
)
{
func
NewPrometheusCollector
(
collectorName
string
,
configFile
[]
byte
,
metricCountLimit
int
,
containerHandler
container
.
ContainerHandler
,
httpClient
*
http
.
Client
)
(
*
PrometheusCollector
,
error
)
{
var
configInJSON
Prometheus
var
configInJSON
Prometheus
err
:=
json
.
Unmarshal
(
configFile
,
&
configInJSON
)
err
:=
json
.
Unmarshal
(
configFile
,
&
configInJSON
)
...
@@ -84,7 +87,7 @@ func NewPrometheusCollector(collectorName string, configFile []byte, metricCount
...
@@ -84,7 +87,7 @@ func NewPrometheusCollector(collectorName string, configFile []byte, metricCount
return
nil
,
fmt
.
Errorf
(
"Too many metrics defined: %d limit %d"
,
len
(
configInJSON
.
MetricsConfig
),
metricCountLimit
)
return
nil
,
fmt
.
Errorf
(
"Too many metrics defined: %d limit %d"
,
len
(
configInJSON
.
MetricsConfig
),
metricCountLimit
)
}
}
//TODO : Add checks for validity of config file (eg : Accurate JSON fields)
//
TODO : Add checks for validity of config file (eg : Accurate JSON fields)
return
&
PrometheusCollector
{
return
&
PrometheusCollector
{
name
:
collectorName
,
name
:
collectorName
,
pollingFrequency
:
minPollingFrequency
,
pollingFrequency
:
minPollingFrequency
,
...
@@ -95,68 +98,110 @@ func NewPrometheusCollector(collectorName string, configFile []byte, metricCount
...
@@ -95,68 +98,110 @@ func NewPrometheusCollector(collectorName string, configFile []byte, metricCount
},
nil
},
nil
}
}
//Returns name of the collector
//
Returns name of the collector
func
(
collector
*
PrometheusCollector
)
Name
()
string
{
func
(
collector
*
PrometheusCollector
)
Name
()
string
{
return
collector
.
name
return
collector
.
name
}
}
func
getMetricData
(
line
string
)
string
{
fields
:=
strings
.
Fields
(
line
)
data
:=
fields
[
3
]
if
len
(
fields
)
>
4
{
for
i
:=
range
fields
{
if
i
>
3
{
data
=
data
+
"_"
+
fields
[
i
]
}
}
}
return
strings
.
TrimSpace
(
data
)
}
func
(
collector
*
PrometheusCollector
)
GetSpec
()
[]
v1
.
MetricSpec
{
func
(
collector
*
PrometheusCollector
)
GetSpec
()
[]
v1
.
MetricSpec
{
specs
:=
[]
v1
.
MetricSpec
{}
response
,
err
:=
collector
.
httpClient
.
Get
(
collector
.
configFile
.
Endpoint
.
URL
)
response
,
err
:=
collector
.
httpClient
.
Get
(
collector
.
configFile
.
Endpoint
.
URL
)
if
err
!=
nil
{
if
err
!=
nil
{
return
specs
return
nil
}
}
defer
response
.
Body
.
Close
()
defer
response
.
Body
.
Close
()
pageContent
,
err
:=
ioutil
.
ReadAll
(
response
.
Body
)
if
response
.
StatusCode
!=
http
.
StatusOK
{
if
err
!=
nil
{
return
nil
return
specs
}
}
lines
:=
strings
.
Split
(
string
(
pageContent
),
"
\n
"
)
dec
:=
expfmt
.
NewDecoder
(
response
.
Body
,
expfmt
.
ResponseFormat
(
response
.
Header
))
lineCount
:=
len
(
lines
)
for
i
,
line
:=
range
lines
{
if
strings
.
HasPrefix
(
line
,
"# HELP"
)
{
if
i
+
2
>=
lineCount
{
break
}
stopIndex
:=
strings
.
IndexAny
(
lines
[
i
+
2
],
"{ "
)
var
specs
[]
v1
.
MetricSpec
if
stopIndex
==
-
1
{
continue
}
name
:=
strings
.
TrimSpace
(
lines
[
i
+
2
][
0
:
stopIndex
])
for
{
if
_
,
ok
:=
collector
.
metricsSet
[
name
];
collector
.
metricsSet
!=
nil
&&
!
ok
{
d
:=
rawmodel
.
MetricFamily
{}
continue
if
err
=
dec
.
Decode
(
&
d
);
err
!=
nil
{
}
break
spec
:=
v1
.
MetricSpec
{
Name
:
name
,
Type
:
v1
.
MetricType
(
getMetricData
(
lines
[
i
+
1
])),
Format
:
"float"
,
Units
:
getMetricData
(
lines
[
i
]),
}
specs
=
append
(
specs
,
spec
)
}
}
name
:=
d
.
GetName
()
if
len
(
name
)
==
0
{
continue
}
// If metrics to collect is specified, skip any metrics not in the list to collect.
if
_
,
ok
:=
collector
.
metricsSet
[
name
];
collector
.
metricsSet
!=
nil
&&
!
ok
{
continue
}
spec
:=
v1
.
MetricSpec
{
Name
:
name
,
Type
:
metricType
(
d
.
GetType
()),
Format
:
v1
.
FloatType
,
}
specs
=
append
(
specs
,
spec
)
}
}
if
err
!=
nil
&&
err
!=
io
.
EOF
{
return
nil
}
return
specs
return
specs
}
}
//Returns collected metrics and the next collection time of the collector
// metricType converts Prometheus metric type to cadvisor metric type.
// If there is no mapping then just return the name of the Prometheus metric type.
func
metricType
(
t
rawmodel
.
MetricType
)
v1
.
MetricType
{
switch
t
{
case
rawmodel
.
MetricType_COUNTER
:
return
v1
.
MetricCumulative
case
rawmodel
.
MetricType_GAUGE
:
return
v1
.
MetricGauge
default
:
return
v1
.
MetricType
(
t
.
String
())
}
}
type
prometheusLabels
[]
*
rawmodel
.
LabelPair
func
labelSetToLabelPairs
(
labels
model
.
Metric
)
prometheusLabels
{
var
promLabels
prometheusLabels
for
k
,
v
:=
range
labels
{
name
:=
string
(
k
)
value
:=
string
(
v
)
promLabels
=
append
(
promLabels
,
&
rawmodel
.
LabelPair
{
Name
:
&
name
,
Value
:
&
value
})
}
return
promLabels
}
func
(
s
prometheusLabels
)
Len
()
int
{
return
len
(
s
)
}
func
(
s
prometheusLabels
)
Swap
(
i
,
j
int
)
{
s
[
i
],
s
[
j
]
=
s
[
j
],
s
[
i
]
}
// ByName implements sort.Interface by providing Less and using the Len and
// Swap methods of the embedded PrometheusLabels value.
type
byName
struct
{
prometheusLabels
}
func
(
s
byName
)
Less
(
i
,
j
int
)
bool
{
return
s
.
prometheusLabels
[
i
]
.
GetName
()
<
s
.
prometheusLabels
[
j
]
.
GetName
()
}
func
prometheusLabelSetToCadvisorLabel
(
promLabels
model
.
Metric
)
string
{
labels
:=
labelSetToLabelPairs
(
promLabels
)
sort
.
Sort
(
byName
{
labels
})
var
b
bytes
.
Buffer
for
i
,
l
:=
range
labels
{
if
i
>
0
{
b
.
WriteString
(
"
\xff
"
)
}
b
.
WriteString
(
l
.
GetName
())
b
.
WriteString
(
"="
)
b
.
WriteString
(
l
.
GetValue
())
}
return
string
(
b
.
Bytes
())
}
// Returns collected metrics and the next collection time of the collector
func
(
collector
*
PrometheusCollector
)
Collect
(
metrics
map
[
string
][]
v1
.
MetricVal
)
(
time
.
Time
,
map
[
string
][]
v1
.
MetricVal
,
error
)
{
func
(
collector
*
PrometheusCollector
)
Collect
(
metrics
map
[
string
][]
v1
.
MetricVal
)
(
time
.
Time
,
map
[
string
][]
v1
.
MetricVal
,
error
)
{
currentTime
:=
time
.
Now
()
currentTime
:=
time
.
Now
()
nextCollectionTime
:=
currentTime
.
Add
(
time
.
Duration
(
collector
.
pollingFrequency
))
nextCollectionTime
:=
currentTime
.
Add
(
time
.
Duration
(
collector
.
pollingFrequency
))
...
@@ -168,59 +213,61 @@ func (collector *PrometheusCollector) Collect(metrics map[string][]v1.MetricVal)
...
@@ -168,59 +213,61 @@ func (collector *PrometheusCollector) Collect(metrics map[string][]v1.MetricVal)
}
}
defer
response
.
Body
.
Close
()
defer
response
.
Body
.
Close
()
pageContent
,
err
:=
ioutil
.
ReadAll
(
response
.
Body
)
if
response
.
StatusCode
!=
http
.
StatusOK
{
if
err
!=
nil
{
return
nextCollectionTime
,
nil
,
fmt
.
Errorf
(
"server returned HTTP status %s"
,
response
.
Status
)
return
nextCollectionTime
,
nil
,
err
}
}
var
errorSlice
[]
error
sdec
:=
expfmt
.
SampleDecoder
{
lines
:=
strings
.
Split
(
string
(
pageContent
),
"
\n
"
)
Dec
:
expfmt
.
NewDecoder
(
response
.
Body
,
expfmt
.
ResponseFormat
(
response
.
Header
)),
Opts
:
&
expfmt
.
DecodeOptions
{
newMetrics
:=
make
(
map
[
string
][]
v1
.
MetricVal
)
Timestamp
:
model
.
TimeFromUnixNano
(
currentTime
.
UnixNano
()),
},
}
for
_
,
line
:=
range
lines
{
var
(
if
line
==
""
{
// 50 is chosen as a reasonable guesstimate at a number of metrics we can
// expect from virtually any endpoint to try to save allocations.
decSamples
=
make
(
model
.
Vector
,
0
,
50
)
newMetrics
=
make
(
map
[
string
][]
v1
.
MetricVal
)
)
for
{
if
err
=
sdec
.
Decode
(
&
decSamples
);
err
!=
nil
{
break
break
}
}
if
!
strings
.
HasPrefix
(
line
,
"# HELP"
)
&&
!
strings
.
HasPrefix
(
line
,
"# TYPE"
)
{
var
metLabel
string
startLabelIndex
:=
strings
.
Index
(
line
,
"{"
)
spaceIndex
:=
strings
.
Index
(
line
,
" "
)
if
startLabelIndex
==
-
1
{
startLabelIndex
=
spaceIndex
}
metName
:=
strings
.
TrimSpace
(
line
[
0
:
startLabelIndex
])
for
_
,
sample
:=
range
decSamples
{
if
_
,
ok
:=
collector
.
metricsSet
[
metName
];
collector
.
metricsSet
!=
nil
&&
!
ok
{
metName
:=
string
(
sample
.
Metric
[
model
.
MetricNameLabel
])
if
len
(
metName
)
==
0
{
continue
continue
}
}
// If metrics to collect is specified, skip any metrics not in the list to collect.
if
startLabelIndex
+
1
<=
spaceIndex
-
1
{
if
_
,
ok
:=
collector
.
metricsSet
[
metName
];
collector
.
metricsSet
!=
nil
&&
!
ok
{
metLabel
=
strings
.
TrimSpace
(
line
[(
startLabelIndex
+
1
)
:
(
spaceIndex
-
1
)])
continue
}
metVal
,
err
:=
strconv
.
ParseFloat
(
line
[
spaceIndex
+
1
:
],
64
)
if
err
!=
nil
{
errorSlice
=
append
(
errorSlice
,
err
)
}
if
math
.
IsNaN
(
metVal
)
{
metVal
=
0
}
}
// TODO Handle multiple labels nicer. Prometheus metrics can have multiple
// labels, cadvisor only accepts a single string for the metric label.
label
:=
prometheusLabelSetToCadvisorLabel
(
sample
.
Metric
)
metric
:=
v1
.
MetricVal
{
metric
:=
v1
.
MetricVal
{
Label
:
metLabel
,
FloatValue
:
float64
(
sample
.
Value
)
,
FloatValue
:
metVal
,
Timestamp
:
sample
.
Timestamp
.
Time
()
,
Timestamp
:
currentTime
,
Label
:
label
,
}
}
newMetrics
[
metName
]
=
append
(
newMetrics
[
metName
],
metric
)
newMetrics
[
metName
]
=
append
(
newMetrics
[
metName
],
metric
)
if
len
(
newMetrics
)
>
collector
.
metricCountLimit
{
if
len
(
newMetrics
)
>
collector
.
metricCountLimit
{
return
nextCollectionTime
,
nil
,
fmt
.
Errorf
(
"too many metrics to collect"
)
return
nextCollectionTime
,
nil
,
fmt
.
Errorf
(
"too many metrics to collect"
)
}
}
}
}
decSamples
=
decSamples
[
:
0
]
}
if
err
!=
nil
&&
err
!=
io
.
EOF
{
return
nextCollectionTime
,
nil
,
err
}
}
for
key
,
val
:=
range
newMetrics
{
for
key
,
val
:=
range
newMetrics
{
metrics
[
key
]
=
append
(
metrics
[
key
],
val
...
)
metrics
[
key
]
=
append
(
metrics
[
key
],
val
...
)
}
}
return
nextCollectionTime
,
metrics
,
compileErrors
(
errorSlice
)
return
nextCollectionTime
,
metrics
,
nil
}
}
vendor/github.com/google/cadvisor/container/libcontainer/helpers.go
View file @
07bd42a1
...
@@ -45,7 +45,7 @@ type CgroupSubsystems struct {
...
@@ -45,7 +45,7 @@ type CgroupSubsystems struct {
// Get information about the cgroup subsystems.
// Get information about the cgroup subsystems.
func
GetCgroupSubsystems
()
(
CgroupSubsystems
,
error
)
{
func
GetCgroupSubsystems
()
(
CgroupSubsystems
,
error
)
{
// Get all cgroup mounts.
// Get all cgroup mounts.
allCgroups
,
err
:=
cgroups
.
GetCgroupMounts
()
allCgroups
,
err
:=
cgroups
.
GetCgroupMounts
(
true
)
if
err
!=
nil
{
if
err
!=
nil
{
return
CgroupSubsystems
{},
err
return
CgroupSubsystems
{},
err
}
}
...
...
vendor/github.com/google/cadvisor/container/rkt/handler.go
View file @
07bd42a1
...
@@ -84,7 +84,7 @@ func newRktContainerHandler(name string, rktClient rktapi.PublicAPIClient, rktPa
...
@@ -84,7 +84,7 @@ func newRktContainerHandler(name string, rktClient rktapi.PublicAPIClient, rktPa
return
nil
,
fmt
.
Errorf
(
"this should be impossible!, new handler failing, but factory allowed, name = %s"
,
name
)
return
nil
,
fmt
.
Errorf
(
"this should be impossible!, new handler failing, but factory allowed, name = %s"
,
name
)
}
}
//rktnetes uses containerID: rkt://fff40827-b994-4e3a-8f88-6427c2c8a5ac:nginx
//
rktnetes uses containerID: rkt://fff40827-b994-4e3a-8f88-6427c2c8a5ac:nginx
if
parsed
.
Container
==
""
{
if
parsed
.
Container
==
""
{
isPod
=
true
isPod
=
true
aliases
=
append
(
aliases
,
"rkt://"
+
parsed
.
Pod
)
aliases
=
append
(
aliases
,
"rkt://"
+
parsed
.
Pod
)
...
...
vendor/github.com/google/cadvisor/info/v1/container.go
View file @
07bd42a1
...
@@ -389,27 +389,27 @@ type NetworkStats struct {
...
@@ -389,27 +389,27 @@ type NetworkStats struct {
}
}
type
TcpStat
struct
{
type
TcpStat
struct
{
//Count of TCP connections in state "Established"
//
Count of TCP connections in state "Established"
Established
uint64
Established
uint64
//Count of TCP connections in state "Syn_Sent"
//
Count of TCP connections in state "Syn_Sent"
SynSent
uint64
SynSent
uint64
//Count of TCP connections in state "Syn_Recv"
//
Count of TCP connections in state "Syn_Recv"
SynRecv
uint64
SynRecv
uint64
//Count of TCP connections in state "Fin_Wait1"
//
Count of TCP connections in state "Fin_Wait1"
FinWait1
uint64
FinWait1
uint64
//Count of TCP connections in state "Fin_Wait2"
//
Count of TCP connections in state "Fin_Wait2"
FinWait2
uint64
FinWait2
uint64
//Count of TCP connections in state "Time_Wait
//
Count of TCP connections in state "Time_Wait
TimeWait
uint64
TimeWait
uint64
//Count of TCP connections in state "Close"
//
Count of TCP connections in state "Close"
Close
uint64
Close
uint64
//Count of TCP connections in state "Close_Wait"
//
Count of TCP connections in state "Close_Wait"
CloseWait
uint64
CloseWait
uint64
//Count of TCP connections in state "Listen_Ack"
//
Count of TCP connections in state "Listen_Ack"
LastAck
uint64
LastAck
uint64
//Count of TCP connections in state "Listen"
//
Count of TCP connections in state "Listen"
Listen
uint64
Listen
uint64
//Count of TCP connections in state "Closing"
//
Count of TCP connections in state "Closing"
Closing
uint64
Closing
uint64
}
}
...
@@ -511,7 +511,7 @@ type ContainerStats struct {
...
@@ -511,7 +511,7 @@ type ContainerStats struct {
// Task load stats
// Task load stats
TaskStats
LoadStats
`json:"task_stats,omitempty"`
TaskStats
LoadStats
`json:"task_stats,omitempty"`
//Custom metrics from all collectors
//
Custom metrics from all collectors
CustomMetrics
map
[
string
][]
MetricVal
`json:"custom_metrics,omitempty"`
CustomMetrics
map
[
string
][]
MetricVal
`json:"custom_metrics,omitempty"`
}
}
...
...
vendor/github.com/google/cadvisor/info/v1/metric.go
View file @
07bd42a1
...
@@ -26,10 +26,10 @@ const (
...
@@ -26,10 +26,10 @@ const (
MetricGauge
MetricType
=
"gauge"
MetricGauge
MetricType
=
"gauge"
// A counter-like value that is only expected to increase.
// A counter-like value that is only expected to increase.
MetricCumulative
=
"cumulative"
MetricCumulative
MetricType
=
"cumulative"
// Rate over a time period.
// Rate over a time period.
MetricDelta
=
"delta"
MetricDelta
MetricType
=
"delta"
)
)
// DataType for metric being exported.
// DataType for metric being exported.
...
@@ -37,7 +37,7 @@ type DataType string
...
@@ -37,7 +37,7 @@ type DataType string
const
(
const
(
IntType
DataType
=
"int"
IntType
DataType
=
"int"
FloatType
=
"float"
FloatType
DataType
=
"float"
)
)
// Spec for custom metric.
// Spec for custom metric.
...
...
vendor/github.com/google/cadvisor/pages/static/assets.go
View file @
07bd42a1
This source diff could not be displayed because it is too large. You can
view the blob
instead.
vendor/github.com/google/cadvisor/pages/templates.go
View file @
07bd42a1
...
@@ -98,7 +98,7 @@ func pagesAssetsHtmlContainersHtml() (*asset, error) {
...
@@ -98,7 +98,7 @@ func pagesAssetsHtmlContainersHtml() (*asset, error) {
return
nil
,
err
return
nil
,
err
}
}
info
:=
bindataFileInfo
{
name
:
"pages/assets/html/containers.html"
,
size
:
9533
,
mode
:
os
.
FileMode
(
416
),
modTime
:
time
.
Unix
(
1462817463
,
0
)}
info
:=
bindataFileInfo
{
name
:
"pages/assets/html/containers.html"
,
size
:
0
,
mode
:
os
.
FileMode
(
0
),
modTime
:
time
.
Unix
(
0
,
0
)}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
a
:=
&
asset
{
bytes
:
bytes
,
info
:
info
}
return
a
,
nil
return
a
,
nil
}
}
...
...
vendor/github.com/google/cadvisor/utils/cloudinfo/azure.go
View file @
07bd42a1
...
@@ -34,7 +34,7 @@ func onAzure() bool {
...
@@ -34,7 +34,7 @@ func onAzure() bool {
return
strings
.
Contains
(
string
(
data
),
MicrosoftCorporation
)
return
strings
.
Contains
(
string
(
data
),
MicrosoftCorporation
)
}
}
//TODO: Implement method.
//
TODO: Implement method.
func
getAzureInstanceType
()
info
.
InstanceType
{
func
getAzureInstanceType
()
info
.
InstanceType
{
return
info
.
UnknownInstance
return
info
.
UnknownInstance
}
}
...
...
vendor/github.com/google/cadvisor/utils/cloudinfo/cloudinfo.go
View file @
07bd42a1
...
@@ -97,7 +97,7 @@ func detectInstanceID(cloudProvider info.CloudProvider) info.InstanceID {
...
@@ -97,7 +97,7 @@ func detectInstanceID(cloudProvider info.CloudProvider) info.InstanceID {
return
info
.
UnNamedInstance
return
info
.
UnNamedInstance
}
}
//TODO: Implement method.
//
TODO: Implement method.
func
onBaremetal
()
bool
{
func
onBaremetal
()
bool
{
return
false
return
false
}
}
vendor/github.com/google/cadvisor/utils/tail/tail.go
View file @
07bd42a1
...
@@ -88,7 +88,7 @@ func (t *Tail) attemptOpen() error {
...
@@ -88,7 +88,7 @@ func (t *Tail) attemptOpen() error {
t
.
file
,
err
=
os
.
Open
(
t
.
filename
)
t
.
file
,
err
=
os
.
Open
(
t
.
filename
)
if
err
==
nil
{
if
err
==
nil
{
// TODO: not interested in old events?
// TODO: not interested in old events?
//t.file.Seek(0, os.SEEK_END)
//
t.file.Seek(0, os.SEEK_END)
t
.
reader
=
bufio
.
NewReader
(
t
.
file
)
t
.
reader
=
bufio
.
NewReader
(
t
.
file
)
return
nil
return
nil
}
}
...
...
vendor/github.com/opencontainers/runc/libcontainer/README.md
View file @
07bd42a1
...
@@ -83,6 +83,7 @@ config := &configs.Config{
...
@@ -83,6 +83,7 @@ config := &configs.Config{
},
},
MaskPaths
:
[]
string
{
MaskPaths
:
[]
string
{
"/proc/kcore"
,
"/proc/kcore"
,
"/sys/firmware"
,
},
},
ReadonlyPaths
:
[]
string
{
ReadonlyPaths
:
[]
string
{
"/proc/sys"
,
"/proc/sysrq-trigger"
,
"/proc/irq"
,
"/proc/bus"
,
"/proc/sys"
,
"/proc/sysrq-trigger"
,
"/proc/irq"
,
"/proc/bus"
,
...
@@ -184,7 +185,7 @@ process := &libcontainer.Process{
...
@@ -184,7 +185,7 @@ process := &libcontainer.Process{
Stderr
:
os
.
Stderr
,
Stderr
:
os
.
Stderr
,
}
}
err
:=
container
.
Start
(
process
)
err
:=
container
.
Run
(
process
)
if
err
!=
nil
{
if
err
!=
nil
{
container
.
Destroy
()
container
.
Destroy
()
logrus
.
Fatal
(
err
)
logrus
.
Fatal
(
err
)
...
...
vendor/github.com/opencontainers/runc/libcontainer/SPEC.md
View file @
07bd42a1
...
@@ -71,7 +71,6 @@ that are required for executing a container's process.
...
@@ -71,7 +71,6 @@ that are required for executing a container's process.
| /dev/tty | 0666 | rwm |
| /dev/tty | 0666 | rwm |
| /dev/random | 0666 | rwm |
| /dev/random | 0666 | rwm |
| /dev/urandom | 0666 | rwm |
| /dev/urandom | 0666 | rwm |
| /dev/fuse | 0666 | rwm |
**ptmx**
**ptmx**
...
...
vendor/github.com/opencontainers/runc/libcontainer/capabilities_linux.go
View file @
07bd42a1
...
@@ -10,7 +10,7 @@ import (
...
@@ -10,7 +10,7 @@ import (
"github.com/syndtr/gocapability/capability"
"github.com/syndtr/gocapability/capability"
)
)
const
allCapabilityTypes
=
capability
.
CAPS
|
capability
.
BOUNDS
const
allCapabilityTypes
=
capability
.
CAPS
|
capability
.
BOUNDS
|
capability
.
AMBS
var
capabilityMap
map
[
string
]
capability
.
Cap
var
capabilityMap
map
[
string
]
capability
.
Cap
...
...
vendor/github.com/opencontainers/runc/libcontainer/cgroups/cgroups.go
View file @
07bd42a1
...
@@ -37,7 +37,7 @@ type Manager interface {
...
@@ -37,7 +37,7 @@ type Manager interface {
// restore the object later.
// restore the object later.
GetPaths
()
map
[
string
]
string
GetPaths
()
map
[
string
]
string
// Set the cgroup as configured.
// Set
s
the cgroup as configured.
Set
(
container
*
configs
.
Config
)
error
Set
(
container
*
configs
.
Config
)
error
}
}
...
...
vendor/github.com/opencontainers/runc/libcontainer/cgroups/fs/apply_raw.go
View file @
07bd42a1
...
@@ -104,6 +104,8 @@ func (m *Manager) Apply(pid int) (err error) {
...
@@ -104,6 +104,8 @@ func (m *Manager) Apply(pid int) (err error) {
if
m
.
Cgroups
==
nil
{
if
m
.
Cgroups
==
nil
{
return
nil
return
nil
}
}
m
.
mu
.
Lock
()
defer
m
.
mu
.
Unlock
()
var
c
=
m
.
Cgroups
var
c
=
m
.
Cgroups
...
@@ -128,8 +130,6 @@ func (m *Manager) Apply(pid int) (err error) {
...
@@ -128,8 +130,6 @@ func (m *Manager) Apply(pid int) (err error) {
return
cgroups
.
EnterPid
(
m
.
Paths
,
pid
)
return
cgroups
.
EnterPid
(
m
.
Paths
,
pid
)
}
}
m
.
mu
.
Lock
()
defer
m
.
mu
.
Unlock
()
paths
:=
make
(
map
[
string
]
string
)
paths
:=
make
(
map
[
string
]
string
)
for
_
,
sys
:=
range
subsystems
{
for
_
,
sys
:=
range
subsystems
{
if
err
:=
sys
.
Apply
(
d
);
err
!=
nil
{
if
err
:=
sys
.
Apply
(
d
);
err
!=
nil
{
...
@@ -195,18 +195,10 @@ func (m *Manager) Set(container *configs.Config) error {
...
@@ -195,18 +195,10 @@ func (m *Manager) Set(container *configs.Config) error {
if
m
.
Cgroups
.
Paths
!=
nil
{
if
m
.
Cgroups
.
Paths
!=
nil
{
return
nil
return
nil
}
}
for
_
,
sys
:=
range
subsystems
{
// Generate fake cgroup data.
d
,
err
:=
getCgroupData
(
container
.
Cgroups
,
-
1
)
if
err
!=
nil
{
return
err
}
// Get the path, but don't error out if the cgroup wasn't found.
path
,
err
:=
d
.
path
(
sys
.
Name
())
if
err
!=
nil
&&
!
cgroups
.
IsNotFound
(
err
)
{
return
err
}
paths
:=
m
.
GetPaths
()
for
_
,
sys
:=
range
subsystems
{
path
:=
paths
[
sys
.
Name
()]
if
err
:=
sys
.
Set
(
path
,
container
.
Cgroups
);
err
!=
nil
{
if
err
:=
sys
.
Set
(
path
,
container
.
Cgroups
);
err
!=
nil
{
return
err
return
err
}
}
...
@@ -223,14 +215,8 @@ func (m *Manager) Set(container *configs.Config) error {
...
@@ -223,14 +215,8 @@ func (m *Manager) Set(container *configs.Config) error {
// Freeze toggles the container's freezer cgroup depending on the state
// Freeze toggles the container's freezer cgroup depending on the state
// provided
// provided
func
(
m
*
Manager
)
Freeze
(
state
configs
.
FreezerState
)
error
{
func
(
m
*
Manager
)
Freeze
(
state
configs
.
FreezerState
)
error
{
d
,
err
:=
getCgroupData
(
m
.
Cgroups
,
0
)
paths
:=
m
.
GetPaths
()
if
err
!=
nil
{
dir
:=
paths
[
"freezer"
]
return
err
}
dir
,
err
:=
d
.
path
(
"freezer"
)
if
err
!=
nil
{
return
err
}
prevState
:=
m
.
Cgroups
.
Resources
.
Freezer
prevState
:=
m
.
Cgroups
.
Resources
.
Freezer
m
.
Cgroups
.
Resources
.
Freezer
=
state
m
.
Cgroups
.
Resources
.
Freezer
=
state
freezer
,
err
:=
subsystems
.
Get
(
"freezer"
)
freezer
,
err
:=
subsystems
.
Get
(
"freezer"
)
...
@@ -246,28 +232,13 @@ func (m *Manager) Freeze(state configs.FreezerState) error {
...
@@ -246,28 +232,13 @@ func (m *Manager) Freeze(state configs.FreezerState) error {
}
}
func
(
m
*
Manager
)
GetPids
()
([]
int
,
error
)
{
func
(
m
*
Manager
)
GetPids
()
([]
int
,
error
)
{
dir
,
err
:=
getCgroupPath
(
m
.
Cgroups
)
paths
:=
m
.
GetPaths
()
if
err
!=
nil
{
return
cgroups
.
GetPids
(
paths
[
"devices"
])
return
nil
,
err
}
return
cgroups
.
GetPids
(
dir
)
}
}
func
(
m
*
Manager
)
GetAllPids
()
([]
int
,
error
)
{
func
(
m
*
Manager
)
GetAllPids
()
([]
int
,
error
)
{
dir
,
err
:=
getCgroupPath
(
m
.
Cgroups
)
paths
:=
m
.
GetPaths
()
if
err
!=
nil
{
return
cgroups
.
GetAllPids
(
paths
[
"devices"
])
return
nil
,
err
}
return
cgroups
.
GetAllPids
(
dir
)
}
func
getCgroupPath
(
c
*
configs
.
Cgroup
)
(
string
,
error
)
{
d
,
err
:=
getCgroupData
(
c
,
0
)
if
err
!=
nil
{
return
""
,
err
}
return
d
.
path
(
"devices"
)
}
}
func
getCgroupData
(
c
*
configs
.
Cgroup
,
pid
int
)
(
*
cgroupData
,
error
)
{
func
getCgroupData
(
c
*
configs
.
Cgroup
,
pid
int
)
(
*
cgroupData
,
error
)
{
...
...
vendor/github.com/opencontainers/runc/libcontainer/cgroups/fs/cpu.go
View file @
07bd42a1
...
@@ -22,10 +22,48 @@ func (s *CpuGroup) Name() string {
...
@@ -22,10 +22,48 @@ func (s *CpuGroup) Name() string {
func
(
s
*
CpuGroup
)
Apply
(
d
*
cgroupData
)
error
{
func
(
s
*
CpuGroup
)
Apply
(
d
*
cgroupData
)
error
{
// We always want to join the cpu group, to allow fair cpu scheduling
// We always want to join the cpu group, to allow fair cpu scheduling
// on a container basis
// on a container basis
_
,
err
:=
d
.
join
(
"cpu"
)
path
,
err
:=
d
.
path
(
"cpu"
)
if
err
!=
nil
&&
!
cgroups
.
IsNotFound
(
err
)
{
if
err
!=
nil
&&
!
cgroups
.
IsNotFound
(
err
)
{
return
err
return
err
}
}
return
s
.
ApplyDir
(
path
,
d
.
config
,
d
.
pid
)
}
func
(
s
*
CpuGroup
)
ApplyDir
(
path
string
,
cgroup
*
configs
.
Cgroup
,
pid
int
)
error
{
// This might happen if we have no cpu cgroup mounted.
// Just do nothing and don't fail.
if
path
==
""
{
return
nil
}
if
err
:=
os
.
MkdirAll
(
path
,
0755
);
err
!=
nil
{
return
err
}
// We should set the real-Time group scheduling settings before moving
// in the process because if the process is already in SCHED_RR mode
// and no RT bandwidth is set, adding it will fail.
if
err
:=
s
.
SetRtSched
(
path
,
cgroup
);
err
!=
nil
{
return
err
}
// because we are not using d.join we need to place the pid into the procs file
// unlike the other subsystems
if
err
:=
cgroups
.
WriteCgroupProc
(
path
,
pid
);
err
!=
nil
{
return
err
}
return
nil
}
func
(
s
*
CpuGroup
)
SetRtSched
(
path
string
,
cgroup
*
configs
.
Cgroup
)
error
{
if
cgroup
.
Resources
.
CpuRtPeriod
!=
0
{
if
err
:=
writeFile
(
path
,
"cpu.rt_period_us"
,
strconv
.
FormatInt
(
cgroup
.
Resources
.
CpuRtPeriod
,
10
));
err
!=
nil
{
return
err
}
}
if
cgroup
.
Resources
.
CpuRtRuntime
!=
0
{
if
err
:=
writeFile
(
path
,
"cpu.rt_runtime_us"
,
strconv
.
FormatInt
(
cgroup
.
Resources
.
CpuRtRuntime
,
10
));
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
@@ -45,15 +83,8 @@ func (s *CpuGroup) Set(path string, cgroup *configs.Cgroup) error {
...
@@ -45,15 +83,8 @@ func (s *CpuGroup) Set(path string, cgroup *configs.Cgroup) error {
return
err
return
err
}
}
}
}
if
cgroup
.
Resources
.
CpuRtPeriod
!=
0
{
if
err
:=
s
.
SetRtSched
(
path
,
cgroup
);
err
!=
nil
{
if
err
:=
writeFile
(
path
,
"cpu.rt_period_us"
,
strconv
.
FormatInt
(
cgroup
.
Resources
.
CpuRtPeriod
,
10
));
err
!=
nil
{
return
err
return
err
}
}
if
cgroup
.
Resources
.
CpuRtRuntime
!=
0
{
if
err
:=
writeFile
(
path
,
"cpu.rt_runtime_us"
,
strconv
.
FormatInt
(
cgroup
.
Resources
.
CpuRtRuntime
,
10
));
err
!=
nil
{
return
err
}
}
}
return
nil
return
nil
...
...
vendor/github.com/opencontainers/runc/libcontainer/cgroups/fs/memory.go
View file @
07bd42a1
...
@@ -16,9 +16,7 @@ import (
...
@@ -16,9 +16,7 @@ import (
"github.com/opencontainers/runc/libcontainer/configs"
"github.com/opencontainers/runc/libcontainer/configs"
)
)
const
(
const
cgroupKernelMemoryLimit
=
"memory.kmem.limit_in_bytes"
cgroupKernelMemoryLimit
=
"memory.kmem.limit_in_bytes"
)
type
MemoryGroup
struct
{
type
MemoryGroup
struct
{
}
}
...
@@ -38,8 +36,10 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
...
@@ -38,8 +36,10 @@ func (s *MemoryGroup) Apply(d *cgroupData) (err error) {
return
err
return
err
}
}
}
}
if
err
:=
EnableKernelMemoryAccounting
(
path
);
err
!=
nil
{
if
d
.
config
.
KernelMemory
!=
0
{
return
err
if
err
:=
EnableKernelMemoryAccounting
(
path
);
err
!=
nil
{
return
err
}
}
}
}
}
defer
func
()
{
defer
func
()
{
...
@@ -62,13 +62,10 @@ func EnableKernelMemoryAccounting(path string) error {
...
@@ -62,13 +62,10 @@ func EnableKernelMemoryAccounting(path string) error {
// We have to limit the kernel memory here as it won't be accounted at all
// We have to limit the kernel memory here as it won't be accounted at all
// until a limit is set on the cgroup and limit cannot be set once the
// until a limit is set on the cgroup and limit cannot be set once the
// cgroup has children, or if there are already tasks in the cgroup.
// cgroup has children, or if there are already tasks in the cgroup.
kernelMemoryLimit
:=
int64
(
1
)
for
_
,
i
:=
range
[]
int64
{
1
,
-
1
}
{
if
err
:=
setKernelMemory
(
path
,
kernelMemoryLimit
);
err
!=
nil
{
if
err
:=
setKernelMemory
(
path
,
i
);
err
!=
nil
{
return
err
return
err
}
}
kernelMemoryLimit
=
int64
(
-
1
)
if
err
:=
setKernelMemory
(
path
,
kernelMemoryLimit
);
err
!=
nil
{
return
err
}
}
return
nil
return
nil
}
}
...
...
vendor/github.com/opencontainers/runc/libcontainer/cgroups/systemd/apply_systemd.go
View file @
07bd42a1
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
"io/ioutil"
"io/ioutil"
"os"
"os"
"path/filepath"
"path/filepath"
"strconv"
"strings"
"strings"
"sync"
"sync"
"time"
"time"
...
@@ -67,12 +66,14 @@ var subsystems = subsystemSet{
...
@@ -67,12 +66,14 @@ var subsystems = subsystemSet{
const
(
const
(
testScopeWait
=
4
testScopeWait
=
4
testSliceWait
=
4
)
)
var
(
var
(
connLock
sync
.
Mutex
connLock
sync
.
Mutex
theConn
*
systemdDbus
.
Conn
theConn
*
systemdDbus
.
Conn
hasStartTransientUnit
bool
hasStartTransientUnit
bool
hasStartTransientSliceUnit
bool
hasTransientDefaultDependencies
bool
hasTransientDefaultDependencies
bool
hasDelegate
bool
hasDelegate
bool
)
)
...
@@ -159,8 +160,36 @@ func UseSystemd() bool {
...
@@ -159,8 +160,36 @@ func UseSystemd() bool {
}
}
}
}
// Assume we have the ability to start a transient unit as a slice
// This was broken until systemd v229, but has been back-ported on RHEL environments >= 219
// For details, see: https://bugzilla.redhat.com/show_bug.cgi?id=1370299
hasStartTransientSliceUnit
=
true
// To ensure simple clean-up, we create a slice off the root with no hierarchy
slice
:=
fmt
.
Sprintf
(
"libcontainer_%d_systemd_test_default.slice"
,
os
.
Getpid
())
if
_
,
err
:=
theConn
.
StartTransientUnit
(
slice
,
"replace"
,
nil
,
nil
);
err
!=
nil
{
if
_
,
ok
:=
err
.
(
dbus
.
Error
);
ok
{
hasStartTransientSliceUnit
=
false
}
}
for
i
:=
0
;
i
<=
testSliceWait
;
i
++
{
if
_
,
err
:=
theConn
.
StopUnit
(
slice
,
"replace"
,
nil
);
err
!=
nil
{
if
dbusError
,
ok
:=
err
.
(
dbus
.
Error
);
ok
{
if
strings
.
Contains
(
dbusError
.
Name
,
"org.freedesktop.systemd1.NoSuchUnit"
)
{
hasStartTransientSliceUnit
=
false
break
}
}
}
else
{
break
}
time
.
Sleep
(
time
.
Millisecond
)
}
// Not critical because of the stop unit logic above.
// Not critical because of the stop unit logic above.
theConn
.
StopUnit
(
scope
,
"replace"
,
nil
)
theConn
.
StopUnit
(
scope
,
"replace"
,
nil
)
theConn
.
StopUnit
(
slice
,
"replace"
,
nil
)
}
}
return
hasStartTransientUnit
return
hasStartTransientUnit
}
}
...
@@ -194,11 +223,24 @@ func (m *Manager) Apply(pid int) error {
...
@@ -194,11 +223,24 @@ func (m *Manager) Apply(pid int) error {
slice
=
c
.
Parent
slice
=
c
.
Parent
}
}
properties
=
append
(
properties
,
properties
=
append
(
properties
,
systemdDbus
.
PropDescription
(
"libcontainer container "
+
c
.
Name
))
systemdDbus
.
PropSlice
(
slice
),
systemdDbus
.
PropDescription
(
"docker container "
+
c
.
Name
),
// if we create a slice, the parent is defined via a Wants=
newProp
(
"PIDs"
,
[]
uint32
{
uint32
(
pid
)}),
if
strings
.
HasSuffix
(
unitName
,
".slice"
)
{
)
// This was broken until systemd v229, but has been back-ported on RHEL environments >= 219
if
!
hasStartTransientSliceUnit
{
return
fmt
.
Errorf
(
"systemd version does not support ability to start a slice as transient unit"
)
}
properties
=
append
(
properties
,
systemdDbus
.
PropWants
(
slice
))
}
else
{
// otherwise, we use Slice=
properties
=
append
(
properties
,
systemdDbus
.
PropSlice
(
slice
))
}
// only add pid if its valid, -1 is used w/ general slice creation.
if
pid
!=
-
1
{
properties
=
append
(
properties
,
newProp
(
"PIDs"
,
[]
uint32
{
uint32
(
pid
)}))
}
if
hasDelegate
{
if
hasDelegate
{
// This is only supported on systemd versions 218 and above.
// This is only supported on systemd versions 218 and above.
...
@@ -302,10 +344,9 @@ func join(c *configs.Cgroup, subsystem string, pid int) (string, error) {
...
@@ -302,10 +344,9 @@ func join(c *configs.Cgroup, subsystem string, pid int) (string, error) {
if
err
:=
os
.
MkdirAll
(
path
,
0755
);
err
!=
nil
{
if
err
:=
os
.
MkdirAll
(
path
,
0755
);
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
if
err
:=
writeFile
(
path
,
"cgroup.procs"
,
strconv
.
Itoa
(
pid
)
);
err
!=
nil
{
if
err
:=
cgroups
.
WriteCgroupProc
(
path
,
pid
);
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
return
path
,
nil
return
path
,
nil
}
}
...
@@ -350,7 +391,7 @@ func joinCgroups(c *configs.Cgroup, pid int) error {
...
@@ -350,7 +391,7 @@ func joinCgroups(c *configs.Cgroup, pid int) error {
// systemd represents slice heirarchy using `-`, so we need to follow suit when
// systemd represents slice heirarchy using `-`, so we need to follow suit when
// generating the path of slice. Essentially, test-a-b.slice becomes
// generating the path of slice. Essentially, test-a-b.slice becomes
// test.slice/test-a.slice/test-a-b.slice.
// test.slice/test-a.slice/test-a-b.slice.
func
e
xpandSlice
(
slice
string
)
(
string
,
error
)
{
func
E
xpandSlice
(
slice
string
)
(
string
,
error
)
{
suffix
:=
".slice"
suffix
:=
".slice"
// Name has to end with ".slice", but can't be just ".slice".
// Name has to end with ".slice", but can't be just ".slice".
if
len
(
slice
)
<
len
(
suffix
)
||
!
strings
.
HasSuffix
(
slice
,
suffix
)
{
if
len
(
slice
)
<
len
(
suffix
)
||
!
strings
.
HasSuffix
(
slice
,
suffix
)
{
...
@@ -364,6 +405,10 @@ func expandSlice(slice string) (string, error) {
...
@@ -364,6 +405,10 @@ func expandSlice(slice string) (string, error) {
var
path
,
prefix
string
var
path
,
prefix
string
sliceName
:=
strings
.
TrimSuffix
(
slice
,
suffix
)
sliceName
:=
strings
.
TrimSuffix
(
slice
,
suffix
)
// if input was -.slice, we should just return root now
if
sliceName
==
"-"
{
return
"/"
,
nil
}
for
_
,
component
:=
range
strings
.
Split
(
sliceName
,
"-"
)
{
for
_
,
component
:=
range
strings
.
Split
(
sliceName
,
"-"
)
{
// test--a.slice isn't permitted, nor is -test.slice.
// test--a.slice isn't permitted, nor is -test.slice.
if
component
==
""
{
if
component
==
""
{
...
@@ -396,7 +441,7 @@ func getSubsystemPath(c *configs.Cgroup, subsystem string) (string, error) {
...
@@ -396,7 +441,7 @@ func getSubsystemPath(c *configs.Cgroup, subsystem string) (string, error) {
slice
=
c
.
Parent
slice
=
c
.
Parent
}
}
slice
,
err
=
e
xpandSlice
(
slice
)
slice
,
err
=
E
xpandSlice
(
slice
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
@@ -483,7 +528,11 @@ func (m *Manager) Set(container *configs.Config) error {
...
@@ -483,7 +528,11 @@ func (m *Manager) Set(container *configs.Config) error {
}
}
func
getUnitName
(
c
*
configs
.
Cgroup
)
string
{
func
getUnitName
(
c
*
configs
.
Cgroup
)
string
{
return
fmt
.
Sprintf
(
"%s-%s.scope"
,
c
.
ScopePrefix
,
c
.
Name
)
// by default, we create a scope unless the user explicitly asks for a slice.
if
!
strings
.
HasSuffix
(
c
.
Name
,
".slice"
)
{
return
fmt
.
Sprintf
(
"%s-%s.scope"
,
c
.
ScopePrefix
,
c
.
Name
)
}
return
c
.
Name
}
}
func
setKernelMemory
(
c
*
configs
.
Cgroup
)
error
{
func
setKernelMemory
(
c
*
configs
.
Cgroup
)
error
{
...
...
vendor/github.com/opencontainers/runc/libcontainer/cgroups/utils.go
View file @
07bd42a1
...
@@ -139,7 +139,7 @@ func (m Mount) GetThisCgroupDir(cgroups map[string]string) (string, error) {
...
@@ -139,7 +139,7 @@ func (m Mount) GetThisCgroupDir(cgroups map[string]string) (string, error) {
return
getControllerPath
(
m
.
Subsystems
[
0
],
cgroups
)
return
getControllerPath
(
m
.
Subsystems
[
0
],
cgroups
)
}
}
func
getCgroupMountsHelper
(
ss
map
[
string
]
bool
,
mi
io
.
Reader
)
([]
Mount
,
error
)
{
func
getCgroupMountsHelper
(
ss
map
[
string
]
bool
,
mi
io
.
Reader
,
all
bool
)
([]
Mount
,
error
)
{
res
:=
make
([]
Mount
,
0
,
len
(
ss
))
res
:=
make
([]
Mount
,
0
,
len
(
ss
))
scanner
:=
bufio
.
NewScanner
(
mi
)
scanner
:=
bufio
.
NewScanner
(
mi
)
numFound
:=
0
numFound
:=
0
...
@@ -166,7 +166,9 @@ func getCgroupMountsHelper(ss map[string]bool, mi io.Reader) ([]Mount, error) {
...
@@ -166,7 +166,9 @@ func getCgroupMountsHelper(ss map[string]bool, mi io.Reader) ([]Mount, error) {
}
else
{
}
else
{
m
.
Subsystems
=
append
(
m
.
Subsystems
,
opt
)
m
.
Subsystems
=
append
(
m
.
Subsystems
,
opt
)
}
}
numFound
++
if
!
all
{
numFound
++
}
}
}
res
=
append
(
res
,
m
)
res
=
append
(
res
,
m
)
}
}
...
@@ -176,23 +178,25 @@ func getCgroupMountsHelper(ss map[string]bool, mi io.Reader) ([]Mount, error) {
...
@@ -176,23 +178,25 @@ func getCgroupMountsHelper(ss map[string]bool, mi io.Reader) ([]Mount, error) {
return
res
,
nil
return
res
,
nil
}
}
func
GetCgroupMounts
()
([]
Mount
,
error
)
{
// GetCgroupMounts returns the mounts for the cgroup subsystems.
// all indicates whether to return just the first instance or all the mounts.
func
GetCgroupMounts
(
all
bool
)
([]
Mount
,
error
)
{
f
,
err
:=
os
.
Open
(
"/proc/self/mountinfo"
)
f
,
err
:=
os
.
Open
(
"/proc/self/mountinfo"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
defer
f
.
Close
()
defer
f
.
Close
()
all
,
err
:=
ParseCgroupFile
(
"/proc/self/cgroup"
)
all
Subsystems
,
err
:=
ParseCgroupFile
(
"/proc/self/cgroup"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
allMap
:=
make
(
map
[
string
]
bool
)
allMap
:=
make
(
map
[
string
]
bool
)
for
s
:=
range
all
{
for
s
:=
range
all
Subsystems
{
allMap
[
s
]
=
true
allMap
[
s
]
=
true
}
}
return
getCgroupMountsHelper
(
allMap
,
f
)
return
getCgroupMountsHelper
(
allMap
,
f
,
all
)
}
}
// GetAllSubsystems returns all the cgroup subsystems supported by the kernel
// GetAllSubsystems returns all the cgroup subsystems supported by the kernel
...
...
vendor/github.com/opencontainers/runc/libcontainer/configs/cgroup_unix.go
View file @
07bd42a1
...
@@ -120,5 +120,5 @@ type Resources struct {
...
@@ -120,5 +120,5 @@ type Resources struct {
NetPrioIfpriomap
[]
*
IfPrioMap
`json:"net_prio_ifpriomap"`
NetPrioIfpriomap
[]
*
IfPrioMap
`json:"net_prio_ifpriomap"`
// Set class identifier for container's network packets
// Set class identifier for container's network packets
NetClsClassid
uint32
`json:"net_cls_classid"`
NetClsClassid
uint32
`json:"net_cls_classid
_u
"`
}
}
vendor/github.com/opencontainers/runc/libcontainer/configs/config.go
View file @
07bd42a1
...
@@ -300,29 +300,38 @@ func (c Command) Run(s HookState) error {
...
@@ -300,29 +300,38 @@ func (c Command) Run(s HookState) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
var
stdout
,
stderr
bytes
.
Buffer
cmd
:=
exec
.
Cmd
{
cmd
:=
exec
.
Cmd
{
Path
:
c
.
Path
,
Path
:
c
.
Path
,
Args
:
c
.
Args
,
Args
:
c
.
Args
,
Env
:
c
.
Env
,
Env
:
c
.
Env
,
Stdin
:
bytes
.
NewReader
(
b
),
Stdin
:
bytes
.
NewReader
(
b
),
Stdout
:
&
stdout
,
Stderr
:
&
stderr
,
}
if
err
:=
cmd
.
Start
();
err
!=
nil
{
return
err
}
}
errC
:=
make
(
chan
error
,
1
)
errC
:=
make
(
chan
error
,
1
)
go
func
()
{
go
func
()
{
out
,
err
:=
cmd
.
CombinedOutpu
t
()
err
:=
cmd
.
Wai
t
()
if
err
!=
nil
{
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"
%s: %s"
,
err
,
out
)
err
=
fmt
.
Errorf
(
"
error running hook: %v, stdout: %s, stderr: %s"
,
err
,
stdout
.
String
(),
stderr
.
String
()
)
}
}
errC
<-
err
errC
<-
err
}()
}()
var
timerCh
<-
chan
time
.
Time
if
c
.
Timeout
!=
nil
{
if
c
.
Timeout
!=
nil
{
select
{
timer
:=
time
.
NewTimer
(
*
c
.
Timeout
)
case
err
:=
<-
errC
:
defer
timer
.
Stop
()
return
err
timerCh
=
timer
.
C
case
<-
time
.
After
(
*
c
.
Timeout
)
:
}
cmd
.
Process
.
Kill
()
select
{
cmd
.
Wait
()
case
err
:=
<-
errC
:
return
fmt
.
Errorf
(
"hook ran past specified timeout of %.1fs"
,
c
.
Timeout
.
Seconds
())
return
err
}
case
<-
timerCh
:
cmd
.
Process
.
Kill
()
cmd
.
Wait
()
return
fmt
.
Errorf
(
"hook ran past specified timeout of %.1fs"
,
c
.
Timeout
.
Seconds
())
}
}
return
<-
errC
}
}
vendor/github.com/opencontainers/runc/libcontainer/configs/device_defaults.go
View file @
07bd42a1
...
@@ -107,19 +107,5 @@ var (
...
@@ -107,19 +107,5 @@ var (
Permissions
:
"rwm"
,
Permissions
:
"rwm"
,
},
},
},
DefaultSimpleDevices
...
)
},
DefaultSimpleDevices
...
)
DefaultAutoCreatedDevices
=
append
([]
*
Device
{
DefaultAutoCreatedDevices
=
append
([]
*
Device
{},
DefaultSimpleDevices
...
)
{
// /dev/fuse is created but not allowed.
// This is to allow java to work. Because java
// Insists on there being a /dev/fuse
// https://github.com/docker/docker/issues/514
// https://github.com/docker/docker/issues/2393
//
Path
:
"/dev/fuse"
,
Type
:
'c'
,
Major
:
10
,
Minor
:
229
,
Permissions
:
"rwm"
,
},
},
DefaultSimpleDevices
...
)
)
)
vendor/github.com/opencontainers/runc/libcontainer/container.go
View file @
07bd42a1
...
@@ -75,8 +75,8 @@ type BaseContainer interface {
...
@@ -75,8 +75,8 @@ type BaseContainer interface {
// Returns the current status of the container.
// Returns the current status of the container.
//
//
// errors:
// errors:
// Container
Destroyed
- Container no longer exists,
// Container
NotExists
- Container no longer exists,
// System
E
rror - System error.
// System
e
rror - System error.
Status
()
(
Status
,
error
)
Status
()
(
Status
,
error
)
// State returns the current container's state information.
// State returns the current container's state information.
...
@@ -91,8 +91,8 @@ type BaseContainer interface {
...
@@ -91,8 +91,8 @@ type BaseContainer interface {
// Returns the PIDs inside this container. The PIDs are in the namespace of the calling process.
// Returns the PIDs inside this container. The PIDs are in the namespace of the calling process.
//
//
// errors:
// errors:
// Container
Destroyed
- Container no longer exists,
// Container
NotExists
- Container no longer exists,
// System
E
rror - System error.
// System
e
rror - System error.
//
//
// Some of the returned PIDs may no longer refer to processes in the Container, unless
// Some of the returned PIDs may no longer refer to processes in the Container, unless
// the Container state is PAUSED in which case every PID in the slice is valid.
// the Container state is PAUSED in which case every PID in the slice is valid.
...
@@ -101,8 +101,8 @@ type BaseContainer interface {
...
@@ -101,8 +101,8 @@ type BaseContainer interface {
// Returns statistics for the container.
// Returns statistics for the container.
//
//
// errors:
// errors:
// Container
Destroyed
- Container no longer exists,
// Container
NotExists
- Container no longer exists,
// System
E
rror - System error.
// System
e
rror - System error.
Stats
()
(
*
Stats
,
error
)
Stats
()
(
*
Stats
,
error
)
// Set resources of container as configured
// Set resources of container as configured
...
@@ -117,7 +117,7 @@ type BaseContainer interface {
...
@@ -117,7 +117,7 @@ type BaseContainer interface {
// start. You can track process lifecycle with passed Process structure.
// start. You can track process lifecycle with passed Process structure.
//
//
// errors:
// errors:
// Container
Destroyed
- Container no longer exists,
// Container
NotExists
- Container no longer exists,
// ConfigInvalid - config is invalid,
// ConfigInvalid - config is invalid,
// ContainerPaused - Container is paused,
// ContainerPaused - Container is paused,
// SystemError - System error.
// SystemError - System error.
...
@@ -128,7 +128,7 @@ type BaseContainer interface {
...
@@ -128,7 +128,7 @@ type BaseContainer interface {
// opens the fifo after start returns.
// opens the fifo after start returns.
//
//
// errors:
// errors:
// Container
Destroyed
- Container no longer exists,
// Container
NotExists
- Container no longer exists,
// ConfigInvalid - config is invalid,
// ConfigInvalid - config is invalid,
// ContainerPaused - Container is paused,
// ContainerPaused - Container is paused,
// SystemError - System error.
// SystemError - System error.
...
...
vendor/github.com/opencontainers/runc/libcontainer/container_linux.go
View file @
07bd42a1
...
@@ -35,7 +35,6 @@ type linuxContainer struct {
...
@@ -35,7 +35,6 @@ type linuxContainer struct {
root
string
root
string
config
*
configs
.
Config
config
*
configs
.
Config
cgroupManager
cgroups
.
Manager
cgroupManager
cgroups
.
Manager
initPath
string
initArgs
[]
string
initArgs
[]
string
initProcess
parentProcess
initProcess
parentProcess
initProcessStartTime
string
initProcessStartTime
string
...
@@ -86,13 +85,14 @@ type Container interface {
...
@@ -86,13 +85,14 @@ type Container interface {
// Systemerror - System error.
// Systemerror - System error.
Restore
(
process
*
Process
,
criuOpts
*
CriuOpts
)
error
Restore
(
process
*
Process
,
criuOpts
*
CriuOpts
)
error
// If the Container state is RUNNING, sets the Container state to PAUSING and pauses
// If the Container state is RUNNING
or CREATED
, sets the Container state to PAUSING and pauses
// the execution of any user processes. Asynchronously, when the container finished being paused the
// the execution of any user processes. Asynchronously, when the container finished being paused the
// state is changed to PAUSED.
// state is changed to PAUSED.
// If the Container state is PAUSED, do nothing.
// If the Container state is PAUSED, do nothing.
//
//
// errors:
// errors:
// ContainerDestroyed - Container no longer exists,
// ContainerNotExists - Container no longer exists,
// ContainerNotRunning - Container not running or created,
// Systemerror - System error.
// Systemerror - System error.
Pause
()
error
Pause
()
error
...
@@ -101,7 +101,8 @@ type Container interface {
...
@@ -101,7 +101,8 @@ type Container interface {
// If the Container state is RUNNING, do nothing.
// If the Container state is RUNNING, do nothing.
//
//
// errors:
// errors:
// ContainerDestroyed - Container no longer exists,
// ContainerNotExists - Container no longer exists,
// ContainerNotPaused - Container is not paused,
// Systemerror - System error.
// Systemerror - System error.
Resume
()
error
Resume
()
error
...
@@ -308,10 +309,7 @@ func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProces
...
@@ -308,10 +309,7 @@ func (c *linuxContainer) newParentProcess(p *Process, doInit bool) (parentProces
}
}
func
(
c
*
linuxContainer
)
commandTemplate
(
p
*
Process
,
childPipe
,
rootDir
*
os
.
File
)
(
*
exec
.
Cmd
,
error
)
{
func
(
c
*
linuxContainer
)
commandTemplate
(
p
*
Process
,
childPipe
,
rootDir
*
os
.
File
)
(
*
exec
.
Cmd
,
error
)
{
cmd
:=
&
exec
.
Cmd
{
cmd
:=
exec
.
Command
(
c
.
initArgs
[
0
],
c
.
initArgs
[
1
:
]
...
)
Path
:
c
.
initPath
,
Args
:
c
.
initArgs
,
}
cmd
.
Stdin
=
p
.
Stdin
cmd
.
Stdin
=
p
.
Stdin
cmd
.
Stdout
=
p
.
Stdout
cmd
.
Stdout
=
p
.
Stdout
cmd
.
Stderr
=
p
.
Stderr
cmd
.
Stderr
=
p
.
Stderr
...
@@ -447,7 +445,7 @@ func (c *linuxContainer) Pause() error {
...
@@ -447,7 +445,7 @@ func (c *linuxContainer) Pause() error {
c
:
c
,
c
:
c
,
})
})
}
}
return
newGenericError
(
fmt
.
Errorf
(
"container not running: %s"
,
status
),
ContainerNotRunning
)
return
newGenericError
(
fmt
.
Errorf
(
"container not running
or created
: %s"
,
status
),
ContainerNotRunning
)
}
}
func
(
c
*
linuxContainer
)
Resume
()
error
{
func
(
c
*
linuxContainer
)
Resume
()
error
{
...
@@ -1049,6 +1047,8 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
...
@@ -1049,6 +1047,8 @@ func (c *linuxContainer) criuNotifications(resp *criurpc.CriuResp, process *Proc
});
err
!=
nil
{
});
err
!=
nil
{
return
err
return
err
}
}
// create a timestamp indicating when the restored checkpoint was started
c
.
created
=
time
.
Now
()
.
UTC
()
if
_
,
err
:=
c
.
updateState
(
r
);
err
!=
nil
{
if
_
,
err
:=
c
.
updateState
(
r
);
err
!=
nil
{
return
err
return
err
}
}
...
...
vendor/github.com/opencontainers/runc/libcontainer/factory_linux.go
View file @
07bd42a1
...
@@ -6,7 +6,6 @@ import (
...
@@ -6,7 +6,6 @@ import (
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"os"
"os"
"os/exec"
"path/filepath"
"path/filepath"
"regexp"
"regexp"
"runtime/debug"
"runtime/debug"
...
@@ -33,32 +32,9 @@ var (
...
@@ -33,32 +32,9 @@ var (
)
)
// InitArgs returns an options func to configure a LinuxFactory with the
// InitArgs returns an options func to configure a LinuxFactory with the
// provided init arguments.
// provided init
binary path and
arguments.
func
InitArgs
(
args
...
string
)
func
(
*
LinuxFactory
)
error
{
func
InitArgs
(
args
...
string
)
func
(
*
LinuxFactory
)
error
{
return
func
(
l
*
LinuxFactory
)
error
{
return
func
(
l
*
LinuxFactory
)
error
{
name
:=
args
[
0
]
if
filepath
.
Base
(
name
)
==
name
{
if
lp
,
err
:=
exec
.
LookPath
(
name
);
err
==
nil
{
name
=
lp
}
}
else
{
abs
,
err
:=
filepath
.
Abs
(
name
)
if
err
!=
nil
{
return
err
}
name
=
abs
}
l
.
InitPath
=
"/proc/self/exe"
l
.
InitArgs
=
append
([]
string
{
name
},
args
[
1
:
]
...
)
return
nil
}
}
// InitPath returns an options func to configure a LinuxFactory with the
// provided absolute path to the init binary and arguements.
func
InitPath
(
path
string
,
args
...
string
)
func
(
*
LinuxFactory
)
error
{
return
func
(
l
*
LinuxFactory
)
error
{
l
.
InitPath
=
path
l
.
InitArgs
=
args
l
.
InitArgs
=
args
return
nil
return
nil
}
}
...
@@ -122,10 +98,10 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) {
...
@@ -122,10 +98,10 @@ func New(root string, options ...func(*LinuxFactory) error) (Factory, error) {
}
}
l
:=
&
LinuxFactory
{
l
:=
&
LinuxFactory
{
Root
:
root
,
Root
:
root
,
InitArgs
:
[]
string
{
"/proc/self/exe"
,
"init"
},
Validator
:
validate
.
New
(),
Validator
:
validate
.
New
(),
CriuPath
:
"criu"
,
CriuPath
:
"criu"
,
}
}
InitArgs
(
os
.
Args
[
0
],
"init"
)(
l
)
Cgroupfs
(
l
)
Cgroupfs
(
l
)
for
_
,
opt
:=
range
options
{
for
_
,
opt
:=
range
options
{
if
err
:=
opt
(
l
);
err
!=
nil
{
if
err
:=
opt
(
l
);
err
!=
nil
{
...
@@ -140,9 +116,6 @@ type LinuxFactory struct {
...
@@ -140,9 +116,6 @@ type LinuxFactory struct {
// Root directory for the factory to store state.
// Root directory for the factory to store state.
Root
string
Root
string
// InitPath is the absolute path to the init binary.
InitPath
string
// InitArgs are arguments for calling the init responsibilities for spawning
// InitArgs are arguments for calling the init responsibilities for spawning
// a container.
// a container.
InitArgs
[]
string
InitArgs
[]
string
...
@@ -202,7 +175,6 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
...
@@ -202,7 +175,6 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
id
:
id
,
id
:
id
,
root
:
containerRoot
,
root
:
containerRoot
,
config
:
config
,
config
:
config
,
initPath
:
l
.
InitPath
,
initArgs
:
l
.
InitArgs
,
initArgs
:
l
.
InitArgs
,
criuPath
:
l
.
CriuPath
,
criuPath
:
l
.
CriuPath
,
cgroupManager
:
l
.
NewCgroupsManager
(
config
.
Cgroups
,
nil
),
cgroupManager
:
l
.
NewCgroupsManager
(
config
.
Cgroups
,
nil
),
...
@@ -216,7 +188,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
...
@@ -216,7 +188,7 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
return
nil
,
newGenericError
(
fmt
.
Errorf
(
"invalid root"
),
ConfigInvalid
)
return
nil
,
newGenericError
(
fmt
.
Errorf
(
"invalid root"
),
ConfigInvalid
)
}
}
containerRoot
:=
filepath
.
Join
(
l
.
Root
,
id
)
containerRoot
:=
filepath
.
Join
(
l
.
Root
,
id
)
state
,
err
:=
l
.
loadState
(
containerRoot
)
state
,
err
:=
l
.
loadState
(
containerRoot
,
id
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -230,7 +202,6 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
...
@@ -230,7 +202,6 @@ func (l *LinuxFactory) Load(id string) (Container, error) {
initProcessStartTime
:
state
.
InitProcessStartTime
,
initProcessStartTime
:
state
.
InitProcessStartTime
,
id
:
id
,
id
:
id
,
config
:
&
state
.
Config
,
config
:
&
state
.
Config
,
initPath
:
l
.
InitPath
,
initArgs
:
l
.
InitArgs
,
initArgs
:
l
.
InitArgs
,
criuPath
:
l
.
CriuPath
,
criuPath
:
l
.
CriuPath
,
cgroupManager
:
l
.
NewCgroupsManager
(
state
.
Config
.
Cgroups
,
state
.
CgroupPaths
),
cgroupManager
:
l
.
NewCgroupsManager
(
state
.
Config
.
Cgroups
,
state
.
CgroupPaths
),
...
@@ -252,17 +223,21 @@ func (l *LinuxFactory) Type() string {
...
@@ -252,17 +223,21 @@ func (l *LinuxFactory) Type() string {
// This is a low level implementation detail of the reexec and should not be consumed externally
// This is a low level implementation detail of the reexec and should not be consumed externally
func
(
l
*
LinuxFactory
)
StartInitialization
()
(
err
error
)
{
func
(
l
*
LinuxFactory
)
StartInitialization
()
(
err
error
)
{
var
pipefd
,
rootfd
int
var
pipefd
,
rootfd
int
for
k
,
v
:=
range
map
[
string
]
*
int
{
for
_
,
pair
:=
range
[]
struct
{
"_LIBCONTAINER_INITPIPE"
:
&
pipefd
,
k
string
"_LIBCONTAINER_STATEDIR"
:
&
rootfd
,
v
*
int
}{
{
"_LIBCONTAINER_INITPIPE"
,
&
pipefd
},
{
"_LIBCONTAINER_STATEDIR"
,
&
rootfd
},
}
{
}
{
s
:=
os
.
Getenv
(
k
)
s
:=
os
.
Getenv
(
pair
.
k
)
i
,
err
:=
strconv
.
Atoi
(
s
)
i
,
err
:=
strconv
.
Atoi
(
s
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"unable to convert %s=%s to int"
,
k
,
s
)
return
fmt
.
Errorf
(
"unable to convert %s=%s to int"
,
pair
.
k
,
s
)
}
}
*
v
=
i
*
pair
.
v
=
i
}
}
var
(
var
(
pipe
=
os
.
NewFile
(
uintptr
(
pipefd
),
"pipe"
)
pipe
=
os
.
NewFile
(
uintptr
(
pipefd
),
"pipe"
)
...
@@ -302,11 +277,11 @@ func (l *LinuxFactory) StartInitialization() (err error) {
...
@@ -302,11 +277,11 @@ func (l *LinuxFactory) StartInitialization() (err error) {
return
i
.
Init
()
return
i
.
Init
()
}
}
func
(
l
*
LinuxFactory
)
loadState
(
root
string
)
(
*
State
,
error
)
{
func
(
l
*
LinuxFactory
)
loadState
(
root
,
id
string
)
(
*
State
,
error
)
{
f
,
err
:=
os
.
Open
(
filepath
.
Join
(
root
,
stateFilename
))
f
,
err
:=
os
.
Open
(
filepath
.
Join
(
root
,
stateFilename
))
if
err
!=
nil
{
if
err
!=
nil
{
if
os
.
IsNotExist
(
err
)
{
if
os
.
IsNotExist
(
err
)
{
return
nil
,
newGenericError
(
err
,
ContainerNotExists
)
return
nil
,
newGenericError
(
fmt
.
Errorf
(
"container %q does not exist"
,
id
)
,
ContainerNotExists
)
}
}
return
nil
,
newGenericError
(
err
,
SystemError
)
return
nil
,
newGenericError
(
err
,
SystemError
)
}
}
...
...
vendor/github.com/opencontainers/runc/libcontainer/generic_error.go
View file @
07bd42a1
...
@@ -67,9 +67,6 @@ func newSystemErrorWithCause(err error, cause string) Error {
...
@@ -67,9 +67,6 @@ func newSystemErrorWithCause(err error, cause string) Error {
// stack frames skipped. This is only to be called by the other functions for
// stack frames skipped. This is only to be called by the other functions for
// formatting the error.
// formatting the error.
func
createSystemError
(
err
error
,
cause
string
)
Error
{
func
createSystemError
(
err
error
,
cause
string
)
Error
{
if
le
,
ok
:=
err
.
(
Error
);
ok
{
return
le
}
gerr
:=
&
genericError
{
gerr
:=
&
genericError
{
Timestamp
:
time
.
Now
(),
Timestamp
:
time
.
Now
(),
Err
:
err
,
Err
:
err
,
...
...
vendor/github.com/opencontainers/runc/libcontainer/init_linux.go
View file @
07bd42a1
...
@@ -144,7 +144,7 @@ func finalizeNamespace(config *initConfig) error {
...
@@ -144,7 +144,7 @@ func finalizeNamespace(config *initConfig) error {
}
}
if
config
.
Cwd
!=
""
{
if
config
.
Cwd
!=
""
{
if
err
:=
syscall
.
Chdir
(
config
.
Cwd
);
err
!=
nil
{
if
err
:=
syscall
.
Chdir
(
config
.
Cwd
);
err
!=
nil
{
return
err
return
fmt
.
Errorf
(
"chdir to cwd (%q) set in config.json failed: %v"
,
config
.
Cwd
,
err
)
}
}
}
}
return
nil
return
nil
...
...
vendor/github.com/opencontainers/runc/libcontainer/label/label_selinux.go
View file @
07bd42a1
...
@@ -129,7 +129,7 @@ func Relabel(path string, fileLabel string, shared bool) error {
...
@@ -129,7 +129,7 @@ func Relabel(path string, fileLabel string, shared bool) error {
exclude_paths
:=
map
[
string
]
bool
{
"/"
:
true
,
"/usr"
:
true
,
"/etc"
:
true
}
exclude_paths
:=
map
[
string
]
bool
{
"/"
:
true
,
"/usr"
:
true
,
"/etc"
:
true
}
if
exclude_paths
[
path
]
{
if
exclude_paths
[
path
]
{
return
fmt
.
Errorf
(
"
R
elabeling of %s is not allowed"
,
path
)
return
fmt
.
Errorf
(
"
SELinux r
elabeling of %s is not allowed"
,
path
)
}
}
if
shared
{
if
shared
{
...
@@ -137,7 +137,10 @@ func Relabel(path string, fileLabel string, shared bool) error {
...
@@ -137,7 +137,10 @@ func Relabel(path string, fileLabel string, shared bool) error {
c
[
"level"
]
=
"s0"
c
[
"level"
]
=
"s0"
fileLabel
=
c
.
Get
()
fileLabel
=
c
.
Get
()
}
}
return
selinux
.
Chcon
(
path
,
fileLabel
,
true
)
if
err
:=
selinux
.
Chcon
(
path
,
fileLabel
,
true
);
err
!=
nil
{
return
fmt
.
Errorf
(
"SELinux relabeling of %s is not allowed: %q"
,
path
,
err
)
}
return
nil
}
}
// GetPidLabel will return the label of the process running with the specified pid
// GetPidLabel will return the label of the process running with the specified pid
...
...
vendor/github.com/opencontainers/runc/libcontainer/process_linux.go
View file @
07bd42a1
...
@@ -32,7 +32,7 @@ type parentProcess interface {
...
@@ -32,7 +32,7 @@ type parentProcess interface {
// wait waits on the process returning the process state.
// wait waits on the process returning the process state.
wait
()
(
*
os
.
ProcessState
,
error
)
wait
()
(
*
os
.
ProcessState
,
error
)
// startTime return
'
s the process start time.
// startTime returns the process start time.
startTime
()
(
string
,
error
)
startTime
()
(
string
,
error
)
signal
(
os
.
Signal
)
error
signal
(
os
.
Signal
)
error
...
@@ -356,7 +356,7 @@ loop:
...
@@ -356,7 +356,7 @@ loop:
}
}
}
}
if
!
sentRun
{
if
!
sentRun
{
return
newSystemErrorWithCause
(
ierr
,
"container init
failed
"
)
return
newSystemErrorWithCause
(
ierr
,
"container init"
)
}
}
if
p
.
config
.
Config
.
Namespaces
.
Contains
(
configs
.
NEWNS
)
&&
!
sentResume
{
if
p
.
config
.
Config
.
Namespaces
.
Contains
(
configs
.
NEWNS
)
&&
!
sentResume
{
return
newSystemError
(
fmt
.
Errorf
(
"could not synchronise after executing prestart hooks with container process"
))
return
newSystemError
(
fmt
.
Errorf
(
"could not synchronise after executing prestart hooks with container process"
))
...
...
vendor/github.com/opencontainers/runc/libcontainer/rootfs_linux.go
View file @
07bd42a1
...
@@ -50,7 +50,7 @@ func setupRootfs(config *configs.Config, console *linuxConsole, pipe io.ReadWrit
...
@@ -50,7 +50,7 @@ func setupRootfs(config *configs.Config, console *linuxConsole, pipe io.ReadWrit
}
}
}
}
if
err
:=
mountToRootfs
(
m
,
config
.
Rootfs
,
config
.
MountLabel
);
err
!=
nil
{
if
err
:=
mountToRootfs
(
m
,
config
.
Rootfs
,
config
.
MountLabel
);
err
!=
nil
{
return
newSystemErrorWithCausef
(
err
,
"mounting %q to rootfs %q
"
,
m
.
Destination
,
config
.
Rootfs
)
return
newSystemErrorWithCausef
(
err
,
"mounting %q to rootfs %q
at %q"
,
m
.
Source
,
config
.
Rootfs
,
m
.
Destination
)
}
}
for
_
,
postcmd
:=
range
m
.
PostmountCmds
{
for
_
,
postcmd
:=
range
m
.
PostmountCmds
{
...
@@ -270,7 +270,7 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
...
@@ -270,7 +270,7 @@ func mountToRootfs(m *configs.Mount, rootfs, mountLabel string) error {
}
}
func
getCgroupMounts
(
m
*
configs
.
Mount
)
([]
*
configs
.
Mount
,
error
)
{
func
getCgroupMounts
(
m
*
configs
.
Mount
)
([]
*
configs
.
Mount
,
error
)
{
mounts
,
err
:=
cgroups
.
GetCgroupMounts
()
mounts
,
err
:=
cgroups
.
GetCgroupMounts
(
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -306,9 +306,6 @@ func getCgroupMounts(m *configs.Mount) ([]*configs.Mount, error) {
...
@@ -306,9 +306,6 @@ func getCgroupMounts(m *configs.Mount) ([]*configs.Mount, error) {
// checkMountDestination checks to ensure that the mount destination is not over the top of /proc.
// checkMountDestination checks to ensure that the mount destination is not over the top of /proc.
// dest is required to be an abs path and have any symlinks resolved before calling this function.
// dest is required to be an abs path and have any symlinks resolved before calling this function.
func
checkMountDestination
(
rootfs
,
dest
string
)
error
{
func
checkMountDestination
(
rootfs
,
dest
string
)
error
{
if
libcontainerUtils
.
CleanPath
(
rootfs
)
==
libcontainerUtils
.
CleanPath
(
dest
)
{
return
fmt
.
Errorf
(
"mounting into / is prohibited"
)
}
invalidDestinations
:=
[]
string
{
invalidDestinations
:=
[]
string
{
"/proc"
,
"/proc"
,
}
}
...
@@ -320,6 +317,8 @@ func checkMountDestination(rootfs, dest string) error {
...
@@ -320,6 +317,8 @@ func checkMountDestination(rootfs, dest string) error {
"/proc/diskstats"
,
"/proc/diskstats"
,
"/proc/meminfo"
,
"/proc/meminfo"
,
"/proc/stat"
,
"/proc/stat"
,
"/proc/swaps"
,
"/proc/uptime"
,
"/proc/net/dev"
,
"/proc/net/dev"
,
}
}
for
_
,
valid
:=
range
validDestinations
{
for
_
,
valid
:=
range
validDestinations
{
...
@@ -663,10 +662,16 @@ func remountReadonly(path string) error {
...
@@ -663,10 +662,16 @@ func remountReadonly(path string) error {
return
fmt
.
Errorf
(
"unable to mount %s as readonly max retries reached"
,
path
)
return
fmt
.
Errorf
(
"unable to mount %s as readonly max retries reached"
,
path
)
}
}
// maskFile bind mounts /dev/null over the top of the specified path inside a container
// maskPath masks the top of the specified path inside a container to avoid
// to avoid security issues from processes reading information from non-namespace aware mounts ( proc/kcore ).
// security issues from processes reading information from non-namespace aware
func
maskFile
(
path
string
)
error
{
// mounts ( proc/kcore ).
// For files, maskPath bind mounts /dev/null over the top of the specified path.
// For directories, maskPath mounts read-only tmpfs over the top of the specified path.
func
maskPath
(
path
string
)
error
{
if
err
:=
syscall
.
Mount
(
"/dev/null"
,
path
,
""
,
syscall
.
MS_BIND
,
""
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
:=
syscall
.
Mount
(
"/dev/null"
,
path
,
""
,
syscall
.
MS_BIND
,
""
);
err
!=
nil
&&
!
os
.
IsNotExist
(
err
)
{
if
err
==
syscall
.
ENOTDIR
{
return
syscall
.
Mount
(
"tmpfs"
,
path
,
"tmpfs"
,
syscall
.
MS_RDONLY
,
""
)
}
return
err
return
err
}
}
return
nil
return
nil
...
...
vendor/github.com/opencontainers/runc/libcontainer/standard_init_linux.go
View file @
07bd42a1
...
@@ -108,7 +108,7 @@ func (l *linuxStandardInit) Init() error {
...
@@ -108,7 +108,7 @@ func (l *linuxStandardInit) Init() error {
}
}
}
}
for
_
,
path
:=
range
l
.
config
.
Config
.
MaskPaths
{
for
_
,
path
:=
range
l
.
config
.
Config
.
MaskPaths
{
if
err
:=
mask
File
(
path
);
err
!=
nil
{
if
err
:=
mask
Path
(
path
);
err
!=
nil
{
return
err
return
err
}
}
}
}
...
...
vendor/github.com/opencontainers/runc/libcontainer/system/syscall_linux_386.go
View file @
07bd42a1
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
// Setuid sets the uid of the calling thread to the specified uid.
// Setuid sets the uid of the calling thread to the specified uid.
func
Setuid
(
uid
int
)
(
err
error
)
{
func
Setuid
(
uid
int
)
(
err
error
)
{
_
,
_
,
e1
:=
syscall
.
RawSyscall
(
syscall
.
SYS_SETUID
,
uintptr
(
uid
),
0
,
0
)
_
,
_
,
e1
:=
syscall
.
RawSyscall
(
syscall
.
SYS_SETUID
32
,
uintptr
(
uid
),
0
,
0
)
if
e1
!=
0
{
if
e1
!=
0
{
err
=
e1
err
=
e1
}
}
...
...
vendor/github.com/opencontainers/runc/libcontainer/utils/utils.go
View file @
07bd42a1
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"path/filepath"
"path/filepath"
"strings"
"strings"
"syscall"
"syscall"
"unsafe"
)
)
const
(
const
(
...
@@ -119,3 +120,7 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
...
@@ -119,3 +120,7 @@ func Annotations(labels []string) (bundle string, userAnnotations map[string]str
}
}
return
return
}
}
func
GetIntSize
()
int
{
return
int
(
unsafe
.
Sizeof
(
1
))
}
vendor/github.com/syndtr/gocapability/capability/capability.go
View file @
07bd42a1
...
@@ -10,42 +10,42 @@ package capability
...
@@ -10,42 +10,42 @@ package capability
type
Capabilities
interface
{
type
Capabilities
interface
{
// Get check whether a capability present in the given
// Get check whether a capability present in the given
// capabilities set. The 'which' value should be one of EFFECTIVE,
// capabilities set. The 'which' value should be one of EFFECTIVE,
// PERMITTED, INHERITABLE
or BOUNDING
.
// PERMITTED, INHERITABLE
, BOUNDING or AMBIENT
.
Get
(
which
CapType
,
what
Cap
)
bool
Get
(
which
CapType
,
what
Cap
)
bool
// Empty check whether all capability bits of the given capabilities
// Empty check whether all capability bits of the given capabilities
// set are zero. The 'which' value should be one of EFFECTIVE,
// set are zero. The 'which' value should be one of EFFECTIVE,
// PERMITTED, INHERITABLE
or BOUNDING
.
// PERMITTED, INHERITABLE
, BOUNDING or AMBIENT
.
Empty
(
which
CapType
)
bool
Empty
(
which
CapType
)
bool
// Full check whether all capability bits of the given capabilities
// Full check whether all capability bits of the given capabilities
// set are one. The 'which' value should be one of EFFECTIVE,
// set are one. The 'which' value should be one of EFFECTIVE,
// PERMITTED, INHERITABLE
or BOUNDING
.
// PERMITTED, INHERITABLE
, BOUNDING or AMBIENT
.
Full
(
which
CapType
)
bool
Full
(
which
CapType
)
bool
// Set sets capabilities of the given capabilities sets. The
// Set sets capabilities of the given capabilities sets. The
// 'which' value should be one or combination (OR'ed) of EFFECTIVE,
// 'which' value should be one or combination (OR'ed) of EFFECTIVE,
// PERMITTED, INHERITABLE
or BOUNDING
.
// PERMITTED, INHERITABLE
, BOUNDING or AMBIENT
.
Set
(
which
CapType
,
caps
...
Cap
)
Set
(
which
CapType
,
caps
...
Cap
)
// Unset unsets capabilities of the given capabilities sets. The
// Unset unsets capabilities of the given capabilities sets. The
// 'which' value should be one or combination (OR'ed) of EFFECTIVE,
// 'which' value should be one or combination (OR'ed) of EFFECTIVE,
// PERMITTED, INHERITABLE
or BOUNDING
.
// PERMITTED, INHERITABLE
, BOUNDING or AMBIENT
.
Unset
(
which
CapType
,
caps
...
Cap
)
Unset
(
which
CapType
,
caps
...
Cap
)
// Fill sets all bits of the given capabilities kind to one. The
// Fill sets all bits of the given capabilities kind to one. The
// 'kind' value should be one or combination (OR'ed) of CAPS
or
// 'kind' value should be one or combination (OR'ed) of CAPS
,
// BOUNDS.
// BOUNDS
or AMBS
.
Fill
(
kind
CapType
)
Fill
(
kind
CapType
)
// Clear sets all bits of the given capabilities kind to zero. The
// Clear sets all bits of the given capabilities kind to zero. The
// 'kind' value should be one or combination (OR'ed) of CAPS
or
// 'kind' value should be one or combination (OR'ed) of CAPS
,
// BOUNDS.
// BOUNDS
or AMBS
.
Clear
(
kind
CapType
)
Clear
(
kind
CapType
)
// String return current capabilities state of the given capabilities
// String return current capabilities state of the given capabilities
// set as string. The 'which' value should be one of EFFECTIVE,
// set as string. The 'which' value should be one of EFFECTIVE,
// PERMITTED, INHERITABLE
or BOUNDING.
// PERMITTED, INHERITABLE
BOUNDING or AMBIENT
StringCap
(
which
CapType
)
string
StringCap
(
which
CapType
)
string
// String return current capabilities state as string.
// String return current capabilities state as string.
...
...
vendor/github.com/syndtr/gocapability/capability/capability_linux.go
View file @
07bd42a1
...
@@ -235,9 +235,10 @@ func (c *capsV1) Apply(kind CapType) error {
...
@@ -235,9 +235,10 @@ func (c *capsV1) Apply(kind CapType) error {
}
}
type
capsV3
struct
{
type
capsV3
struct
{
hdr
capHeader
hdr
capHeader
data
[
2
]
capData
data
[
2
]
capData
bounds
[
2
]
uint32
bounds
[
2
]
uint32
ambient
[
2
]
uint32
}
}
func
(
c
*
capsV3
)
Get
(
which
CapType
,
what
Cap
)
bool
{
func
(
c
*
capsV3
)
Get
(
which
CapType
,
what
Cap
)
bool
{
...
@@ -256,6 +257,8 @@ func (c *capsV3) Get(which CapType, what Cap) bool {
...
@@ -256,6 +257,8 @@ func (c *capsV3) Get(which CapType, what Cap) bool {
return
(
1
<<
uint
(
what
))
&
c
.
data
[
i
]
.
inheritable
!=
0
return
(
1
<<
uint
(
what
))
&
c
.
data
[
i
]
.
inheritable
!=
0
case
BOUNDING
:
case
BOUNDING
:
return
(
1
<<
uint
(
what
))
&
c
.
bounds
[
i
]
!=
0
return
(
1
<<
uint
(
what
))
&
c
.
bounds
[
i
]
!=
0
case
AMBIENT
:
return
(
1
<<
uint
(
what
))
&
c
.
ambient
[
i
]
!=
0
}
}
return
false
return
false
...
@@ -275,6 +278,9 @@ func (c *capsV3) getData(which CapType, dest []uint32) {
...
@@ -275,6 +278,9 @@ func (c *capsV3) getData(which CapType, dest []uint32) {
case
BOUNDING
:
case
BOUNDING
:
dest
[
0
]
=
c
.
bounds
[
0
]
dest
[
0
]
=
c
.
bounds
[
0
]
dest
[
1
]
=
c
.
bounds
[
1
]
dest
[
1
]
=
c
.
bounds
[
1
]
case
AMBIENT
:
dest
[
0
]
=
c
.
ambient
[
0
]
dest
[
1
]
=
c
.
ambient
[
1
]
}
}
}
}
...
@@ -313,6 +319,9 @@ func (c *capsV3) Set(which CapType, caps ...Cap) {
...
@@ -313,6 +319,9 @@ func (c *capsV3) Set(which CapType, caps ...Cap) {
if
which
&
BOUNDING
!=
0
{
if
which
&
BOUNDING
!=
0
{
c
.
bounds
[
i
]
|=
1
<<
uint
(
what
)
c
.
bounds
[
i
]
|=
1
<<
uint
(
what
)
}
}
if
which
&
AMBIENT
!=
0
{
c
.
ambient
[
i
]
|=
1
<<
uint
(
what
)
}
}
}
}
}
...
@@ -336,6 +345,9 @@ func (c *capsV3) Unset(which CapType, caps ...Cap) {
...
@@ -336,6 +345,9 @@ func (c *capsV3) Unset(which CapType, caps ...Cap) {
if
which
&
BOUNDING
!=
0
{
if
which
&
BOUNDING
!=
0
{
c
.
bounds
[
i
]
&=
^
(
1
<<
uint
(
what
))
c
.
bounds
[
i
]
&=
^
(
1
<<
uint
(
what
))
}
}
if
which
&
AMBIENT
!=
0
{
c
.
ambient
[
i
]
&=
^
(
1
<<
uint
(
what
))
}
}
}
}
}
...
@@ -353,6 +365,10 @@ func (c *capsV3) Fill(kind CapType) {
...
@@ -353,6 +365,10 @@ func (c *capsV3) Fill(kind CapType) {
c
.
bounds
[
0
]
=
0xffffffff
c
.
bounds
[
0
]
=
0xffffffff
c
.
bounds
[
1
]
=
0xffffffff
c
.
bounds
[
1
]
=
0xffffffff
}
}
if
kind
&
AMBS
==
AMBS
{
c
.
ambient
[
0
]
=
0xffffffff
c
.
ambient
[
1
]
=
0xffffffff
}
}
}
func
(
c
*
capsV3
)
Clear
(
kind
CapType
)
{
func
(
c
*
capsV3
)
Clear
(
kind
CapType
)
{
...
@@ -369,6 +385,10 @@ func (c *capsV3) Clear(kind CapType) {
...
@@ -369,6 +385,10 @@ func (c *capsV3) Clear(kind CapType) {
c
.
bounds
[
0
]
=
0
c
.
bounds
[
0
]
=
0
c
.
bounds
[
1
]
=
0
c
.
bounds
[
1
]
=
0
}
}
if
kind
&
AMBS
==
AMBS
{
c
.
ambient
[
0
]
=
0
c
.
ambient
[
1
]
=
0
}
}
}
func
(
c
*
capsV3
)
StringCap
(
which
CapType
)
(
ret
string
)
{
func
(
c
*
capsV3
)
StringCap
(
which
CapType
)
(
ret
string
)
{
...
@@ -410,6 +430,10 @@ func (c *capsV3) Load() (err error) {
...
@@ -410,6 +430,10 @@ func (c *capsV3) Load() (err error) {
fmt
.
Sscanf
(
line
[
4
:
],
"nd: %08x%08x"
,
&
c
.
bounds
[
1
],
&
c
.
bounds
[
0
])
fmt
.
Sscanf
(
line
[
4
:
],
"nd: %08x%08x"
,
&
c
.
bounds
[
1
],
&
c
.
bounds
[
0
])
break
break
}
}
if
strings
.
HasPrefix
(
line
,
"CapA"
)
{
fmt
.
Sscanf
(
line
[
4
:
],
"mb: %08x%08x"
,
&
c
.
ambient
[
1
],
&
c
.
ambient
[
0
])
break
}
}
}
f
.
Close
()
f
.
Close
()
...
@@ -442,7 +466,25 @@ func (c *capsV3) Apply(kind CapType) (err error) {
...
@@ -442,7 +466,25 @@ func (c *capsV3) Apply(kind CapType) (err error) {
}
}
if
kind
&
CAPS
==
CAPS
{
if
kind
&
CAPS
==
CAPS
{
return
capset
(
&
c
.
hdr
,
&
c
.
data
[
0
])
err
=
capset
(
&
c
.
hdr
,
&
c
.
data
[
0
])
if
err
!=
nil
{
return
}
}
if
kind
&
AMBS
==
AMBS
{
for
i
:=
Cap
(
0
);
i
<=
CAP_LAST_CAP
;
i
++
{
action
:=
pr_CAP_AMBIENT_LOWER
if
c
.
Get
(
AMBIENT
,
i
)
{
action
=
pr_CAP_AMBIENT_RAISE
}
err
:=
prctl
(
pr_CAP_AMBIENT
,
action
,
uintptr
(
i
),
0
,
0
)
// Ignore EINVAL as not supported on kernels before 4.3
if
errno
,
ok
:=
err
.
(
syscall
.
Errno
);
ok
&&
errno
==
syscall
.
EINVAL
{
err
=
nil
continue
}
}
}
}
return
return
...
...
vendor/github.com/syndtr/gocapability/capability/enum.go
View file @
07bd42a1
...
@@ -20,6 +20,8 @@ func (c CapType) String() string {
...
@@ -20,6 +20,8 @@ func (c CapType) String() string {
return
"bounding"
return
"bounding"
case
CAPS
:
case
CAPS
:
return
"caps"
return
"caps"
case
AMBIENT
:
return
"ambient"
}
}
return
"unknown"
return
"unknown"
}
}
...
@@ -29,9 +31,11 @@ const (
...
@@ -29,9 +31,11 @@ const (
PERMITTED
PERMITTED
INHERITABLE
INHERITABLE
BOUNDING
BOUNDING
AMBIENT
CAPS
=
EFFECTIVE
|
PERMITTED
|
INHERITABLE
CAPS
=
EFFECTIVE
|
PERMITTED
|
INHERITABLE
BOUNDS
=
BOUNDING
BOUNDS
=
BOUNDING
AMBS
=
AMBIENT
)
)
//go:generate go run enumgen/gen.go
//go:generate go run enumgen/gen.go
...
...
vendor/github.com/syndtr/gocapability/capability/syscall_linux.go
View file @
07bd42a1
...
@@ -38,6 +38,15 @@ func capset(hdr *capHeader, data *capData) (err error) {
...
@@ -38,6 +38,15 @@ func capset(hdr *capHeader, data *capData) (err error) {
return
return
}
}
// not yet in syscall
const
(
pr_CAP_AMBIENT
=
47
pr_CAP_AMBIENT_IS_SET
=
uintptr
(
1
)
pr_CAP_AMBIENT_RAISE
=
uintptr
(
2
)
pr_CAP_AMBIENT_LOWER
=
uintptr
(
3
)
pr_CAP_AMBIENT_CLEAR_ALL
=
uintptr
(
4
)
)
func
prctl
(
option
int
,
arg2
,
arg3
,
arg4
,
arg5
uintptr
)
(
err
error
)
{
func
prctl
(
option
int
,
arg2
,
arg3
,
arg4
,
arg5
uintptr
)
(
err
error
)
{
_
,
_
,
e1
:=
syscall
.
Syscall6
(
syscall
.
SYS_PRCTL
,
uintptr
(
option
),
arg2
,
arg3
,
arg4
,
arg5
,
0
)
_
,
_
,
e1
:=
syscall
.
Syscall6
(
syscall
.
SYS_PRCTL
,
uintptr
(
option
),
arg2
,
arg3
,
arg4
,
arg5
,
0
)
if
e1
!=
0
{
if
e1
!=
0
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment