Update runc vendor
Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
parent
a1affdb4ff
commit
ddc53c9cd2
@ -20,7 +20,7 @@ github.com/gogo/protobuf v1.0.0
|
|||||||
github.com/gogo/googleapis 08a7655d27152912db7aaf4f983275eaf8d128ef
|
github.com/gogo/googleapis 08a7655d27152912db7aaf4f983275eaf8d128ef
|
||||||
github.com/golang/protobuf v1.1.0
|
github.com/golang/protobuf v1.1.0
|
||||||
github.com/opencontainers/runtime-spec d810dbc60d8c5aeeb3d054bd1132fab2121968ce # v1.0.1-43-gd810dbc
|
github.com/opencontainers/runtime-spec d810dbc60d8c5aeeb3d054bd1132fab2121968ce # v1.0.1-43-gd810dbc
|
||||||
github.com/opencontainers/runc 69663f0bd4b60df09991c08812a60108003fa340
|
github.com/opencontainers/runc 20aff4f0488c6d4b8df4d85b4f63f1f704c11abd
|
||||||
github.com/sirupsen/logrus v1.0.0
|
github.com/sirupsen/logrus v1.0.0
|
||||||
github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
|
github.com/urfave/cli 7bc6a0acffa589f415f88aca16cc1de5ffd66f9c
|
||||||
golang.org/x/net b3756b4b77d7b13260a0a2ec658753cf48922eac
|
golang.org/x/net b3756b4b77d7b13260a0a2ec658753cf48922eac
|
||||||
|
5
vendor/github.com/opencontainers/runc/libcontainer/configs/config.go
generated
vendored
5
vendor/github.com/opencontainers/runc/libcontainer/configs/config.go
generated
vendored
@ -141,9 +141,10 @@ type Config struct {
|
|||||||
|
|
||||||
// OomScoreAdj specifies the adjustment to be made by the kernel when calculating oom scores
|
// OomScoreAdj specifies the adjustment to be made by the kernel when calculating oom scores
|
||||||
// for a process. Valid values are between the range [-1000, '1000'], where processes with
|
// for a process. Valid values are between the range [-1000, '1000'], where processes with
|
||||||
// higher scores are preferred for being killed.
|
// higher scores are preferred for being killed. If it is unset then we don't touch the current
|
||||||
|
// value.
|
||||||
// More information about kernel oom score calculation here: https://lwn.net/Articles/317814/
|
// More information about kernel oom score calculation here: https://lwn.net/Articles/317814/
|
||||||
OomScoreAdj int `json:"oom_score_adj"`
|
OomScoreAdj *int `json:"oom_score_adj,omitempty"`
|
||||||
|
|
||||||
// UidMappings is an array of User ID mappings for User Namespaces
|
// UidMappings is an array of User ID mappings for User Namespaces
|
||||||
UidMappings []IDMap `json:"uid_mappings"`
|
UidMappings []IDMap `json:"uid_mappings"`
|
||||||
|
5
vendor/github.com/opencontainers/runc/libcontainer/devices/devices.go
generated
vendored
5
vendor/github.com/opencontainers/runc/libcontainer/devices/devices.go
generated
vendored
@ -30,8 +30,9 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
devNumber = stat.Rdev
|
devNumber = uint64(stat.Rdev)
|
||||||
major = unix.Major(devNumber)
|
major = unix.Major(devNumber)
|
||||||
|
minor = unix.Minor(devNumber)
|
||||||
)
|
)
|
||||||
if major == 0 {
|
if major == 0 {
|
||||||
return nil, ErrNotADevice
|
return nil, ErrNotADevice
|
||||||
@ -51,7 +52,7 @@ func DeviceFromPath(path, permissions string) (*configs.Device, error) {
|
|||||||
Type: devType,
|
Type: devType,
|
||||||
Path: path,
|
Path: path,
|
||||||
Major: int64(major),
|
Major: int64(major),
|
||||||
Minor: int64(unix.Minor(devNumber)),
|
Minor: int64(minor),
|
||||||
Permissions: permissions,
|
Permissions: permissions,
|
||||||
FileMode: os.FileMode(mode),
|
FileMode: os.FileMode(mode),
|
||||||
Uid: stat.Uid,
|
Uid: stat.Uid,
|
||||||
|
63
vendor/github.com/opencontainers/runc/libcontainer/nsenter/nsexec.c
generated
vendored
63
vendor/github.com/opencontainers/runc/libcontainer/nsenter/nsexec.c
generated
vendored
@ -505,7 +505,8 @@ void join_namespaces(char *nslist)
|
|||||||
|
|
||||||
ns->fd = fd;
|
ns->fd = fd;
|
||||||
ns->ns = nsflag(namespace);
|
ns->ns = nsflag(namespace);
|
||||||
strncpy(ns->path, path, PATH_MAX);
|
strncpy(ns->path, path, PATH_MAX - 1);
|
||||||
|
ns->path[PATH_MAX - 1] = '\0';
|
||||||
} while ((namespace = strtok_r(NULL, ",", &saveptr)) != NULL);
|
} while ((namespace = strtok_r(NULL, ",", &saveptr)) != NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -678,17 +679,15 @@ void nsexec(void)
|
|||||||
/*
|
/*
|
||||||
* Enable setgroups(2) if we've been asked to. But we also
|
* Enable setgroups(2) if we've been asked to. But we also
|
||||||
* have to explicitly disable setgroups(2) if we're
|
* have to explicitly disable setgroups(2) if we're
|
||||||
* creating a rootless container (this is required since
|
* creating a rootless container for single-entry mapping.
|
||||||
* Linux 3.19).
|
* i.e. config.is_setgroup == false.
|
||||||
|
* (this is required since Linux 3.19).
|
||||||
|
*
|
||||||
|
* For rootless multi-entry mapping, config.is_setgroup shall be true and
|
||||||
|
* newuidmap/newgidmap shall be used.
|
||||||
*/
|
*/
|
||||||
if (config.is_rootless && config.is_setgroup) {
|
|
||||||
kill(child, SIGKILL);
|
|
||||||
bail("cannot allow setgroup in an unprivileged user namespace setup");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.is_setgroup)
|
if (config.is_rootless && !config.is_setgroup)
|
||||||
update_setgroups(child, SETGROUPS_ALLOW);
|
|
||||||
if (config.is_rootless)
|
|
||||||
update_setgroups(child, SETGROUPS_DENY);
|
update_setgroups(child, SETGROUPS_DENY);
|
||||||
|
|
||||||
/* Set up mappings. */
|
/* Set up mappings. */
|
||||||
@ -809,25 +808,30 @@ void nsexec(void)
|
|||||||
if (config.namespaces)
|
if (config.namespaces)
|
||||||
join_namespaces(config.namespaces);
|
join_namespaces(config.namespaces);
|
||||||
|
|
||||||
/*
|
|
||||||
* Unshare all of the namespaces. Now, it should be noted that this
|
|
||||||
* ordering might break in the future (especially with rootless
|
|
||||||
* containers). But for now, it's not possible to split this into
|
|
||||||
* CLONE_NEWUSER + [the rest] because of some RHEL SELinux issues.
|
|
||||||
*
|
|
||||||
* Note that we don't merge this with clone() because there were
|
|
||||||
* some old kernel versions where clone(CLONE_PARENT | CLONE_NEWPID)
|
|
||||||
* was broken, so we'll just do it the long way anyway.
|
|
||||||
*/
|
|
||||||
if (unshare(config.cloneflags) < 0)
|
|
||||||
bail("failed to unshare namespaces");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deal with user namespaces first. They are quite special, as they
|
* Deal with user namespaces first. They are quite special, as they
|
||||||
* affect our ability to unshare other namespaces and are used as
|
* affect our ability to unshare other namespaces and are used as
|
||||||
* context for privilege checks.
|
* context for privilege checks.
|
||||||
|
*
|
||||||
|
* We don't unshare all namespaces in one go. The reason for this
|
||||||
|
* is that, while the kernel documentation may claim otherwise,
|
||||||
|
* there are certain cases where unsharing all namespaces at once
|
||||||
|
* will result in namespace objects being owned incorrectly.
|
||||||
|
* Ideally we should just fix these kernel bugs, but it's better to
|
||||||
|
* be safe than sorry, and fix them separately.
|
||||||
|
*
|
||||||
|
* A specific case of this is that the SELinux label of the
|
||||||
|
* internal kern-mount that mqueue uses will be incorrect if the
|
||||||
|
* UTS namespace is cloned before the USER namespace is mapped.
|
||||||
|
* I've also heard of similar problems with the network namespace
|
||||||
|
* in some scenarios. This also mirrors how LXC deals with this
|
||||||
|
* problem.
|
||||||
*/
|
*/
|
||||||
if (config.cloneflags & CLONE_NEWUSER) {
|
if (config.cloneflags & CLONE_NEWUSER) {
|
||||||
|
if (unshare(CLONE_NEWUSER) < 0)
|
||||||
|
bail("failed to unshare user namespace");
|
||||||
|
config.cloneflags &= ~CLONE_NEWUSER;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We don't have the privileges to do any mapping here (see the
|
* We don't have the privileges to do any mapping here (see the
|
||||||
* clone_parent rant). So signal our parent to hook us up.
|
* clone_parent rant). So signal our parent to hook us up.
|
||||||
@ -853,8 +857,21 @@ void nsexec(void)
|
|||||||
if (prctl(PR_SET_DUMPABLE, 0, 0, 0, 0) < 0)
|
if (prctl(PR_SET_DUMPABLE, 0, 0, 0, 0) < 0)
|
||||||
bail("failed to set process as dumpable");
|
bail("failed to set process as dumpable");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Become root in the namespace proper. */
|
||||||
|
if (setresuid(0, 0, 0) < 0)
|
||||||
|
bail("failed to become root in user namespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unshare all of the namespaces. Note that we don't merge this
|
||||||
|
* with clone() because there were some old kernel versions where
|
||||||
|
* clone(CLONE_PARENT | CLONE_NEWPID) was broken, so we'll just do
|
||||||
|
* it the long way.
|
||||||
|
*/
|
||||||
|
if (unshare(config.cloneflags) < 0)
|
||||||
|
bail("failed to unshare namespaces");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: What about non-namespace clone flags that we're dropping here?
|
* TODO: What about non-namespace clone flags that we're dropping here?
|
||||||
*
|
*
|
||||||
|
38
vendor/github.com/opencontainers/runc/libcontainer/system/linux.go
generated
vendored
38
vendor/github.com/opencontainers/runc/libcontainer/system/linux.go
generated
vendored
@ -3,13 +3,12 @@
|
|||||||
package system
|
package system
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"syscall" // only for exec
|
"syscall" // only for exec
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/libcontainer/user"
|
||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -102,34 +101,43 @@ func Setctty() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunningInUserNS detects whether we are currently running in a user namespace.
|
// RunningInUserNS detects whether we are currently running in a user namespace.
|
||||||
// Copied from github.com/lxc/lxd/shared/util.go
|
// Originally copied from github.com/lxc/lxd/shared/util.go
|
||||||
func RunningInUserNS() bool {
|
func RunningInUserNS() bool {
|
||||||
file, err := os.Open("/proc/self/uid_map")
|
uidmap, err := user.CurrentProcessUIDMap()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// This kernel-provided file only exists if user namespaces are supported
|
// This kernel-provided file only exists if user namespaces are supported
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
defer file.Close()
|
return UIDMapInUserNS(uidmap)
|
||||||
|
}
|
||||||
|
|
||||||
buf := bufio.NewReader(file)
|
func UIDMapInUserNS(uidmap []user.IDMap) bool {
|
||||||
l, _, err := buf.ReadLine()
|
|
||||||
if err != nil {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
line := string(l)
|
|
||||||
var a, b, c int64
|
|
||||||
fmt.Sscanf(line, "%d %d %d", &a, &b, &c)
|
|
||||||
/*
|
/*
|
||||||
* We assume we are in the initial user namespace if we have a full
|
* We assume we are in the initial user namespace if we have a full
|
||||||
* range - 4294967295 uids starting at uid 0.
|
* range - 4294967295 uids starting at uid 0.
|
||||||
*/
|
*/
|
||||||
if a == 0 && b == 0 && c == 4294967295 {
|
if len(uidmap) == 1 && uidmap[0].ID == 0 && uidmap[0].ParentID == 0 && uidmap[0].Count == 4294967295 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetParentNSeuid returns the euid within the parent user namespace
|
||||||
|
func GetParentNSeuid() int64 {
|
||||||
|
euid := int64(os.Geteuid())
|
||||||
|
uidmap, err := user.CurrentProcessUIDMap()
|
||||||
|
if err != nil {
|
||||||
|
// This kernel-provided file only exists if user namespaces are supported
|
||||||
|
return euid
|
||||||
|
}
|
||||||
|
for _, um := range uidmap {
|
||||||
|
if um.ID <= euid && euid <= um.ID+um.Count-1 {
|
||||||
|
return um.ParentID + euid - um.ID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return euid
|
||||||
|
}
|
||||||
|
|
||||||
// SetSubreaper sets the value i as the subreaper setting for the calling process
|
// SetSubreaper sets the value i as the subreaper setting for the calling process
|
||||||
func SetSubreaper(i int) error {
|
func SetSubreaper(i int) error {
|
||||||
return unix.Prctl(PR_SET_CHILD_SUBREAPER, uintptr(i), 0, 0, 0)
|
return unix.Prctl(PR_SET_CHILD_SUBREAPER, uintptr(i), 0, 0, 0)
|
||||||
|
18
vendor/github.com/opencontainers/runc/libcontainer/system/unsupported.go
generated
vendored
18
vendor/github.com/opencontainers/runc/libcontainer/system/unsupported.go
generated
vendored
@ -2,8 +2,26 @@
|
|||||||
|
|
||||||
package system
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/opencontainers/runc/libcontainer/user"
|
||||||
|
)
|
||||||
|
|
||||||
// RunningInUserNS is a stub for non-Linux systems
|
// RunningInUserNS is a stub for non-Linux systems
|
||||||
// Always returns false
|
// Always returns false
|
||||||
func RunningInUserNS() bool {
|
func RunningInUserNS() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UIDMapInUserNS is a stub for non-Linux systems
|
||||||
|
// Always returns false
|
||||||
|
func UIDMapInUserNS(uidmap []user.IDMap) bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetParentNSeuid returns the euid within the parent user namespace
|
||||||
|
// Always returns os.Geteuid on non-linux
|
||||||
|
func GetParentNSeuid() int {
|
||||||
|
return os.Geteuid()
|
||||||
|
}
|
||||||
|
26
vendor/github.com/opencontainers/runc/libcontainer/user/lookup_unix.go
generated
vendored
26
vendor/github.com/opencontainers/runc/libcontainer/user/lookup_unix.go
generated
vendored
@ -114,3 +114,29 @@ func CurrentUser() (User, error) {
|
|||||||
func CurrentGroup() (Group, error) {
|
func CurrentGroup() (Group, error) {
|
||||||
return LookupGid(unix.Getgid())
|
return LookupGid(unix.Getgid())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CurrentUserSubUIDs() ([]SubID, error) {
|
||||||
|
u, err := CurrentUser()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ParseSubIDFileFilter("/etc/subuid",
|
||||||
|
func(entry SubID) bool { return entry.Name == u.Name })
|
||||||
|
}
|
||||||
|
|
||||||
|
func CurrentGroupSubGIDs() ([]SubID, error) {
|
||||||
|
g, err := CurrentGroup()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return ParseSubIDFileFilter("/etc/subgid",
|
||||||
|
func(entry SubID) bool { return entry.Name == g.Name })
|
||||||
|
}
|
||||||
|
|
||||||
|
func CurrentProcessUIDMap() ([]IDMap, error) {
|
||||||
|
return ParseIDMapFile("/proc/self/uid_map")
|
||||||
|
}
|
||||||
|
|
||||||
|
func CurrentProcessGIDMap() ([]IDMap, error) {
|
||||||
|
return ParseIDMapFile("/proc/self/gid_map")
|
||||||
|
}
|
||||||
|
133
vendor/github.com/opencontainers/runc/libcontainer/user/user.go
generated
vendored
133
vendor/github.com/opencontainers/runc/libcontainer/user/user.go
generated
vendored
@ -75,12 +75,29 @@ func groupFromOS(g *user.Group) (Group, error) {
|
|||||||
return newGroup, nil
|
return newGroup, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SubID represents an entry in /etc/sub{u,g}id
|
||||||
|
type SubID struct {
|
||||||
|
Name string
|
||||||
|
SubID int64
|
||||||
|
Count int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// IDMap represents an entry in /proc/PID/{u,g}id_map
|
||||||
|
type IDMap struct {
|
||||||
|
ID int64
|
||||||
|
ParentID int64
|
||||||
|
Count int64
|
||||||
|
}
|
||||||
|
|
||||||
func parseLine(line string, v ...interface{}) {
|
func parseLine(line string, v ...interface{}) {
|
||||||
if line == "" {
|
parseParts(strings.Split(line, ":"), v...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func parseParts(parts []string, v ...interface{}) {
|
||||||
|
if len(parts) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.Split(line, ":")
|
|
||||||
for i, p := range parts {
|
for i, p := range parts {
|
||||||
// Ignore cases where we don't have enough fields to populate the arguments.
|
// Ignore cases where we don't have enough fields to populate the arguments.
|
||||||
// Some configuration files like to misbehave.
|
// Some configuration files like to misbehave.
|
||||||
@ -96,6 +113,8 @@ func parseLine(line string, v ...interface{}) {
|
|||||||
case *int:
|
case *int:
|
||||||
// "numbers", with conversion errors ignored because of some misbehaving configuration files.
|
// "numbers", with conversion errors ignored because of some misbehaving configuration files.
|
||||||
*e, _ = strconv.Atoi(p)
|
*e, _ = strconv.Atoi(p)
|
||||||
|
case *int64:
|
||||||
|
*e, _ = strconv.ParseInt(p, 10, 64)
|
||||||
case *[]string:
|
case *[]string:
|
||||||
// Comma-separated lists.
|
// Comma-separated lists.
|
||||||
if p != "" {
|
if p != "" {
|
||||||
@ -105,7 +124,7 @@ func parseLine(line string, v ...interface{}) {
|
|||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
// Someone goof'd when writing code using this function. Scream so they can hear us.
|
// Someone goof'd when writing code using this function. Scream so they can hear us.
|
||||||
panic(fmt.Sprintf("parseLine only accepts {*string, *int, *[]string} as arguments! %#v is not a pointer!", e))
|
panic(fmt.Sprintf("parseLine only accepts {*string, *int, *int64, *[]string} as arguments! %#v is not a pointer!", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -479,3 +498,111 @@ func GetAdditionalGroupsPath(additionalGroups []string, groupPath string) ([]int
|
|||||||
}
|
}
|
||||||
return GetAdditionalGroups(additionalGroups, group)
|
return GetAdditionalGroups(additionalGroups, group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ParseSubIDFile(path string) ([]SubID, error) {
|
||||||
|
subid, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer subid.Close()
|
||||||
|
return ParseSubID(subid)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseSubID(subid io.Reader) ([]SubID, error) {
|
||||||
|
return ParseSubIDFilter(subid, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseSubIDFileFilter(path string, filter func(SubID) bool) ([]SubID, error) {
|
||||||
|
subid, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer subid.Close()
|
||||||
|
return ParseSubIDFilter(subid, filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseSubIDFilter(r io.Reader, filter func(SubID) bool) ([]SubID, error) {
|
||||||
|
if r == nil {
|
||||||
|
return nil, fmt.Errorf("nil source for subid-formatted data")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
s = bufio.NewScanner(r)
|
||||||
|
out = []SubID{}
|
||||||
|
)
|
||||||
|
|
||||||
|
for s.Scan() {
|
||||||
|
if err := s.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
line := strings.TrimSpace(s.Text())
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// see: man 5 subuid
|
||||||
|
p := SubID{}
|
||||||
|
parseLine(line, &p.Name, &p.SubID, &p.Count)
|
||||||
|
|
||||||
|
if filter == nil || filter(p) {
|
||||||
|
out = append(out, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseIDMapFile(path string) ([]IDMap, error) {
|
||||||
|
r, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
return ParseIDMap(r)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseIDMap(r io.Reader) ([]IDMap, error) {
|
||||||
|
return ParseIDMapFilter(r, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseIDMapFileFilter(path string, filter func(IDMap) bool) ([]IDMap, error) {
|
||||||
|
r, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer r.Close()
|
||||||
|
return ParseIDMapFilter(r, filter)
|
||||||
|
}
|
||||||
|
|
||||||
|
func ParseIDMapFilter(r io.Reader, filter func(IDMap) bool) ([]IDMap, error) {
|
||||||
|
if r == nil {
|
||||||
|
return nil, fmt.Errorf("nil source for idmap-formatted data")
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
s = bufio.NewScanner(r)
|
||||||
|
out = []IDMap{}
|
||||||
|
)
|
||||||
|
|
||||||
|
for s.Scan() {
|
||||||
|
if err := s.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
line := strings.TrimSpace(s.Text())
|
||||||
|
if line == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// see: man 7 user_namespaces
|
||||||
|
p := IDMap{}
|
||||||
|
parseParts(strings.Fields(line), &p.ID, &p.ParentID, &p.Count)
|
||||||
|
|
||||||
|
if filter == nil || filter(p) {
|
||||||
|
out = append(out, p)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user