<div dir="ltr">What about something like following?<div><br></div><div><div>diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c</div><div>index 480c4f5..eb99e5a 100644</div><div>--- a/src/lxc/lxccontainer.c</div><div>

+++ b/src/lxc/lxccontainer.c</div><div>@@ -508,7 +508,7 @@ static bool lxcapi_create(struct lxc_container *c, char *t, char *const argv[])</div><div> <span class="" style="white-space:pre">        </span>int len, nargs = 0;</div>

<div> <span class="" style="white-space:pre">  </span>char **newargv;</div><div> </div><div>-<span class="" style="white-space:pre">  </span>if (!c)</div><div>+<span class="" style="white-space:pre">   </span>if (!c || access(c->lxc_conf->rootfs.path, F_OK) == 0) </div>

<div> <span class="" style="white-space:pre">          </span>return false;</div><div> </div><div> <span class="" style="white-space:pre">   </span>len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;</div><div>

@@ -523,9 +523,6 @@ static bool lxcapi_create(struct lxc_container *c, char *t, char *const argv[])</div><div> <span class="" style="white-space:pre">           </span>goto out;</div><div> <span class="" style="white-space:pre">        </span>}</div>

<div> </div><div>-<span class="" style="white-space:pre">  </span>if (!create_container_dir(c))</div><div>-<span class="" style="white-space:pre">             </span>goto out;</div><div>-</div><div> <span class="" style="white-space:pre">        </span>if (!c->save_config(c, NULL)) {</div>

<div> <span class="" style="white-space:pre">          </span>ERROR("failed to save starting configuration for %s\n", c->name);</div><div> <span class="" style="white-space:pre">           </span>goto out;</div><div>@@ -767,6 +764,9 @@ static bool lxcapi_save_config(struct lxc_container *c, const char *alt_file)</div>

<div> <span class="" style="white-space:pre">                  </span>return false;</div><div> <span class="" style="white-space:pre">            </span>}</div><div> </div><div>+<span class="" style="white-space:pre">        </span>if (!create_container_dir(c))</div>

<div>+<span class="" style="white-space:pre">           </span>return false;</div><div>+</div><div> <span class="" style="white-space:pre">    </span>FILE *fout = fopen(alt_file, "w");</div><div> <span class="" style="white-space:pre">     </span>if (!fout)</div>

<div> <span class="" style="white-space:pre">          </span>return false;</div><div>@@ -785,7 +785,7 @@ static bool lxcapi_destroy(struct lxc_container *c)</div><div> <span class="" style="white-space:pre">      </span>pid_t pid;</div>

<div> <span class="" style="white-space:pre">  </span>int ret, status;</div><div> </div><div>-<span class="" style="white-space:pre"> </span>if (!c)</div><div>+<span class="" style="white-space:pre">   </span>if (!c || access(c->lxc_conf->rootfs.path, F_OK) != 0)</div>

<div> <span class="" style="white-space:pre">          </span>return false;</div><div> </div><div> <span class="" style="white-space:pre">   </span>pid = fork();</div></div><div><br></div><div><br></div><div style>and this is how it behaves with it;</div>

<div style><br></div><div style><div>caglar@qgq:~$ cat test.py </div><div>import lxc</div><div>c = lxc.Container("abcdef")</div><div>print (c.set_config_item("lxc.utsname", "abcdef"))</div><div>

print (c.save_config())</div><div>print (c.create("ubuntu"))</div><div>print (c.create("ubuntu"))</div><div>print (c.destroy())</div><div>print (c.destroy())</div><div><br></div><div><div>caglar@qgq:~$ sudo python3 test.py </div>

<div>True<br></div><div>True</div><div>True</div><div>False</div><div>True</div><div>False</div></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Sun, Mar 31, 2013 at 7:26 PM, S.Çağlar Onur <span dir="ltr"><<a href="mailto:caglar@10ur.org" target="_blank">caglar@10ur.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Stéphane,<br><br>Hmm, then I believe there is another bug somewhere cause here is what happens with your ordering;<div>

<br><div><div>caglar@qgq:~/Project/lxc$ sudo python3</div><div>Python 3.2.3 (default, Oct 19 2012, 19:53:16) </div>
<div>[GCC 4.7.2] on linux2</div><div>Type "help", "copyright", "credits" or "license" for more information.</div><div>>>> import lxc</div><div>__main__:1: Warning: The python-lxc API isn't yet stable and may change at any point in the future.</div>

<div class="im">
<div>>>> c = lxc.Container("abcdef")</div><div>>>> c.set_config_item("lxc.utsname", "blah")</div></div><div>True</div><div>>>> c.set_config_item("lxc.utsname", "abcdef")</div>


<div>True</div><div>>>> c.save_config()</div><div>False</div><div><div>>>> c.config_file_name</div><div>'/var/lib/lxc/abcdef/config'</div></div><div><br></div><div>so it looks like save_config don't work if the container directory is not there and as long as I see only create calls create_container_dir to do that. </div>


