diff --git a/libcontainer/console_windows.go b/libcontainer/console_windows.go index c61e866a5d5..55e48d5155e 100644 --- a/libcontainer/console_windows.go +++ b/libcontainer/console_windows.go @@ -1,5 +1,9 @@ package libcontainer +import ( + "os" +) + // newConsole returns an initialized console that can be used within a container func newConsole() (Console, error) { return &windowsConsole{}, nil @@ -13,6 +17,10 @@ func (c *windowsConsole) Fd() uintptr { return 0 } +func (c *windowsConsole) File() *os.File { + return nil +} + func (c *windowsConsole) Path() string { return "" } diff --git a/libcontainer/user/lookup.go b/libcontainer/user/lookup.go index bf491c89c2a..95e9eebc0b0 100644 --- a/libcontainer/user/lookup.go +++ b/libcontainer/user/lookup.go @@ -2,8 +2,6 @@ package user import ( "errors" - - "golang.org/x/sys/unix" ) var ( @@ -37,13 +35,6 @@ func lookupUser(filter func(u User) bool) (User, error) { return users[0], nil } -// CurrentUser looks up the current user by their user id in /etc/passwd. If the -// user cannot be found (or there is no /etc/passwd file on the filesystem), -// then CurrentUser returns an error. -func CurrentUser() (User, error) { - return LookupUid(unix.Getuid()) -} - // LookupUser looks up a user by their username in /etc/passwd. If the user // cannot be found (or there is no /etc/passwd file on the filesystem), then // LookupUser returns an error. @@ -85,13 +76,6 @@ func lookupGroup(filter func(g Group) bool) (Group, error) { return groups[0], nil } -// CurrentGroup looks up the current user's group by their primary group id's -// entry in /etc/passwd. If the group cannot be found (or there is no -// /etc/group file on the filesystem), then CurrentGroup returns an error. -func CurrentGroup() (Group, error) { - return LookupGid(unix.Getgid()) -} - // LookupGroup looks up a group by its name in /etc/group. If the group cannot // be found (or there is no /etc/group file on the filesystem), then LookupGroup // returns an error. diff --git a/libcontainer/user/lookup_unix.go b/libcontainer/user/lookup_unix.go index 758b734c225..c2bb9ec90da 100644 --- a/libcontainer/user/lookup_unix.go +++ b/libcontainer/user/lookup_unix.go @@ -5,6 +5,8 @@ package user import ( "io" "os" + + "golang.org/x/sys/unix" ) // Unix-specific path to the passwd and group formatted files. @@ -28,3 +30,17 @@ func GetGroupPath() (string, error) { func GetGroup() (io.ReadCloser, error) { return os.Open(unixGroupPath) } + +// CurrentUser looks up the current user by their user id in /etc/passwd. If the +// user cannot be found (or there is no /etc/passwd file on the filesystem), +// then CurrentUser returns an error. +func CurrentUser() (User, error) { + return LookupUid(unix.Getuid()) +} + +// CurrentGroup looks up the current user's group by their primary group id's +// entry in /etc/passwd. If the group cannot be found (or there is no +// /etc/group file on the filesystem), then CurrentGroup returns an error. +func CurrentGroup() (Group, error) { + return LookupGid(unix.Getgid()) +} diff --git a/libcontainer/user/lookup_unsupported.go b/libcontainer/user/lookup_unsupported.go index 7217948870c..213b2d34246 100644 --- a/libcontainer/user/lookup_unsupported.go +++ b/libcontainer/user/lookup_unsupported.go @@ -19,3 +19,11 @@ func GetGroupPath() (string, error) { func GetGroup() (io.ReadCloser, error) { return nil, ErrUnsupported } + +func CurrentUser() (User, error) { + return LookupUid(-1) +} + +func CurrentGroup() (Group, error) { + return LookupGid(-1) +} diff --git a/libcontainer/utils/utils.go b/libcontainer/utils/utils.go index baa54c9ba2c..83702603f7a 100644 --- a/libcontainer/utils/utils.go +++ b/libcontainer/utils/utils.go @@ -9,8 +9,6 @@ import ( "path/filepath" "strings" "unsafe" - - "golang.org/x/sys/unix" ) const ( @@ -40,15 +38,6 @@ func ResolveRootfs(uncleanRootfs string) (string, error) { return filepath.EvalSymlinks(rootfs) } -// ExitStatus returns the correct exit status for a process based on if it -// was signaled or exited cleanly -func ExitStatus(status unix.WaitStatus) int { - if status.Signaled() { - return exitSignalOffset + int(status.Signal()) - } - return status.ExitStatus() -} - // WriteJSON writes the provided struct v to w using standard json marshaling func WriteJSON(w io.Writer, v interface{}) error { data, err := json.Marshal(v) diff --git a/libcontainer/utils/utils_unix.go b/libcontainer/utils/utils_unix.go index c96088988a6..830e5bb1d1c 100644 --- a/libcontainer/utils/utils_unix.go +++ b/libcontainer/utils/utils_unix.go @@ -42,3 +42,12 @@ func NewSockPair(name string) (parent *os.File, child *os.File, err error) { } return os.NewFile(uintptr(fds[1]), name+"-p"), os.NewFile(uintptr(fds[0]), name+"-c"), nil } + +// ExitStatus returns the correct exit status for a process based on if it +// was signaled or exited cleanly +func ExitStatus(status unix.WaitStatus) int { + if status.Signaled() { + return exitSignalOffset + int(status.Signal()) + } + return status.ExitStatus() +}