mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Updated cleanup code to be more explicit about ignoring errors.
Errors are shown as being ignored by assigning to the blank identifier. PiperOrigin-RevId: 218103819 Change-Id: I7cc7b9d8ac503a03de5504ebdeb99ed30a531cf2
This commit is contained in:
@@ -190,7 +190,9 @@ func (c *Cgroup) Install(res *specs.LinuxResources) error {
|
||||
// Mark that cgroup resources are owned by me.
|
||||
log.Debugf("Creating cgroup %q", c.Name)
|
||||
c.Own = true
|
||||
clean := specutils.MakeCleanup(func() { c.Uninstall() })
|
||||
// The Cleanup object cleans up partially created cgroups when an error occurs.
|
||||
// Errors occuring during cleanup itself are ignored.
|
||||
clean := specutils.MakeCleanup(func() { _ = c.Uninstall() })
|
||||
defer clean.Clean()
|
||||
|
||||
for key, ctrl := range controllers {
|
||||
|
||||
@@ -262,7 +262,9 @@ func Create(id string, spec *specs.Spec, conf *boot.Config, bundleDir, consoleSo
|
||||
Status: Creating,
|
||||
Owner: os.Getenv("USER"),
|
||||
}
|
||||
cu := specutils.MakeCleanup(func() { c.Destroy() })
|
||||
// The Cleanup object cleans up partially created containers when an error occurs.
|
||||
// Any errors occuring during cleanup itself are ignored.
|
||||
cu := specutils.MakeCleanup(func() { _ = c.Destroy() })
|
||||
defer cu.Clean()
|
||||
|
||||
// If the metadata annotations indicate that this container should be
|
||||
@@ -424,6 +426,8 @@ func Run(id string, spec *specs.Spec, conf *boot.Config, bundleDir, consoleSocke
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error creating container: %v", err)
|
||||
}
|
||||
// Clean up partially created container if an error ocurrs.
|
||||
// Any errors returned by Destroy() itself are ignored.
|
||||
defer c.Destroy()
|
||||
|
||||
if err := c.Start(conf); err != nil {
|
||||
|
||||
@@ -68,7 +68,9 @@ type Sandbox struct {
|
||||
// sandbox.
|
||||
func Create(id string, spec *specs.Spec, conf *boot.Config, bundleDir, consoleSocket, userLog string, ioFiles []*os.File) (*Sandbox, error) {
|
||||
s := &Sandbox{ID: id}
|
||||
c := specutils.MakeCleanup(func() { s.destroy() })
|
||||
// The Cleanup object cleans up partially created sandboxes when an error occurs.
|
||||
// Any errors occuring during cleanup itself are ignored.
|
||||
c := specutils.MakeCleanup(func() { _ = s.destroy() })
|
||||
defer c.Clean()
|
||||
|
||||
if cg, ok := cgroup.New(spec); ok {
|
||||
|
||||
Reference in New Issue
Block a user