mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #7702 from LK4D4/fix_panic_on_bad_device_#7701
Handle error from GetDevice early
This commit is contained in:
commit
89f64712fa
2 changed files with 16 additions and 2 deletions
|
@ -230,10 +230,10 @@ func populateCommand(c *Container, env []string) error {
|
||||||
userSpecifiedDevices := make([]*devices.Device, len(c.hostConfig.Devices))
|
userSpecifiedDevices := make([]*devices.Device, len(c.hostConfig.Devices))
|
||||||
for i, deviceMapping := range c.hostConfig.Devices {
|
for i, deviceMapping := range c.hostConfig.Devices {
|
||||||
device, err := devices.GetDevice(deviceMapping.PathOnHost, deviceMapping.CgroupPermissions)
|
device, err := devices.GetDevice(deviceMapping.PathOnHost, deviceMapping.CgroupPermissions)
|
||||||
device.Path = deviceMapping.PathInContainer
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("error gathering device information while adding custom device %s", err)
|
return fmt.Errorf("error gathering device information while adding custom device %q: %s", deviceMapping.PathOnHost, err)
|
||||||
}
|
}
|
||||||
|
device.Path = deviceMapping.PathInContainer
|
||||||
userSpecifiedDevices[i] = device
|
userSpecifiedDevices[i] = device
|
||||||
}
|
}
|
||||||
allowedDevices := append(devices.DefaultAllowedDevices, userSpecifiedDevices...)
|
allowedDevices := append(devices.DefaultAllowedDevices, userSpecifiedDevices...)
|
||||||
|
|
|
@ -1630,3 +1630,17 @@ func TestWriteResolvFileAndNotCommit(t *testing.T) {
|
||||||
|
|
||||||
logDone("run - write to /etc/resolv.conf and not commited")
|
logDone("run - write to /etc/resolv.conf and not commited")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestRunWithBadDevice(t *testing.T) {
|
||||||
|
name := "baddevice"
|
||||||
|
cmd := exec.Command(dockerBinary, "run", "--name", name, "--device", "/etc", "busybox", "true")
|
||||||
|
out, _, err := runCommandWithOutput(cmd)
|
||||||
|
if err == nil {
|
||||||
|
t.Fatal("Run should fail with bad device")
|
||||||
|
}
|
||||||
|
expected := `"/etc": not a device node`
|
||||||
|
if !strings.Contains(out, expected) {
|
||||||
|
t.Fatalf("Output should contain %q, actual out: %q", expected, out)
|
||||||
|
}
|
||||||
|
logDone("run - error with bad device")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue