mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
dbb9fc03ae
Only some libcontainer packages can be built on non-linux platforms
(not that it make sense, but at least go build succeeds). Let's call
these "good" packages.
For all other packages (i.e. ones that fail to build with GOOS other
than linux), it does not make sense to have linux build tag (as they
are broken already, and thus are not and can not be used on anything
other than Linux).
Remove linux build tag for all non-"good" packages.
This was mostly done by the following script, with just a few manual
fixes on top.
function list_good_pkgs() {
for pkg in $(find . -type d -print); do
GOOS=freebsd go build $pkg 2>/dev/null \
&& GOOS=solaris go build $pkg 2>/dev/null \
&& echo $pkg
done | sed -e 's|^./||' | tr '\n' '|' | sed -e 's/|$//'
}
function remove_tag() {
sed -i -e '\|^// +build linux$|d' $1
go fmt $1
}
SKIP="^("$(list_good_pkgs)")"
for f in $(git ls-files . | grep .go$); do
if echo $f | grep -qE "$SKIP"; then
echo skip $f
continue
fi
echo proc $f
remove_tag $f
done
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
package fs
|
|
|
|
import (
|
|
"math"
|
|
"strconv"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/cgroups"
|
|
"github.com/opencontainers/runc/libcontainer/cgroups/fscommon"
|
|
"github.com/opencontainers/runc/libcontainer/configs"
|
|
)
|
|
|
|
type PidsGroup struct{}
|
|
|
|
func (s *PidsGroup) Name() string {
|
|
return "pids"
|
|
}
|
|
|
|
func (s *PidsGroup) Apply(path string, d *cgroupData) error {
|
|
return join(path, d.pid)
|
|
}
|
|
|
|
func (s *PidsGroup) Set(path string, r *configs.Resources) error {
|
|
if r.PidsLimit != 0 {
|
|
// "max" is the fallback value.
|
|
limit := "max"
|
|
|
|
if r.PidsLimit > 0 {
|
|
limit = strconv.FormatInt(r.PidsLimit, 10)
|
|
}
|
|
|
|
if err := cgroups.WriteFile(path, "pids.max", limit); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (s *PidsGroup) GetStats(path string, stats *cgroups.Stats) error {
|
|
if !cgroups.PathExists(path) {
|
|
return nil
|
|
}
|
|
current, err := fscommon.GetCgroupParamUint(path, "pids.current")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
max, err := fscommon.GetCgroupParamUint(path, "pids.max")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
// If no limit is set, read from pids.max returns "max", which is
|
|
// converted to MaxUint64 by GetCgroupParamUint. Historically, we
|
|
// represent "no limit" for pids as 0, thus this conversion.
|
|
if max == math.MaxUint64 {
|
|
max = 0
|
|
}
|
|
|
|
stats.PidsStats.Current = current
|
|
stats.PidsStats.Limit = max
|
|
return nil
|
|
}
|