Skip to content

Commit ec9b0b5

Browse files
committed
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>
1 parent 52f702a commit ec9b0b5

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

list.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import (
55
"errors"
66
"fmt"
77
"os"
8+
"os/user"
9+
"strconv"
810
"syscall"
911
"text/tabwriter"
1012
"time"
1113

12-
"github.com/moby/sys/user"
1314
"github.com/opencontainers/runc/libcontainer"
1415
"github.com/opencontainers/runc/libcontainer/utils"
1516
"github.com/urfave/cli"
@@ -136,9 +137,10 @@ func getContainers(context *cli.Context) ([]containerState, error) {
136137
}
137138
// This cast is safe on Linux.
138139
uid := st.Sys().(*syscall.Stat_t).Uid
139-
owner, err := user.LookupUid(int(uid))
140-
if err != nil {
141-
owner.Name = fmt.Sprintf("#%d", uid)
140+
owner := "#" + strconv.Itoa(int(uid))
141+
u, err := user.LookupId(owner[1:])
142+
if err == nil {
143+
owner = u.Username
142144
}
143145

144146
container, err := libcontainer.Load(root, item.Name())
@@ -170,7 +172,7 @@ func getContainers(context *cli.Context) ([]containerState, error) {
170172
Rootfs: state.BaseState.Config.Rootfs,
171173
Created: state.BaseState.Created,
172174
Annotations: annotations,
173-
Owner: owner.Name,
175+
Owner: owner,
174176
})
175177
}
176178
return s, nil

0 commit comments

Comments
 (0)