Skip to content

Commit

Permalink
runc list: use standard os/user
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
kolyshkin committed Sep 28, 2023
1 parent 6b7df6e commit b166280
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b166280

Please sign in to comment.