Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Add support for * for device name in --device #460

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions oci/devices_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,26 @@ func deviceCgroup(d *devices.Device) specs.LinuxDeviceCgroup {
func DevicesFromPath(pathOnHost, pathInContainer, cgroupPermissions string) (devs []specs.LinuxDevice, devPermissions []specs.LinuxDeviceCgroup, err error) {
resolvedPathOnHost := pathOnHost

// Only wildcard * is supported
if strings.HasSuffix(resolvedPathOnHost, "*") {
devicePaths, _ := filepath.Glob(resolvedPathOnHost)
var err error
var dev *devices.Device
for _, devicePath := range devicePaths {
dev, err = devices.DeviceFromPath(devicePath, cgroupPermissions)
if err != nil {
return nil, nil, fmt.Errorf("no device %q %s", devicePath, err)
}
devs = append(devs, Device(dev))
devPermissions = append(devPermissions, deviceCgroup(dev))
}
if len(devs) > 0 {
return devs, devPermissions, nil
} else {
return devs, devPermissions, fmt.Errorf("error gathering device information while adding custom device %q: %s", pathOnHost, err)
}
}

// check if it is a symbolic link
if src, e := os.Lstat(pathOnHost); e == nil && src.Mode()&os.ModeSymlink == os.ModeSymlink {
if linkedPathOnHost, e := filepath.EvalSymlinks(pathOnHost); e == nil {
Expand Down