]> git.proxmox.com Git - mirror_lxc.git/commitdiff
python3: Allow setting daemonize and close_fds
authorStéphane Graber <stgraber@ubuntu.com>
Thu, 28 Nov 2013 19:32:53 +0000 (14:32 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 29 Nov 2013 15:43:35 +0000 (10:43 -0500)
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 <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/python-lxc/lxc.c

index f850a3ddf589c3af389bd0ce49b81e6391fdc9a4..5a20ff47c996052e05c7d517cf80cc96d1ef05a0 100644 (file)
@@ -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, "|OOOO", 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,