Re: [lxc-devel] [PATCH] python3: Add snapshot_* to the binding

2013-11-29 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
 Signed-off-by: Stéphane Graber stgra...@ubuntu.com

Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com

 ---
  src/python-lxc/lxc.c | 127 
 +++
  1 file changed, 127 insertions(+)
 
 diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
 index 050f6ae..f850a3d 100644
 --- a/src/python-lxc/lxc.c
 +++ b/src/python-lxc/lxc.c
 @@ -1119,6 +1119,106 @@ Container_shutdown(Container *self, PyObject *args, 
 PyObject *kwds)
  }
  
  static PyObject *
 +Container_snapshot(Container *self, PyObject *args, PyObject *kwds)
 +{
 +char *comment_path = NULL;
 +static char *kwlist[] = {comment_path, NULL};
 +int retval = 0;
 +int ret = 0;
 +char newname[20];
 +
 +if (! PyArg_ParseTupleAndKeywords(args, kwds, |s, kwlist,
 +  comment_path))
 +return NULL;
 +
 +retval = self-container-snapshot(self-container, comment_path);
 +
 +if (retval  0) {
 +Py_RETURN_FALSE;
 +}
 +
 +ret = snprintf(newname, 20, snap%d, retval);
 +if (ret  0 || ret = 20)
 +return NULL;
 +
 +
 +return PyUnicode_FromString(newname);
 +}
 +
 +static PyObject *
 +Container_snapshot_destroy(Container *self, PyObject *args, PyObject *kwds)
 +{
 +char *name = NULL;
 +static char *kwlist[] = {name, NULL};
 +
 +if (! PyArg_ParseTupleAndKeywords(args, kwds, s|, kwlist,
 +  name))
 +return NULL;
 +
 +if (self-container-snapshot_destroy(self-container, name)) {
 +Py_RETURN_TRUE;
 +}
 +
 +Py_RETURN_FALSE;
 +}
 +
 +static PyObject *
 +Container_snapshot_list(Container *self, PyObject *args, PyObject *kwds)
 +{
 +struct lxc_snapshot *snap;
 +int snap_count = 0;
 +PyObject *list = NULL;
 +int i = 0;
 +
 +snap_count = self-container-snapshot_list(self-container, snap);
 +
 +if (snap_count  0) {
 +PyErr_SetString(PyExc_KeyError, Unable to list snapshots);
 +return NULL;
 +}
 +
 +list = PyTuple_New(snap_count);
 +for (i = 0; i  snap_count; i++) {
 +PyObject *list_entry = NULL;
 +
 +list_entry = PyTuple_New(4);
 +PyTuple_SET_ITEM(list_entry, 0,
 + PyUnicode_FromString(snap[i].name));
 +PyTuple_SET_ITEM(list_entry, 1,
 + PyUnicode_FromString(snap[i].comment_pathname));
 +PyTuple_SET_ITEM(list_entry, 2,
 + PyUnicode_FromString(snap[i].timestamp));
 +PyTuple_SET_ITEM(list_entry, 3,
 + PyUnicode_FromString(snap[i].lxcpath));
 +
 +snap[i].free(snap[i]);
 +
 +PyTuple_SET_ITEM(list, i, list_entry);
 +}
 +
 +return list;
 +}
 +
 +
 +static PyObject *
 +Container_snapshot_restore(Container *self, PyObject *args, PyObject *kwds)
 +{
 +char *name = NULL;
 +char *newname = NULL;
 +static char *kwlist[] = {name, newname, NULL};
 +
 +if (! PyArg_ParseTupleAndKeywords(args, kwds, s|s, kwlist,
 +  name, newname))
 +return NULL;
 +
 +if (self-container-snapshot_restore(self-container, name, newname)) {
 +Py_RETURN_TRUE;
 +}
 +
 +Py_RETURN_FALSE;
 +}
 +
 +static PyObject *
  Container_start(Container *self, PyObject *args, PyObject *kwds)
  {
  char** init_args = {NULL};
 @@ -1390,6 +1490,33 @@ static PyMethodDef Container_methods[] = {
   unless timeout is set to a positive value, in which case 
   the container will be killed when the timeout is reached.
  },
 +{snapshot, (PyCFunction)Container_snapshot,
 + METH_VARARGS|METH_KEYWORDS,
 + snapshot(comment_path = None) - string\n
 + \n
 + Snapshot the container and return the snapshot name 
 + (or False on error).
 +},
 +{snapshot_destroy, (PyCFunction)Container_snapshot_destroy,
 + METH_VARARGS|METH_KEYWORDS,
 + snapshot_destroy(name) - boolean\n
 + \n
 + Destroy a snapshot.
 +},
 +{snapshot_list, (PyCFunction)Container_snapshot_list,
 + METH_NOARGS,
 + snapshot_list() - tuple of snapshot tuples\n
 + \n
 + List all snapshots for a container.
 +},
 +{snapshot_restore, (PyCFunction)Container_snapshot_restore,
 + METH_VARARGS|METH_KEYWORDS,
 + snapshot_restore(name, newname = None) - boolean\n
 + \n
 + Restore a container snapshot. If newname is provided a new 
 + container will be created from the snapshot, otherwise an in-place 
 + restore will be attempted.
 +},
  {start, (PyCFunction)Container_start,
   METH_VARARGS|METH_KEYWORDS,
   start(useinit = False, cmd = (,)) - boolean\n
 -- 
 1.8.4.4
 
 
 --
 Rapidly troubleshoot problems before they affect your business. Most IT 
 organizations don't have a clear picture of how application performance 
 affects their 

Re: [lxc-devel] [PATCH] python3: Allow setting daemonize and close_fds

2013-11-29 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
 This extends the list of arguments of start() allowing the user to
 request the container be started in the foreground and have control on
 whether fds will be closed or not (daemonize=True implies that too).
 
 One problem at the moment however is that while we have functions to set
 close_fds and daemonize in the API, we don't have functions to unset
 those flags, so those new parameters will only work on the initial call
 to start() any further call will use the values of the previous one.
 
 I think it'd make sense to change lxcapi slightly to have daemonize and
 close_fds offer a similar interface, both returning booleans and both
 accepting a value as a parameter so API users can set the value they
 want.

What would be the point in checking the value as opposed to simply
setting the one you want?

If unsetting is all we need, we could just add a boolean argument to
want_damonize and want_close_all_fds.  If there is a good reason to
be able to check the values, then we can either add a get_daemonize,
or make the second argument to want_daemonize an int, where -1 means
unset, 1 means set, and 0 means just give me the return value.

Or maybe we want to just add new api fns so as not to change the
existing api?  I'm feeling indecisive.

 Signed-off-by: Stéphane Graber stgra...@ubuntu.com

Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com

 ---
  src/python-lxc/lxc.c | 33 +
  1 file changed, 25 insertions(+), 8 deletions(-)
 
 diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
 index f850a3d..5a20ff4 100644
 --- a/src/python-lxc/lxc.c
 +++ b/src/python-lxc/lxc.c
 @@ -1221,13 +1221,21 @@ Container_snapshot_restore(Container *self, PyObject 
 *args, PyObject *kwds)
  static PyObject *
  Container_start(Container *self, PyObject *args, PyObject *kwds)
  {
 +PyObject *useinit = NULL;
 +PyObject *daemonize = NULL;
 +PyObject *close_fds = NULL;
 +
 +PyObject *vargs = NULL;
  char** init_args = {NULL};
 -PyObject *useinit = NULL, *retval = NULL, *vargs = NULL;
 +
 +PyObject *retval = NULL;
  int init_useinit = 0, i = 0;
 -static char *kwlist[] = {useinit, cmd, NULL};
 +static char *kwlist[] = {useinit, daemonize, close_fds,
 + cmd, NULL};
  
 -if (! PyArg_ParseTupleAndKeywords(args, kwds, |OO, kwlist,
 -  useinit, vargs))
 +if (! PyArg_ParseTupleAndKeywords(args, kwds, |, kwlist,
 +  useinit, daemonize, close_fds,
 +  vargs))
  return NULL;
  
  if (useinit  useinit == Py_True) {
 @@ -1241,7 +1249,13 @@ Container_start(Container *self, PyObject *args, 
 PyObject *kwds)
  }
  }
  
 -self-container-want_daemonize(self-container);
 +if (close_fds  close_fds == Py_True) {
 +self-container-want_close_all_fds(self-container);
 +}
 +
 +if (!daemonize || daemonize == Py_True) {
 +self-container-want_daemonize(self-container);
 +}
  
  if (self-container-start(self-container, init_useinit, init_args))
  retval = Py_True;
 @@ -1519,10 +1533,13 @@ static PyMethodDef Container_methods[] = {
  },
  {start, (PyCFunction)Container_start,
   METH_VARARGS|METH_KEYWORDS,
 - start(useinit = False, cmd = (,)) - boolean\n
 + start(useinit = False, daemonize=True, close_fds=False, 
 + cmd = (,)) - boolean\n
   \n
 - Start the container, optionally using lxc-init and 
 - an alternate init command, then returns its return code.
 + Start the container, return True on success.\n
 + When set useinit will make LXC use lxc-init to start the container.\n
 + The container can be started in the foreground with daemonize=False.\n
 + All fds may also be closed by passing close_fds=True.
  },
  {stop, (PyCFunction)Container_stop,
   METH_NOARGS,
 -- 
 1.8.4.4
 
 
 --
 Rapidly troubleshoot problems before they affect your business. Most IT 
 organizations don't have a clear picture of how application performance 
 affects their revenue. With AppDynamics, you get 100% visibility into your 
 Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
 http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
 ___
 Lxc-devel mailing list
 Lxc-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/lxc-devel

--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics 

Re: [lxc-devel] [PATCH] python3: Allow setting daemonize and close_fds

2013-11-29 Thread Stéphane Graber
On Fri, Nov 29, 2013 at 09:27:15AM -0600, Serge Hallyn wrote:
 Quoting Stéphane Graber (stgra...@ubuntu.com):
  This extends the list of arguments of start() allowing the user to
  request the container be started in the foreground and have control on
  whether fds will be closed or not (daemonize=True implies that too).
  
  One problem at the moment however is that while we have functions to set
  close_fds and daemonize in the API, we don't have functions to unset
  those flags, so those new parameters will only work on the initial call
  to start() any further call will use the values of the previous one.
  
  I think it'd make sense to change lxcapi slightly to have daemonize and
  close_fds offer a similar interface, both returning booleans and both
  accepting a value as a parameter so API users can set the value they
  want.
 
 What would be the point in checking the value as opposed to simply
 setting the one you want?
 
 If unsetting is all we need, we could just add a boolean argument to
 want_damonize and want_close_all_fds.  If there is a good reason to
 be able to check the values, then we can either add a get_daemonize,
 or make the second argument to want_daemonize an int, where -1 means
 unset, 1 means set, and 0 means just give me the return value.
 
 Or maybe we want to just add new api fns so as not to change the
 existing api?  I'm feeling indecisive.

I don't want to check the values but I want to get error reporting.

Currently want_daemonize doesn't return anything so I don't know whether
the setting was save or not. want_close_all_fds solves that issue by
returning a bool with true meaning that the value was saved and false
meaning that something went wrong.


Considering that we haven't commited to a stable API yet, I'd think that
just adding a second argument to both functions to pass the state we
want would be perfectly fine and it'll be trivial to update any code
using that.

If you're happy with that, I'll send a patch later today doing just that.

 
  Signed-off-by: Stéphane Graber stgra...@ubuntu.com
 
 Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com
 
  ---
   src/python-lxc/lxc.c | 33 +
   1 file changed, 25 insertions(+), 8 deletions(-)
  
  diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
  index f850a3d..5a20ff4 100644
  --- a/src/python-lxc/lxc.c
  +++ b/src/python-lxc/lxc.c
  @@ -1221,13 +1221,21 @@ Container_snapshot_restore(Container *self, 
  PyObject *args, PyObject *kwds)
   static PyObject *
   Container_start(Container *self, PyObject *args, PyObject *kwds)
   {
  +PyObject *useinit = NULL;
  +PyObject *daemonize = NULL;
  +PyObject *close_fds = NULL;
  +
  +PyObject *vargs = NULL;
   char** init_args = {NULL};
  -PyObject *useinit = NULL, *retval = NULL, *vargs = NULL;
  +
  +PyObject *retval = NULL;
   int init_useinit = 0, i = 0;
  -static char *kwlist[] = {useinit, cmd, NULL};
  +static char *kwlist[] = {useinit, daemonize, close_fds,
  + cmd, NULL};
   
  -if (! PyArg_ParseTupleAndKeywords(args, kwds, |OO, kwlist,
  -  useinit, vargs))
  +if (! PyArg_ParseTupleAndKeywords(args, kwds, |, kwlist,
  +  useinit, daemonize, close_fds,
  +  vargs))
   return NULL;
   
   if (useinit  useinit == Py_True) {
  @@ -1241,7 +1249,13 @@ Container_start(Container *self, PyObject *args, 
  PyObject *kwds)
   }
   }
   
  -self-container-want_daemonize(self-container);
  +if (close_fds  close_fds == Py_True) {
  +self-container-want_close_all_fds(self-container);
  +}
  +
  +if (!daemonize || daemonize == Py_True) {
  +self-container-want_daemonize(self-container);
  +}
   
   if (self-container-start(self-container, init_useinit, init_args))
   retval = Py_True;
  @@ -1519,10 +1533,13 @@ static PyMethodDef Container_methods[] = {
   },
   {start, (PyCFunction)Container_start,
METH_VARARGS|METH_KEYWORDS,
  - start(useinit = False, cmd = (,)) - boolean\n
  + start(useinit = False, daemonize=True, close_fds=False, 
  + cmd = (,)) - boolean\n
\n
  - Start the container, optionally using lxc-init and 
  - an alternate init command, then returns its return code.
  + Start the container, return True on success.\n
  + When set useinit will make LXC use lxc-init to start the 
  container.\n
  + The container can be started in the foreground with 
  daemonize=False.\n
  + All fds may also be closed by passing close_fds=True.
   },
   {stop, (PyCFunction)Container_stop,
METH_NOARGS,
  -- 
  1.8.4.4
  
  
  --
  Rapidly troubleshoot problems before they affect your business. Most IT 
  organizations don't have a clear picture of how 

[lxc-devel] [lxc/lxc] 956f23: python3: Add snapshot_* to the binding

2013-11-29 Thread GitHub
  Branch: refs/heads/master
  Home:   https://github.com/lxc/lxc
  Commit: 956f23e332bf470cdacccf40966e41f972bb48ac
  https://github.com/lxc/lxc/commit/956f23e332bf470cdacccf40966e41f972bb48ac
  Author: Stéphane Graber stgra...@ubuntu.com
  Date:   2013-11-29 (Fri, 29 Nov 2013)

  Changed paths:
M src/python-lxc/lxc.c

  Log Message:
  ---
  python3: Add snapshot_* to the binding

Signed-off-by: Stéphane Graber stgra...@ubuntu.com
Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com


  Commit: a15877ce8046438a84b8301e1970dfc2c7c409e0
  https://github.com/lxc/lxc/commit/a15877ce8046438a84b8301e1970dfc2c7c409e0
  Author: Stéphane Graber stgra...@ubuntu.com
  Date:   2013-11-29 (Fri, 29 Nov 2013)

  Changed paths:
M src/python-lxc/lxc.c

  Log Message:
  ---
  python3: Allow setting daemonize and close_fds

This extends the list of arguments of start() allowing the user to
request the container be started in the foreground and have control on
whether fds will be closed or not (daemonize=True implies that too).

One problem at the moment however is that while we have functions to set
close_fds and daemonize in the API, we don't have functions to unset
those flags, so those new parameters will only work on the initial call
to start() any further call will use the values of the previous one.

I think it'd make sense to change lxcapi slightly to have daemonize and
close_fds offer a similar interface, both returning booleans and both
accepting a value as a parameter so API users can set the value they
want.

Signed-off-by: Stéphane Graber stgra...@ubuntu.com
Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com


Compare: https://github.com/lxc/lxc/compare/98e5ba5156d4...a15877ce8046--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] python3: Use FSConverter for all paths

2013-11-29 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
 Signed-off-by: Stéphane Graber stgra...@ubuntu.com

After a brief look at http://docs.python.org/3.1/c-api/unicode.html I
suppose it looks good...

Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com

 ---
  src/python-lxc/lxc.c | 69 
 +---
  1 file changed, 60 insertions(+), 9 deletions(-)
 
 diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
 index 5a20ff4..b4f1da3 100644
 --- a/src/python-lxc/lxc.c
 +++ b/src/python-lxc/lxc.c
 @@ -510,16 +510,33 @@ Container_add_device_node(Container *self, PyObject 
 *args, PyObject *kwds)
  static char *kwlist[] = {src_path, dest_path, NULL};
  char *src_path = NULL;
  char *dst_path = NULL;
 +PyObject *py_src_path = NULL;
 +PyObject *py_dst_path = NULL;
  
 -if (! PyArg_ParseTupleAndKeywords(args, kwds, s|s, kwlist,
 -  src_path, dst_path))
 +if (! PyArg_ParseTupleAndKeywords(args, kwds, O|O, kwlist,
 +  PyUnicode_FSConverter, py_src_path,
 +  PyUnicode_FSConverter, py_dst_path))
  return NULL;
  
 +if (py_src_path != NULL) {
 +src_path = PyBytes_AS_STRING(py_src_path);
 +assert(src_path != NULL);
 +}
 +
 +if (py_dst_path != NULL) {
 +dst_path = PyBytes_AS_STRING(py_dst_path);
 +assert(dst_path != NULL);
 +}
 +
  if (self-container-add_device_node(self-container, src_path,
   dst_path)) {
 +Py_XDECREF(py_src_path);
 +Py_XDECREF(py_dst_path);
  Py_RETURN_TRUE;
  }
  
 +Py_XDECREF(py_src_path);
 +Py_XDECREF(py_dst_path);
  Py_RETURN_FALSE;
  }
  
 @@ -611,14 +628,16 @@ Container_clone(Container *self, PyObject *args, 
 PyObject *kwds)
  char **hookargs = NULL;
  
  PyObject *py_hookargs = NULL;
 +PyObject *py_config_path = NULL;
  struct lxc_container *new_container = NULL;
  int i = 0;
  
  static char *kwlist[] = {newname, config_path, flags, bdevtype,
   bdevdata, newsize, hookargs, NULL};
 -if (! PyArg_ParseTupleAndKeywords(args, kwds, s|sisskO, kwlist,
 -  newname, config_path, flags,
 -  bdevtype, bdevdata, newsize,
 +if (! PyArg_ParseTupleAndKeywords(args, kwds, s|OisskO, kwlist,
 +  newname,
 +  PyUnicode_FSConverter, py_config_path,
 +  flags, bdevtype, bdevdata, newsize,
py_hookargs))
  return NULL;
  
 @@ -635,10 +654,17 @@ Container_clone(Container *self, PyObject *args, 
 PyObject *kwds)
  }
  }
  
 +if (py_config_path != NULL) {
 +config_path = PyBytes_AS_STRING(py_config_path);
 +assert(config_path != NULL);
 +}
 +
  new_container = self-container-clone(self-container, newname,
 config_path, flags, bdevtype,
 bdevdata, newsize, hookargs);
  
 +Py_XDECREF(py_config_path);
 +
  if (hookargs) {
  for (i = 0; i  PyTuple_GET_SIZE(py_hookargs); i++)
  free(hookargs[i]);
 @@ -1010,16 +1036,33 @@ Container_remove_device_node(Container *self, 
 PyObject *args, PyObject *kwds)
  static char *kwlist[] = {src_path, dest_path, NULL};
  char *src_path = NULL;
  char *dst_path = NULL;
 +PyObject *py_src_path = NULL;
 +PyObject *py_dst_path = NULL;
  
 -if (! PyArg_ParseTupleAndKeywords(args, kwds, s|s, kwlist,
 -  src_path, dst_path))
 +if (! PyArg_ParseTupleAndKeywords(args, kwds, O|O, kwlist,
 +  PyUnicode_FSConverter, py_src_path,
 +  PyUnicode_FSConverter, py_dst_path))
  return NULL;
  
 +if (py_src_path != NULL) {
 +src_path = PyBytes_AS_STRING(py_src_path);
 +assert(src_path != NULL);
 +}
 +
 +if (py_dst_path != NULL) {
 +dst_path = PyBytes_AS_STRING(py_dst_path);
 +assert(dst_path != NULL);
 +}
 +
  if (self-container-remove_device_node(self-container, src_path,
  dst_path)) {
 +Py_XDECREF(py_src_path);
 +Py_XDECREF(py_dst_path);
  Py_RETURN_TRUE;
  }
  
 +Py_XDECREF(py_src_path);
 +Py_XDECREF(py_dst_path);
  Py_RETURN_FALSE;
  }
  
 @@ -1126,13 +1169,21 @@ Container_snapshot(Container *self, PyObject *args, 
 PyObject *kwds)
  int retval = 0;
  int ret = 0;
  char newname[20];
 +PyObject *py_comment_path;
  
 -if (! PyArg_ParseTupleAndKeywords(args, kwds, |s, kwlist,
 -  comment_path))
 +if (! 

[lxc-devel] [lxc/lxc] c1ee94: python3: Use FSConverter for all paths

2013-11-29 Thread GitHub
  Branch: refs/heads/master
  Home:   https://github.com/lxc/lxc
  Commit: c1ee94cfd3c96a0c279ebcf617156385aabb7054
  https://github.com/lxc/lxc/commit/c1ee94cfd3c96a0c279ebcf617156385aabb7054
  Author: Stéphane Graber stgra...@ubuntu.com
  Date:   2013-11-29 (Fri, 29 Nov 2013)

  Changed paths:
M src/python-lxc/lxc.c

  Log Message:
  ---
  python3: Use FSConverter for all paths

Signed-off-by: Stéphane Graber stgra...@ubuntu.com
Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com


--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] Allow unsetting daemonize and close_fds

2013-11-29 Thread Stéphane Graber
As mentioned in a previous commit, this does two changes:
 - Make want_daemonize return a bool (false on failure, true on success)
 - Make both want_daemonize and want_close_all_fds take a state
   argument so the user can choose to unset those flags.

This commit also updates all occurences of those two functions.

Signed-off-by: Stéphane Graber stgra...@ubuntu.com
---
 src/lua-lxc/core.c |  2 +-
 src/lxc/lxc_start.c|  4 ++--
 src/lxc/lxccontainer.c | 20 +---
 src/lxc/lxccontainer.h |  4 ++--
 src/python-lxc/lxc.c   | 10 --
 src/tests/attach.c |  2 +-
 src/tests/cgpath.c |  2 +-
 src/tests/concurrent.c |  2 +-
 src/tests/console.c|  2 +-
 src/tests/containertests.c |  2 +-
 src/tests/createtest.c |  2 +-
 src/tests/shutdowntest.c   |  2 +-
 12 files changed, 33 insertions(+), 21 deletions(-)

diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index 9492c07..04f2f1d 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -156,7 +156,7 @@ static int container_start(lua_State *L)
argv[j] = NULL;
 }
 
-c-want_daemonize(c);
+c-want_daemonize(c, 1);
 lua_pushboolean(L, !!c-start(c, useinit, argv));
 return 1;
 }
diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index e537846..2a833a6 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -325,7 +325,7 @@ int main(int argc, char *argv[])
}
 
