Skip to content

Commit

Permalink
Cleanup error handling for runc CGroups implementation (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
agners authored Aug 9, 2022
1 parent b9db176 commit 9bdfc14
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cgroup/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,17 @@ func (d cgroup) AddDevicesAllowed(containerID string, permission string) (bool,
permissions := []string{permission}
resources, err := CreateDeviceUpdateResources(permissions)
if err != nil {
error := fmt.Errorf("Error calling runc for '%s': %s", containerID, err)
error := fmt.Errorf("Error creating device resources for '%s': %s", containerID, err)
logging.Error.Printf("%s", error)
return false, dbus.MakeFailedError(error)
}

fmt.Printf("Container resources update %#v\n", resources)

cmd := exec.Command("runc", "--root", "/var/run/docker/runtime-runc/moby/", "update", "--resources", "-", containerID)
fmt.Printf("Calling command %v", cmd.Args)

// Pass resources as OCI LinuxResources JSON object
stdin, err := cmd.StdinPipe()
if err != nil {
error := fmt.Errorf("Error calling runc for '%s': %s", containerID, err)
error := fmt.Errorf("Error creating stdin pipe for '%s': %s", containerID, err)
logging.Error.Printf("%s", error)
return false, dbus.MakeFailedError(error)
}
Expand All @@ -67,7 +64,7 @@ func (d cgroup) AddDevicesAllowed(containerID string, permission string) (bool,
return false, dbus.MakeFailedError(error)
}

logging.Info.Printf("Permission '%s', granted for Container '%s'", containerID, permission)
logging.Info.Printf("Permission '%s', granted for Container '%s' via runc", containerID, permission)
return true, nil
} else {
// Make sure path is relative to cgroupFSDockerDevices
Expand All @@ -94,7 +91,7 @@ func (d cgroup) AddDevicesAllowed(containerID string, permission string) (bool,
return false, dbus.MakeFailedError(fmt.Errorf("Can't write CGroup permission '%s': %s", permission, err))
}

logging.Info.Printf("Permission '%s', granted for Container '%s'", containerID, permission)
logging.Info.Printf("Permission '%s', granted for Container '%s' via CGroup devices.allow", containerID, permission)
return true, nil
}
}
Expand Down

0 comments on commit 9bdfc14

Please sign in to comment.