runc list: use standard os/user

Switch from github.com/moby/sys/user to Go stdlib os/user
(which has both libc-backed and pure Go implementations).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2023-08-28 17:55:28 -07:00
parent 52f702af56
commit ec9b0b5f72

12
list.go
View File

@@ -5,11 +5,12 @@ import (
"errors"
"fmt"
"os"
"os/user"
"strconv"
"syscall"
"text/tabwriter"
"time"
"github.com/moby/sys/user"
"github.com/opencontainers/runc/libcontainer"
"github.com/opencontainers/runc/libcontainer/utils"
"github.com/urfave/cli"
@@ -136,9 +137,10 @@ func getContainers(context *cli.Context) ([]containerState, error) {
}
// This cast is safe on Linux.
uid := st.Sys().(*syscall.Stat_t).Uid
owner, err := user.LookupUid(int(uid))
if err != nil {
owner.Name = fmt.Sprintf("#%d", uid)
owner := "#" + strconv.Itoa(int(uid))
u, err := user.LookupId(owner[1:])
if err == nil {
owner = u.Username
}
container, err := libcontainer.Load(root, item.Name())
@@ -170,7 +172,7 @@ func getContainers(context *cli.Context) ([]containerState, error) {
Rootfs: state.BaseState.Config.Rootfs,
Created: state.BaseState.Created,
Annotations: annotations,
Owner: owner.Name,
Owner: owner,
})
}
return s, nil