[lxc-devel] [lxd/master] Check for errors when removing devices during cleanup

dhedberg on Github lxc-bot at linuxcontainers.org
Thu Apr 28 09:37:57 UTC 2016


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 647 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20160428/38834c4f/attachment.bin>
-------------- next part --------------
From 2aa4e1057c0a0560bbbc779677edd71f3dfb30d2 Mon Sep 17 00:00:00 2001
From: David Hedberg <david.hedberg at gmail.com>
Date: Thu, 28 Apr 2016 11:29:41 +0200
Subject: [PATCH] Check for errors when removing devices during cleanup

removeUnixDevices() and removeDiskDevices() both abort after the first
failure. We need to check for errors in cleanup to avoid running
rm -rf * on any remaining devices.
---
 lxd/container_lxc.go | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/lxd/container_lxc.go b/lxd/container_lxc.go
index 70f483f..58a60e5 100644
--- a/lxd/container_lxc.go
+++ b/lxd/container_lxc.go
@@ -1763,10 +1763,14 @@ func (c *containerLXC) Restore(sourceContainer container) error {
 	return nil
 }
 
-func (c *containerLXC) cleanup() {
+func (c *containerLXC) cleanup() error {
 	// Unmount any leftovers
-	c.removeUnixDevices()
-	c.removeDiskDevices()
+	if err := c.removeUnixDevices(); err != nil {
+		return err
+	}
+	if err := c.removeDiskDevices(); err != nil {
+		return err
+	}
 
 	// Remove the security profiles
 	AADeleteProfile(c)
@@ -1777,6 +1781,8 @@ func (c *containerLXC) cleanup() {
 
 	// Remove the shmounts path
 	os.RemoveAll(shared.VarPath("shmounts", c.Name()))
+
+	return nil
 }
 
 func (c *containerLXC) Delete() error {
@@ -1792,7 +1798,9 @@ func (c *containerLXC) Delete() error {
 		}
 
 		// Clean things up
-		c.cleanup()
+		if err := c.cleanup(); err != nil {
+			return err
+		}
 
 		// Delete the container from disk
 		if shared.PathExists(c.Path()) {
@@ -1823,7 +1831,9 @@ func (c *containerLXC) Rename(newName string) error {
 	}
 
 	// Clean things up
-	c.cleanup()
+	if err := c.cleanup(); err != nil {
+		return err
+	}
 
 	// Rename the logging path
 	os.RemoveAll(shared.LogPath(newName))


More information about the lxc-devel mailing list