]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
Allow unsetting daemonize and close_fds
authorStéphane Graber <stgraber@ubuntu.com>
Fri, 29 Nov 2013 15:53:15 +0000 (10:53 -0500)
committerStéphane Graber <stgraber@ubuntu.com>
Fri, 29 Nov 2013 21:05:07 +0000 (16:05 -0500)
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 <stgraber@ubuntu.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
12 files changed:
src/lua-lxc/core.c
src/lxc/lxc_start.c
src/lxc/lxccontainer.c
src/lxc/lxccontainer.h
src/python-lxc/lxc.c
src/tests/attach.c
src/tests/cgpath.c
src/tests/concurrent.c
src/tests/console.c
src/tests/containertests.c
src/tests/createtest.c
src/tests/shutdowntest.c

index 9492c07fb9b66df701578c03c036d6faadc379e8..8904ffc86f6fba4bee713bddd77a5d4a3a3333de 100644 (file)
@@ -156,7 +156,7 @@ static int container_start(lua_State *L)
        argv[j] = NULL;
     }
 
-    c->want_daemonize(c);
+    c->want_daemonize(c, true);
     lua_pushboolean(L, !!c->start(c, useinit, argv));
     return 1;
 }
index e5378469bd0f9748678827b6e741764ff6840f47..5e4565cda3d0d6dc278f2b9f0e25927cb8b681c3 100644 (file)
@@ -325,7 +325,7 @@ int main(int argc, char *argv[])
        }
 
        if (my_args.daemonize) {
-               c->want_daemonize(c);
+               c->want_daemonize(c, true);
        }
 
        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, true);
 
        err = c->start(c, 0, args) ? 0 : -1;
 
index 283fbb58f53e08150c90c0ffd80f5ac4105087f4..50796ae1622dbf9bdb6fc109241120b17bc217c6 100644 (file)
@@ -455,21 +455,23 @@ 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, bool state)
 {
        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, bool state)
 {
        if (!c || !c->lxc_conf)
                return false;
@@ -477,7 +479,7 @@ static bool lxcapi_want_close_all_fds(struct lxc_container *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;
 }
@@ -549,7 +551,7 @@ static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv
 {
        int ret;
        struct lxc_conf *conf;
-       int daemonize = 0;
+       bool daemonize = false;
        char *default_args[] = {
                "/sbin/init",
                '\0',
index 6044f4dc3bd823fe408ebff2ef2f7a4b01b26a3e..9093de23b1a4d1aa0f1ec0375555f801cb89b97f 100644 (file)
@@ -93,7 +93,7 @@ struct lxc_container {
        int error_num;
 
        /*! Whether container wishes to be daemonized */
-       int daemonize;
+       bool daemonize;
 
        /*! Full path to configuration file */
        char *config_path;
@@ -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, bool 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, bool state);
 
        /*!
         * \brief Return current config file name.
index b4f1da3a2419fe0363aec5cb35c749d19b483c6e..cd92949258727c88bdc4ec9779475e62caa3dd31 100644 (file)
@@ -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, true);
+    }
+    else {
+        self->container->want_close_all_fds(self->container, false);
     }
 
     if (!daemonize || daemonize == Py_True) {
-        self->container->want_daemonize(self->container);
+        self->container->want_daemonize(self->container, true);
+    }
+    else {
+        self->container->want_daemonize(self->container, false);
     }
 
     if (self->container->start(self->container, init_useinit, init_args))
index 57a4bddb46c11e57bfd98df9771b5ab6174fce0d..2f0cb0892bb1e924254ce3a3ac9357f750ab1208 100644 (file)
@@ -315,7 +315,7 @@ static struct lxc_container *test_ct_create(const char *lxcpath,
        if (lsm_enabled())
                test_attach_lsm_set_config(ct);
 
-       ct->want_daemonize(ct);
+       ct->want_daemonize(ct, true);
        if (!ct->startl(ct, 0, NULL)) {
                TSTERR("starting container %s", name);
                goto out2;
index 493b07a7947c107afb45105f4548c42b6bd80c68..1c14468e0d399e781067b552a667397efeab6e90 100644 (file)
@@ -172,7 +172,7 @@ static int test_container(const char *lxcpath,
                goto out2;
        }
        c->load_config(c, NULL);
-       c->want_daemonize(c);
+       c->want_daemonize(c, true);
        if (!c->startl(c, 0, NULL)) {
                TSTERR("starting container %s", name);
                goto out3;
index 76fae875822ade3f7fc82a7fec6d03f63a56f039..6ae2662519aad164f1cd0dd41925489912a6d2a0 100644 (file)
@@ -88,7 +88,7 @@ static void do_function(void *arguments)
         }
     } else if(strcmp(args->mode, "start") == 0) {
         if (c->is_defined(c) && !c->is_running(c)) {
-            c->want_daemonize(c);
+            c->want_daemonize(c, true);
             if (!c->start(c, false, NULL)) {
                 fprintf(stderr, "Starting the container (%s) failed...\n", name);
                 goto out;
index c4cb3b2388c099e1c6e17f28357b24ddab7068ef..558e2790501670f147b806a5bdcf9e90710e0769 100644 (file)
@@ -145,7 +145,7 @@ static int test_console(const char *lxcpath,
        c->load_config(c, NULL);
        c->set_config_item(c, "lxc.tty", TTYCNT_STR);
        c->save_config(c, NULL);
-       c->want_daemonize(c);
+       c->want_daemonize(c, true);
        if (!c->startl(c, 0, NULL)) {
                TSTERR("starting container %s", name);
                goto out3;
index e463e352e7e3ca54e81dd550e0b9ddd55c34e346..8ec840f6b447cd31efa82f44436ea15734de6614 100644 (file)
@@ -225,7 +225,7 @@ int main(int argc, char *argv[])
                goto out;
 
        /* non-daemonized is tested in 'startone' */
-       c->want_daemonize(c);
+       c->want_daemonize(c, true);
        if (!c->startl(c, 0, NULL, NULL)) {
                fprintf(stderr, "%d: %s failed to start daemonized\n", __LINE__, c->name);
                goto out;
index c018458b435515faf2d930d04a9aeb20ed9fca5b..b53c9638476b9d68cd3585fb294bf8d8c1f79131 100644 (file)
@@ -61,7 +61,7 @@ int main(int argc, char *argv[])
        }
 
        c->load_config(c, NULL);
-       c->want_daemonize(c);
+       c->want_daemonize(c, true);
        if (!c->startl(c, 0, NULL)) {
                fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
                goto out;
index c7070c16c5f3c81491193201018911adad78d118..fc4e8fd44987ffa9efdd8b8d7bb80f7f40fb934a 100644 (file)
@@ -62,7 +62,7 @@ int main(int argc, char *argv[])
        }
 
        c->load_config(c, NULL);
-       c->want_daemonize(c);
+       c->want_daemonize(c, true);
        if (!c->startl(c, 0, NULL)) {
                fprintf(stderr, "%d: failed to start %s\n", __LINE__, MYNAME);
                goto out;