<div><br></div><div>Maybe correct way to handle that is to call create_container_dir from save_config as well but checking the rootfs directory's existence from create/destrory?</div><div><br></div><div>
Best,</div><div><div class="h5"><br><br>On Sun, Mar 31, 2013 at 5:22 PM, Stéphane Graber <<a href="mailto:stgraber@ubuntu.com" target="_blank">stgraber@ubuntu.com</a>> wrote:<br>><br>> On 03/31/2013 04:22 PM, S.Çağlar Onur wrote:<br>

> > From: "S.Çağlar Onur" <<a href="mailto:caglar@10ur.org" target="_blank">caglar@10ur.org</a>><br>
> ><br>> > 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.<br>> ><br>> >>> c = lxc.Container("r")<br>


> >>>> c.create("ubuntu")<br>> > True<br>> >>>> c.create("ubuntu")<br>> > True<br>> >>>> c.create("ubuntu")<br>> > True<br>> >>>> c.create("ubuntu")<br>


> > True<br>> >>>> c.create("ubuntu")<br>> >>>> c.destroy()<br>> > True<br>> >>>> c.destroy()<br>> > lxc-destroy: 'r' does not exist<br>> > False<br>


> >>>> c.destroy()<br>> > lxc-destroy: 'r' does not exist<br>> > False<br>> ><br>> > New behaviour<br>> ><br>> >>>> c = lxc.Container("r")<br>

> >>>> c.create('ubuntu')<br>
> > True<br>> >>>> c.create('ubuntu')<br>> > False<br>> >>>> c.destroy()<br>> > True<br>> >>>> c.destroy()<br>> > False<br>> >>>><br>


><br>><br>> Won't this break the following?<br>> c = lxc.Container("abcdef")<br>> c.set_config_item("lxc.utsname", "blah")<br>> c.save_config()<br>> c.create("ubuntu")<br>


><br>> I personally always considered ".create()" to mean "generate a new<br>> rootfs" which doesn't at all mean "generate a new config file".<br>><br>> ".destroy()" on the other hand destroys everything, including the config.<br>


><br>><br>><br>> > Signed-off-by: S.Çağlar Onur <<a href="mailto:caglar@10ur.org" target="_blank">caglar@10ur.org</a>><br>> > ---<br>> >  src/lxc/lxccontainer.c |    4 ++--<br>> >  1 file changed, 2 insertions(+), 2 deletions(-)<br>


> ><br>> > diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c<br>> > index 480c4f5..7a11c85 100644<br>> > --- a/src/lxc/lxccontainer.c<br>> > +++ b/src/lxc/lxccontainer.c<br>> > @@ -508,7 +508,7 @@ static bool lxcapi_create(struct lxc_container *c, char *t, char *const argv[])<br>


> >       int len, nargs = 0;<br>> >       char **newargv;<br>> ><br>> > -     if (!c)<br>> > +     if (!c || lxcapi_is_defined(c))<br>> >               return false;<br>> ><br>> >       len = strlen(LXCTEMPLATEDIR) + strlen(t) + strlen("/lxc-") + 1;<br>


> > @@ -785,7 +785,7 @@ static bool lxcapi_destroy(struct lxc_container *c)<br>> >       pid_t pid;<br>> >       int ret, status;<br>> ><br>> > -     if (!c)<br>> > +     if (!c || !lxcapi_is_defined(c))<br>


> >               return false;<br>> ><br>> >       pid = fork();<br>> ><br>><br>><br>> --<br>> Stéphane Graber<br>> Ubuntu developer<br>> <a href="http://www.ubuntu.com" target="_blank">http://www.ubuntu.com</a><br>


><br>><br></div></div>> ------------------------------------------------------------------------------<br>> Own the Future-Intel(R) Level Up Game Demo Contest 2013<br>> Rise to greatness in Intel's independent game demo contest. Compete<br>


> for recognition, cash, and the chance to get your game on Steam.<br>> $5K grand prize plus 10 genre and skill prizes. Submit your demo<br>> by 6/6/13. <a href="http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2" target="_blank">http://altfarm.mediaplex.com/ad/ck/12124-176961-30367-2</a><br>


> _______________________________________________<br>> Lxc-devel mailing list<br>> <a href="mailto:Lxc-devel@lists.sourceforge.net" target="_blank">Lxc-devel@lists.sourceforge.net</a><br>> <a href="https://lists.sourceforge.net/lists/listinfo/lxc-devel" target="_blank">https://lists.sourceforge.net/lists/listinfo/lxc-devel</a><br>


><br><br><br><br>--<br>S.Çağlar Onur <<a href="mailto:caglar@10ur.org" target="_blank">caglar@10ur.org</a>><br></div></div></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br>S.Çağlar Onur <<a href="mailto:caglar@10ur.org">caglar@10ur.org</a>>
</div>