if (my_args.daemonize) {
-   c-want_daemonize(c);
+   c-want_daemonize(c, 1);
}
 
if (pid_fp != NULL) {
@@ -337,7 +337,7 @@ int main(int argc, char *argv[])
}
 
if (my_args.close_all_fds)
-   c-want_close_all_fds(c);
+   c-want_close_all_fds(c, 1);
 
err = c-start(c, 0, args) ? 0 : -1;
 
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 283fbb5..4234760 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -455,29 +455,35 @@ static bool lxcapi_load_config(struct lxc_container *c, 
const char *alt_file)
return ret;
 }
 
-static void lxcapi_want_daemonize(struct lxc_container *c)
+static bool lxcapi_want_daemonize(struct lxc_container *c, int state)
 {
+   if (state  1)
+   return false;
if (!c || !c-lxc_conf)
-   return;
+   return false;
if (container_mem_lock(c)) {
ERROR(Error getting mem lock);
-   return;
+   return false;
}
-   c-daemonize = 1;
+   c-daemonize = state;
/* daemonize implies close_all_fds so set it */
-   c-lxc_conf-close_all_fds = 1;
+   if (state == 1)
+   c-lxc_conf-close_all_fds = 1;
container_mem_unlock(c);
+   return true;
 }
 
-static bool lxcapi_want_close_all_fds(struct lxc_container *c)
+static bool lxcapi_want_close_all_fds(struct lxc_container *c, int state)
 {
+   if (state  1)
+   return false;
if (!c || !c-lxc_conf)
return false;
if (container_mem_lock(c)) {
ERROR(Error getting mem lock);
return false;
}
-   c-lxc_conf-close_all_fds = 1;
+   c-lxc_conf-close_all_fds = state;
container_mem_unlock(c);
return true;
 }
diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index 6044f4d..8333610 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -209,7 +209,7 @@ struct lxc_container {
 *
 * \return \c true if container wants to be daemonised, else \c false.
 */
-   void (*want_daemonize)(struct lxc_container *c);
+   bool (*want_daemonize)(struct lxc_container *c, int state);
 
/*!
 * \brief Determine whether container wishes all file descriptors
@@ -220,7 +220,7 @@ struct lxc_container {
 * \return \c true if container wants all file descriptors closed,
 *  else \c false.
 */
-   bool (*want_close_all_fds)(struct lxc_container *c);
+   bool (*want_close_all_fds)(struct lxc_container *c, int state);
 
/*!
 * \brief Return current config file name.
diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
index b4f1da3..92d79f9 100644
--- a/src/python-lxc/lxc.c
+++ b/src/python-lxc/lxc.c
@@ -1301,11 +1301,17 @@ Container_start(Container *self, PyObject *args, 
PyObject *kwds)
 }
 
 if (close_fds  close_fds == Py_True) {
-self-container-want_close_all_fds(self-container);
+self-container-want_close_all_fds(self-container, 1);
+}
+else {
+self-container-want_close_all_fds(self-container, 0);
 }
 
 if (!daemonize || daemonize == Py_True) {
-self-container-want_daemonize(self-container);
+self-container-want_daemonize(self-container, 1);
+}
+else {
+self-container-want_daemonize(self-container, 0);
 }
 
 if (self-container-start(self-container, init_useinit, init_args))

Re: [lxc-devel] [PATCH] Allow unsetting daemonize and close_fds

2013-11-29 Thread James Hunt
On 29/11/13 15:55, Stéphane Graber wrote:
 As mentioned in a previous commit, this does two changes:
  - Make want_daemonize return a bool (false on failure, true on success)
  - Make both want_daemonize and want_close_all_fds take a state
argument so the user can choose to unset those flags.
 
 This commit also updates all occurences of those two functions.
 
 Signed-off-by: Stéphane Graber stgra...@ubuntu.com
 ---
  src/lua-lxc/core.c |  2 +-
  src/lxc/lxc_start.c|  4 ++--
  src/lxc/lxccontainer.c | 20 +---
  src/lxc/lxccontainer.h |  4 ++--
  src/python-lxc/lxc.c   | 10 --
  src/tests/attach.c |  2 +-
  src/tests/cgpath.c |  2 +-
  src/tests/concurrent.c |  2 +-
  src/tests/console.c|  2 +-
  src/tests/containertests.c |  2 +-
  src/tests/createtest.c |  2 +-
  src/tests/shutdowntest.c   |  2 +-
  12 files changed, 33 insertions(+), 21 deletions(-)
 
 diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
 index 9492c07..04f2f1d 100644
 --- a/src/lua-lxc/core.c
 +++ b/src/lua-lxc/core.c
 @@ -156,7 +156,7 @@ static int container_start(lua_State *L)
   argv[j] = NULL;
  }
  
 -c-want_daemonize(c);
 +c-want_daemonize(c, 1);
  lua_pushboolean(L, !!c-start(c, useinit, argv));
  return 1;
  }
 diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
 index e537846..2a833a6 100644
 --- a/src/lxc/lxc_start.c
 +++ b/src/lxc/lxc_start.c
 @@ -325,7 +325,7 @@ int main(int argc, char *argv[])
   }
  
   if (my_args.daemonize) {
 - c-want_daemonize(c);
 + c-want_daemonize(c, 1);
   }
  
   if (pid_fp != NULL) {
 @@ -337,7 +337,7 @@ int main(int argc, char *argv[])
   }
  
   if (my_args.close_all_fds)
 - c-want_close_all_fds(c);
 + c-want_close_all_fds(c, 1);
  
   err = c-start(c, 0, args) ? 0 : -1;
  
 diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
 index 283fbb5..4234760 100644
 --- a/src/lxc/lxccontainer.c
 +++ b/src/lxc/lxccontainer.c
 @@ -455,29 +455,35 @@ static bool lxcapi_load_config(struct lxc_container *c, 
 const char *alt_file)
   return ret;
  }
  
 -static void lxcapi_want_daemonize(struct lxc_container *c)
 +static bool lxcapi_want_daemonize(struct lxc_container *c, int state)
  {
 + if (state  1)
 + return false;
   if (!c || !c-lxc_conf)
 - return;
 + return false;
   if (container_mem_lock(c)) {
   ERROR(Error getting mem lock);
 - return;
 + return false;
   }
 - c-daemonize = 1;
 + c-daemonize = state;
   /* daemonize implies close_all_fds so set it */
 - c-lxc_conf-close_all_fds = 1;
 + if (state == 1)
 + c-lxc_conf-close_all_fds = 1;
   container_mem_unlock(c);
 + return true;
  }
  
 -static bool lxcapi_want_close_all_fds(struct lxc_container *c)
 +static bool lxcapi_want_close_all_fds(struct lxc_container *c, int state)
  {
 + if (state  1)
 + return false;
   if (!c || !c-lxc_conf)
   return false;
   if (container_mem_lock(c)) {
   ERROR(Error getting mem lock);
   return false;
   }
 - c-lxc_conf-close_all_fds = 1;
 + c-lxc_conf-close_all_fds = state;
   container_mem_unlock(c);
   return true;
  }
 diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
 index 6044f4d..8333610 100644
 --- a/src/lxc/lxccontainer.h
 +++ b/src/lxc/lxccontainer.h
 @@ -209,7 +209,7 @@ struct lxc_container {
*
* \return \c true if container wants to be daemonised, else \c false.
*/
 - void (*want_daemonize)(struct lxc_container *c);
 + bool (*want_daemonize)(struct lxc_container *c, int state);
Happily, this fixes the incorrect doxygen \return already specified :)

  
   /*!
* \brief Determine whether container wishes all file descriptors
 @@ -220,7 +220,7 @@ struct lxc_container {
* \return \c true if container wants all file descriptors closed,
*  else \c false.
*/
 - bool (*want_close_all_fds)(struct lxc_container *c);
 + bool (*want_close_all_fds)(struct lxc_container *c, int state);
