github.com/lazyboychen7/engine@v17.12.1-ce-rc2+incompatible/daemon/listeners/group_unix.go (about) 1 // +build !windows 2 3 package listeners 4 5 import ( 6 "fmt" 7 "strconv" 8 9 "github.com/opencontainers/runc/libcontainer/user" 10 "github.com/pkg/errors" 11 ) 12 13 const defaultSocketGroup = "docker" 14 15 func lookupGID(name string) (int, error) { 16 groupFile, err := user.GetGroupPath() 17 if err != nil { 18 return -1, errors.Wrap(err, "error looking up groups") 19 } 20 groups, err := user.ParseGroupFileFilter(groupFile, func(g user.Group) bool { 21 return g.Name == name || strconv.Itoa(g.Gid) == name 22 }) 23 if err != nil { 24 return -1, errors.Wrapf(err, "error parsing groups for %s", name) 25 } 26 if len(groups) > 0 { 27 return groups[0].Gid, nil 28 } 29 gid, err := strconv.Atoi(name) 30 if err == nil { 31 return gid, nil 32 } 33 return -1, fmt.Errorf("group %s not found", name) 34 }