[lxc-devel] [PATCH] API shouldn't be calling create for already defined containers or destroy for non defined ones.
S.Çağlar Onur
caglar at 10ur.org
Sun Mar 31 20:22:08 UTC 2013
From: "S.Çağlar Onur" <caglar at 10ur.org>
Currently it behaves like following which might be confusing for the code that checks the return value of those calls to determine whether operation completed successfully or not.
>> c = lxc.Container("r")
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
True
>>> c.create("ubuntu")
>>> c.destroy()
True
>>> c.destroy()
lxc-destroy: 'r' does not exist
False
>>> c.destroy()
lxc-destroy: 'r' does not exist
False
New behaviour
>>> c = lxc.Container("r")
>>> c.create('ubuntu')
True
>>> c.create('ubuntu')
False
>>> c.destroy()
True
>>> c.destroy()
False
>>>
Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>
---
src/lxc/lxccontainer.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 480c4f5..7a11c85 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -508,7 +508,7 @@ static bool lxcapi_create(struct lxc_container *c, char *t, char *const argv[])
int len, nargs = 0;
char **newargv;
- if (!c)
+ if (!c || lxcapi_is_defined(c))
return false;
len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;
@@ -785,7 +785,7 @@ static bool lxcapi_destroy(struct lxc_container *c)
pid_t pid;
int ret, status;
- if (!c)
+ if (!c || !lxcapi_is_defined(c))
return false;
pid = fork();
--
1.7.10.4
More information about the lxc-devel
mailing list