Missing a doc update (needs a new \param documenting state).

  
   /*!
* \brief Return current config file name.
 diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
 index b4f1da3..92d79f9 100644
 --- a/src/python-lxc/lxc.c
 +++ b/src/python-lxc/lxc.c
 @@ -1301,11 +1301,17 @@ Container_start(Container *self, PyObject *args, 
 PyObject *kwds)
  }
  
  if (close_fds  close_fds == Py_True) {
 -self-container-want_close_all_fds(self-container);
 +self-container-want_close_all_fds(self-container, 1);
 +}
 +else {
 +self-container-want_close_all_fds(self-container, 0);
  }
  
  if (!daemonize || daemonize == Py_True) {
 -self-container-want_daemonize(self-container);
 +

[lxc-devel] [PATCH] Update doxygen doc for previous change

2013-11-29 Thread Stéphane Graber
Reported-by: James Hunt james.h...@ubuntu.com
Signed-off-by: Stéphane Graber stgra...@ubuntu.com
---
 src/lxc/lxccontainer.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index 8333610..ed340e2 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -206,6 +206,7 @@ struct lxc_container {
 * from the terminal.
 *
 * \param c Container.
+* \param state Value for the daemonize bit (0 or 1).
 *
 * \return \c true if container wants to be daemonised, else \c false.
 */
@@ -216,6 +217,7 @@ struct lxc_container {
 *  to be closed on startup.
 *
 * \param c Container.
+* \param state Value for the close_all_fds bit (0 or 1).
 *
 * \return \c true if container wants all file descriptors closed,
 *  else \c false.
-- 
1.8.4.4


--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Update doxygen doc for previous change

2013-11-29 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
 Reported-by: James Hunt james.h...@ubuntu.com
 Signed-off-by: Stéphane Graber stgra...@ubuntu.com

Ah, thanks.

Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com

 ---
  src/lxc/lxccontainer.h | 2 ++
  1 file changed, 2 insertions(+)
 
 diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
 index 8333610..ed340e2 100644
 --- a/src/lxc/lxccontainer.h
 +++ b/src/lxc/lxccontainer.h
 @@ -206,6 +206,7 @@ struct lxc_container {
* from the terminal.
*
* \param c Container.
 +  * \param state Value for the daemonize bit (0 or 1).
*
* \return \c true if container wants to be daemonised, else \c false.
*/
 @@ -216,6 +217,7 @@ struct lxc_container {
*  to be closed on startup.
*
* \param c Container.
 +  * \param state Value for the close_all_fds bit (0 or 1).
*
* \return \c true if container wants all file descriptors closed,
*  else \c false.
 -- 
 1.8.4.4
 
 
 --
 Rapidly troubleshoot problems before they affect your business. Most IT 
 organizations don't have a clear picture of how application performance 
 affects their revenue. With AppDynamics, you get 100% visibility into your 
 Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
 http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
 ___
 Lxc-devel mailing list
 Lxc-devel@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/lxc-devel

--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Allow unsetting daemonize and close_fds

2013-11-29 Thread S . Çağlar Onur
On Fri, Nov 29, 2013 at 2:34 PM, Serge Hallyn serge.hal...@ubuntu.com wrote:
 Quoting Stéphane Graber (stgra...@ubuntu.com):
 As mentioned in a previous commit, this does two changes:
  - Make want_daemonize return a bool (false on failure, true on success)
  - Make both want_daemonize and want_close_all_fds take a state
argument so the user can choose to unset those flags.

 This commit also updates all occurences of those two functions.

 Signed-off-by: Stéphane Graber stgra...@ubuntu.com

 Two comments below.  With that and James' comments addressed,

 Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com

 ---
  src/lua-lxc/core.c |  2 +-
  src/lxc/lxc_start.c|  4 ++--
  src/lxc/lxccontainer.c | 20 +---
  src/lxc/lxccontainer.h |  4 ++--
  src/python-lxc/lxc.c   | 10 --
  src/tests/attach.c |  2 +-
  src/tests/cgpath.c |  2 +-
  src/tests/concurrent.c |  2 +-
  src/tests/console.c|  2 +-
  src/tests/containertests.c |  2 +-
  src/tests/createtest.c |  2 +-
  src/tests/shutdowntest.c   |  2 +-
  12 files changed, 33 insertions(+), 21 deletions(-)

 diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
 index 9492c07..04f2f1d 100644
 --- a/src/lua-lxc/core.c
 +++ b/src/lua-lxc/core.c
 @@ -156,7 +156,7 @@ static int container_start(lua_State *L)
   argv[j] = NULL;
  }

 -c-want_daemonize(c);
 +c-want_daemonize(c, 1);
  lua_pushboolean(L, !!c-start(c, useinit, argv));
  return 1;
  }
 diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
 index e537846..2a833a6 100644
 --- a/src/lxc/lxc_start.c
 +++ b/src/lxc/lxc_start.c
 @@ -325,7 +325,7 @@ int main(int argc, char *argv[])
   }

   if (my_args.daemonize) {
 - c-want_daemonize(c);
 + c-want_daemonize(c, 1);
   }

   if (pid_fp != NULL) {
 @@ -337,7 +337,7 @@ int main(int argc, char *argv[])
   }

   if (my_args.close_all_fds)
 - c-want_close_all_fds(c);
 + c-want_close_all_fds(c, 1);

   err = c-start(c, 0, args) ? 0 : -1;

 diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
 index 283fbb5..4234760 100644
 --- a/src/lxc/lxccontainer.c
 +++ b/src/lxc/lxccontainer.c
 @@ -455,29 +455,35 @@ static bool lxcapi_load_config(struct lxc_container 
 *c, const char *alt_file)
   return ret;
  }

 -static void lxcapi_want_daemonize(struct lxc_container *c)
 +static bool lxcapi_want_daemonize(struct lxc_container *c, int state)
  {
 + if (state  1)

 What about  0?

Why we are not passing a bool instead of int?

 + return false;
   if (!c || !c-lxc_conf)
 - return;
 + return false;
   if (container_mem_lock(c)) {
   ERROR(Error getting mem lock);
 - return;
 + return false;
   }
 - c-daemonize = 1;
 + c-daemonize = state;
   /* daemonize implies close_all_fds so set it */
 - c-lxc_conf-close_all_fds = 1;
 + if (state == 1)
 + c-lxc_conf-close_all_fds = 1;
   container_mem_unlock(c);
 + return true;
  }

 -static bool lxcapi_want_close_all_fds(struct lxc_container *c)
 +static bool lxcapi_want_close_all_fds(struct lxc_container *c, int state)
  {
 + if (state  1)

 Same.

 + return false;
   if (!c || !c-lxc_conf)
   return false;
   if (container_mem_lock(c)) {
   ERROR(Error getting mem lock);
   return false;
   }
 - c-lxc_conf-close_all_fds = 1;
 + c-lxc_conf-close_all_fds = state;
   container_mem_unlock(c);
   return true;
  }
 diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
 index 6044f4d..8333610 100644
 --- a/src/lxc/lxccontainer.h
 +++ b/src/lxc/lxccontainer.h
 @@ -209,7 +209,7 @@ struct lxc_container {
*
* \return \c true if container wants to be daemonised, else \c false.
*/
 - void (*want_daemonize)(struct lxc_container *c);
 + bool (*want_daemonize)(struct lxc_container *c, int state);

   /*!
* \brief Determine whether container wishes all file descriptors
 @@ -220,7 +220,7 @@ struct lxc_container {
* \return \c true if container wants all file descriptors closed,
*  else \c false.
*/
 - bool (*want_close_all_fds)(struct lxc_container *c);
 + bool (*want_close_all_fds)(struct lxc_container *c, int state);

   /*!
* \brief Return current config file name.
 diff --git a/src/python-lxc/lxc.c b/src/python-lxc/lxc.c
 index b4f1da3..92d79f9 100644
 --- a/src/python-lxc/lxc.c
 +++ b/src/python-lxc/lxc.c
 @@ -1301,11 +1301,17 @@ Container_start(Container *self, PyObject *args, 
 PyObject *kwds)
  }

  if (close_fds  close_fds == Py_True) {
 -self-container-want_close_all_fds(self-container);
 +self-container-want_close_all_fds(self-container, 1);
 +}
 +else {
 +self-container-want_close_all_fds(self-container, 0);
  }

   

Re: [lxc-devel] [PATCH] Allow unsetting daemonize and close_fds

2013-11-29 Thread Stéphane Graber
On Fri, Nov 29, 2013 at 02:40:35PM -0500, S.Çağlar Onur wrote:
 On Fri, Nov 29, 2013 at 2:34 PM, Serge Hallyn serge.hal...@ubuntu.com wrote:
  Quoting Stéphane Graber (stgra...@ubuntu.com):
  As mentioned in a previous commit, this does two changes:
   - Make want_daemonize return a bool (false on failure, true on success)
   - Make both want_daemonize and want_close_all_fds take a state
 argument so the user can choose to unset those flags.
 
  This commit also updates all occurences of those two functions.
 
  Signed-off-by: Stéphane Graber stgra...@ubuntu.com
 
  Two comments below.  With that and James' comments addressed,
 
  Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com
 
  ---
   src/lua-lxc/core.c |  2 +-
   src/lxc/lxc_start.c|  4 ++--
   src/lxc/lxccontainer.c | 20 +---
   src/lxc/lxccontainer.h |  4 ++--
   src/python-lxc/lxc.c   | 10 --
   src/tests/attach.c |  2 +-
   src/tests/cgpath.c |  2 +-
   src/tests/concurrent.c |  2 +-
   src/tests/console.c|  2 +-
   src/tests/containertests.c |  2 +-
   src/tests/createtest.c |  2 +-
   src/tests/shutdowntest.c   |  2 +-
   12 files changed, 33 insertions(+), 21 deletions(-)
 
  diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
  index 9492c07..04f2f1d 100644
  --- a/src/lua-lxc/core.c
  +++ b/src/lua-lxc/core.c
  @@ -156,7 +156,7 @@ static int container_start(lua_State *L)
argv[j] = NULL;
   }
 
  -c-want_daemonize(c);
  +c-want_daemonize(c, 1);
   lua_pushboolean(L, !!c-start(c, useinit, argv));
   return 1;
   }
  diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
  index e537846..2a833a6 100644
  --- a/src/lxc/lxc_start.c
  +++ b/src/lxc/lxc_start.c
  @@ -325,7 +325,7 @@ int main(int argc, char *argv[])
}
 
if (my_args.daemonize) {
  - c-want_daemonize(c);
  + c-want_daemonize(c, 1);
}
 
if (pid_fp != NULL) {
  @@ -337,7 +337,7 @@ int main(int argc, char *argv[])
}
 
if (my_args.close_all_fds)
  - c-want_close_all_fds(c);
  + c-want_close_all_fds(c, 1);
 
err = c-start(c, 0, args) ? 0 : -1;
 
  diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
  index 283fbb5..4234760 100644
  --- a/src/lxc/lxccontainer.c
  +++ b/src/lxc/lxccontainer.c
  @@ -455,29 +455,35 @@ static bool lxcapi_load_config(struct lxc_container 
  *c, const char *alt_file)
return ret;
   }
 
  -static void lxcapi_want_daemonize(struct lxc_container *c)
  +static bool lxcapi_want_daemonize(struct lxc_container *c, int state)
   {
  + if (state  1)
 
  What about  0?
 
 Why we are not passing a bool instead of int?

I based this on similar parameters of other API functions (useinit being
one). Though looking back now it seems we have a couple of cases where
we're also passing bool in such case...

I guess another reason would be if we ever wanted to add finer grained
options for those two commands as unlikely as it may be :)

Serge: Any preference?

  + return false;
if (!c || !c-lxc_conf)
  - return;
  + return false;
if (container_mem_lock(c)) {
ERROR(Error getting mem lock);
  - return;
  + return false;
}
  - c-daemonize = 1;
  + c-daemonize = state;
/* daemonize implies close_all_fds so set it */
  - c-lxc_conf-close_all_fds = 1;
  + if (state == 1)
  + c-lxc_conf-close_all_fds = 1;
container_mem_unlock(c);
  + return true;
   }
 
  -static bool lxcapi_want_close_all_fds(struct lxc_container *c)
  +static bool lxcapi_want_close_all_fds(struct lxc_container *c, int state)
   {
  + if (state  1)
 
  Same.
 
  + return false;
if (!c || !c-lxc_conf)
return false;
if (container_mem_lock(c)) {
ERROR(Error getting mem lock);
return false;
}
  - c-lxc_conf-close_all_fds = 1;
  + c-lxc_conf-close_all_fds = state;
container_mem_unlock(c);
return true;
   }
  diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
  index 6044f4d..8333610 100644
  --- a/src/lxc/lxccontainer.h
  +++ b/src/lxc/lxccontainer.h
  @@ -209,7 +209,7 @@ struct lxc_container {
 *
 * \return \c true if container wants to be daemonised, else \c 
  false.
 */
  - void (*want_daemonize)(struct lxc_container *c);
  + bool (*want_daemonize)(struct lxc_container *c, int state);
 
/*!
 * \brief Determine whether container wishes all file descriptors
  @@ -220,7 +220,7 @@ struct lxc_container {
 * \return \c true if container wants all file descriptors closed,
 *  else \c false.
 */
  - bool (*want_close_all_fds)(struct lxc_container *c);
  + bool (*want_close_all_fds)(struct lxc_container *c, int state);
 
/*!
 * 

[lxc-devel] [lxc/lxc] 540f93: Allow unsetting daemonize and close_fds

2013-11-29 Thread GitHub
  Branch: refs/heads/master
  Home:   https://github.com/lxc/lxc
  Commit: 540f932aeb28274e8e7ea1e8f3a8e5889b88e1d6
  https://github.com/lxc/lxc/commit/540f932aeb28274e8e7ea1e8f3a8e5889b88e1d6
  Author: Stéphane Graber stgra...@ubuntu.com
  Date:   2013-11-29 (Fri, 29 Nov 2013)

  Changed paths:
M src/lua-lxc/core.c
M src/lxc/lxc_start.c
M src/lxc/lxccontainer.c
M src/lxc/lxccontainer.h
M src/python-lxc/lxc.c
M src/tests/attach.c
M src/tests/cgpath.c
M src/tests/concurrent.c
M src/tests/console.c
M src/tests/containertests.c
M src/tests/createtest.c
M src/tests/shutdowntest.c

  Log Message:
  ---
  Allow unsetting daemonize and close_fds

As mentioned in a previous commit, this does two changes:
 - Make want_daemonize return a bool (false on failure, true on success)
 - Make both want_daemonize and want_close_all_fds take a state
   argument so the user can choose to unset those flags.

This commit also updates all occurences of those two functions and turns
the daemonize attribute from an int to a bool.

Signed-off-by: Stéphane Graber stgra...@ubuntu.com
Acked-by: Serge Hallyn serge.hal...@ubuntu.com


  Commit: c9d845b5183650d24b728a90dd8c60e3b50f928c
  https://github.com/lxc/lxc/commit/c9d845b5183650d24b728a90dd8c60e3b50f928c
  Author: Stéphane Graber stgra...@ubuntu.com
  Date:   2013-11-29 (Fri, 29 Nov 2013)

  Changed paths:
M src/lxc/lxccontainer.h

  Log Message:
  ---
  Update doxygen doc for previous change

Reported-by: James Hunt james.h...@ubuntu.com
Signed-off-by: Stéphane Graber stgra...@ubuntu.com
Acked-by: Serge Hallyn serge.hal...@ubuntu.com


Compare: https://github.com/lxc/lxc/compare/c1ee94cfd3c9...c9d845b51836--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Allow unsetting daemonize and close_fds

2013-11-29 Thread Serge Hallyn
Quoting Stéphane Graber (stgra...@ubuntu.com):
 On Fri, Nov 29, 2013 at 02:40:35PM -0500, S.Çağlar Onur wrote:
  On Fri, Nov 29, 2013 at 2:34 PM, Serge Hallyn serge.hal...@ubuntu.com 
  wrote:
   Quoting Stéphane Graber (stgra...@ubuntu.com):
   As mentioned in a previous commit, this does two changes:
- Make want_daemonize return a bool (false on failure, true on success)
- Make both want_daemonize and want_close_all_fds take a state
  argument so the user can choose to unset those flags.
  
   This commit also updates all occurences of those two functions.
  
   Signed-off-by: Stéphane Graber stgra...@ubuntu.com
  
   Two comments below.  With that and James' comments addressed,
  
   Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com
  
   ---
src/lua-lxc/core.c |  2 +-
src/lxc/lxc_start.c|  4 ++--
src/lxc/lxccontainer.c | 20 +---
src/lxc/lxccontainer.h |  4 ++--
src/python-lxc/lxc.c   | 10 --
src/tests/attach.c |  2 +-
src/tests/cgpath.c |  2 +-
src/tests/concurrent.c |  2 +-
src/tests/console.c|  2 +-
src/tests/containertests.c |  2 +-
src/tests/createtest.c |  2 +-
src/tests/shutdowntest.c   |  2 +-
12 files changed, 33 insertions(+), 21 deletions(-)
  
   diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
   index 9492c07..04f2f1d 100644
   --- a/src/lua-lxc/core.c
   +++ b/src/lua-lxc/core.c
   @@ -156,7 +156,7 @@ static int container_start(lua_State *L)
 argv[j] = NULL;
}
  
   -c-want_daemonize(c);
   +c-want_daemonize(c, 1);
lua_pushboolean(L, !!c-start(c, useinit, argv));
return 1;
}
   diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
   index e537846..2a833a6 100644
   --- a/src/lxc/lxc_start.c
   +++ b/src/lxc/lxc_start.c
   @@ -325,7 +325,7 @@ int main(int argc, char *argv[])
 }
  
 if (my_args.daemonize) {
   - c-want_daemonize(c);
   + c-want_daemonize(c, 1);
 }
  
 if (pid_fp != NULL) {
   @@ -337,7 +337,7 @@ int main(int argc, char *argv[])
 }
  
 if (my_args.close_all_fds)
   - c-want_close_all_fds(c);
   + c-want_close_all_fds(c, 1);
  
 err = c-start(c, 0, args) ? 0 : -1;
  
   diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
   index 283fbb5..4234760 100644
   --- a/src/lxc/lxccontainer.c
   +++ b/src/lxc/lxccontainer.c
   @@ -455,29 +455,35 @@ static bool lxcapi_load_config(struct 
   lxc_container *c, const char *alt_file)
 return ret;
}
  
   -static void lxcapi_want_daemonize(struct lxc_container *c)
   +static bool lxcapi_want_daemonize(struct lxc_container *c, int state)
{
   + if (state  1)
  
   What about  0?
  
  Why we are not passing a bool instead of int?
 
 I based this on similar parameters of other API functions (useinit being
 one). Though looking back now it seems we have a couple of cases where
 we're also passing bool in such case...
 
 I guess another reason would be if we ever wanted to add finer grained
 options for those two commands as unlikely as it may be :)
 
 Serge: Any preference?

(I assume this question is now obsolete)

-serge

--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


Re: [lxc-devel] [PATCH] Allow unsetting daemonize and close_fds

2013-11-29 Thread Stéphane Graber
On Fri, Nov 29, 2013 at 04:16:46PM -0600, Serge Hallyn wrote:
 Quoting Stéphane Graber (stgra...@ubuntu.com):
  On Fri, Nov 29, 2013 at 02:40:35PM -0500, S.Çağlar Onur wrote:
   On Fri, Nov 29, 2013 at 2:34 PM, Serge Hallyn serge.hal...@ubuntu.com 
   wrote:
Quoting Stéphane Graber (stgra...@ubuntu.com):
As mentioned in a previous commit, this does two changes:
 - Make want_daemonize return a bool (false on failure, true on 
success)
 - Make both want_daemonize and want_close_all_fds take a state
   argument so the user can choose to unset those flags.
   
This commit also updates all occurences of those two functions.
   
Signed-off-by: Stéphane Graber stgra...@ubuntu.com
   
Two comments below.  With that and James' comments addressed,
   
Acked-by: Serge E. Hallyn serge.hal...@ubuntu.com
   
---
 src/lua-lxc/core.c |  2 +-
 src/lxc/lxc_start.c|  4 ++--
 src/lxc/lxccontainer.c | 20 +---
 src/lxc/lxccontainer.h |  4 ++--
 src/python-lxc/lxc.c   | 10 --
 src/tests/attach.c |  2 +-
 src/tests/cgpath.c |  2 +-
 src/tests/concurrent.c |  2 +-
 src/tests/console.c|  2 +-
 src/tests/containertests.c |  2 +-
 src/tests/createtest.c |  2 +-
 src/tests/shutdowntest.c   |  2 +-
 12 files changed, 33 insertions(+), 21 deletions(-)
   
diff --git a/src/lua-lxc/core.c b/src/lua-lxc/core.c
index 9492c07..04f2f1d 100644
--- a/src/lua-lxc/core.c
+++ b/src/lua-lxc/core.c
@@ -156,7 +156,7 @@ static int container_start(lua_State *L)
  argv[j] = NULL;
 }
   
-c-want_daemonize(c);
+c-want_daemonize(c, 1);
 lua_pushboolean(L, !!c-start(c, useinit, argv));
 return 1;
 }
diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c
index e537846..2a833a6 100644
--- a/src/lxc/lxc_start.c
+++ b/src/lxc/lxc_start.c
@@ -325,7 +325,7 @@ int main(int argc, char *argv[])
  }
   
  if (my_args.daemonize) {
- c-want_daemonize(c);
+ c-want_daemonize(c, 1);
  }
   
  if (pid_fp != NULL) {
@@ -337,7 +337,7 @@ int main(int argc, char *argv[])
  }
   
  if (my_args.close_all_fds)
- c-want_close_all_fds(c);
+ c-want_close_all_fds(c, 1);
   
  err = c-start(c, 0, args) ? 0 : -1;
   
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 283fbb5..4234760 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -455,29 +455,35 @@ static bool lxcapi_load_config(struct 
lxc_container *c, const char *alt_file)
  return ret;
 }
   
-static void lxcapi_want_daemonize(struct lxc_container *c)
+static bool lxcapi_want_daemonize(struct lxc_container *c, int state)
 {
+ if (state  1)
   
What about  0?
   
   Why we are not passing a bool instead of int?
  
  I based this on similar parameters of other API functions (useinit being
  one). Though looking back now it seems we have a couple of cases where
  we're also passing bool in such case...
  
  I guess another reason would be if we ever wanted to add finer grained
  options for those two commands as unlikely as it may be :)
  
  Serge: Any preference?
 
 (I assume this question is now obsolete)
 
 -serge

It's indeed, for anyone else following, I ended up converting those to
bool and changing the type of daemonize to match.

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com


signature.asc
Description: Digital signature
--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel


[lxc-devel] [PATCH] ubuntu: Actually attempt to remove /dev/shm

2013-11-29 Thread Stéphane Graber
Signed-off-by: Stéphane Graber stgra...@ubuntu.com
---
 templates/lxc-ubuntu-cloud.in | 3 ++-
 templates/lxc-ubuntu.in   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/templates/lxc-ubuntu-cloud.in b/templates/lxc-ubuntu-cloud.in
index 3042d89..e97c7e3 100644
--- a/templates/lxc-ubuntu-cloud.in
+++ b/templates/lxc-ubuntu-cloud.in
@@ -139,8 +139,9 @@ EOF
 # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
 # get bind mounted to the host's /run/shm.  So try to rmdir
 # it, and in case that fails move it out of the way.
+# NOTE: This can only be removed once 12.04 goes out of support
 if [ ! -L $rootfs/dev/shm ]  [ -d $rootfs/run/shm ]  [ -e 
$rootfs/dev/shm ]; then
-mv $rootfs/dev/shm $rootfs/dev/shm.bak
+rmdir $rootfs/dev/shm 2/dev/null || mv $rootfs/dev/shm 
$rootfs/dev/shm.bak
 ln -s /run/shm $rootfs/dev/shm
 fi
 
diff --git a/templates/lxc-ubuntu.in b/templates/lxc-ubuntu.in
index 4e6a54f..8ed9be7 100644
--- a/templates/lxc-ubuntu.in
+++ b/templates/lxc-ubuntu.in
@@ -541,8 +541,9 @@ EOF
 # I'm afraid of doing rm -rf $rootfs/dev/shm, in case it did
 # get bind mounted to the host's /run/shm.  So try to rmdir
 # it, and in case that fails move it out of the way.
+# NOTE: This can only be removed once 12.04 goes out of support
 if [ ! -L $rootfs/dev/shm ]  [ -d $rootfs/run/shm ]  [ -e 
$rootfs/dev/shm ]; then
-mv $rootfs/dev/shm $rootfs/dev/shm.bak
+rmdir $rootfs/dev/shm 2/dev/null || mv $rootfs/dev/shm 
$rootfs/dev/shm.bak
 ln -s /run/shm $rootfs/dev/shm
 fi
 
-- 
1.8.4.4


--
Rapidly troubleshoot problems before they affect your business. Most IT 
organizations don't have a clear picture of how application performance 
affects their revenue. With AppDynamics, you get 100% visibility into your 
Java,.NET,  PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro!
http://pubads.g.doubleclick.net/gampad/clk?id=84349351iu=/4140/ostg.clktrk
___
Lxc-devel mailing list
Lxc-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxc-devel