]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc-start: store PID file to lxc_container
authorQiang Huang <h.huangqiang@huawei.com>
Wed, 22 Jan 2014 04:11:37 +0000 (12:11 +0800)
committerStéphane Graber <stgraber@ubuntu.com>
Thu, 23 Jan 2014 00:51:45 +0000 (19:51 -0500)
So we can remove PID file untill lxc_container_free.

This also fix bug: https://github.com/lxc/lxc/issues/89

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
src/lxc/lxc_start.c
src/lxc/lxccontainer.c
src/lxc/lxccontainer.h

index d5379daf7517414d521851496810c4db0c82faf9..fd2dc6ebdb99a7204d6bcffffd531a9ee7820381 100644 (file)
@@ -302,6 +302,11 @@ int main(int argc, char *argv[])
        }
 
        if (my_args.pidfile != NULL) {
+               if (ensure_path(&c->pidfile, my_args.pidfile) < 0) {
+                       ERROR("failed to ensure pidfile '%s'", my_args.pidfile);
+                       goto out;
+               }
+
                pid_fp = fopen(my_args.pidfile, "w");
                if (pid_fp == NULL) {
                        SYSERROR("failed to create pidfile '%s' for '%s'",
@@ -342,10 +347,6 @@ int main(int argc, char *argv[])
                c->want_close_all_fds(c, true);
 
        err = c->start(c, 0, args) ? 0 : -1;
-
-       if (my_args.pidfile)
-               unlink(my_args.pidfile);
-
 out:
        lxc_container_put(c);
        if (pid_fp)
index 167708d7db9cd7f6227073bfc8626683b89c15af..f1c98a4b64a58913ccf676e9180f57378ca18f21 100644 (file)
@@ -237,6 +237,12 @@ static void lxc_container_free(struct lxc_container *c)
                free(c->config_path);
                c->config_path = NULL;
        }
+       if (c->pidfile) {
+               unlink(c->pidfile);
+               free(c->pidfile);
+               c->pidfile = NULL;
+       }
+
        free(c);
 }
 
@@ -3178,6 +3184,7 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
                lxcapi_clear_config(c);
        }
        c->daemonize = true;
+       c->pidfile = NULL;
 
        // assign the member functions
        c->is_defined = lxcapi_is_defined;
index f3c7d720b7707948a3a8f1fac0fe505790975849..84caa312a01afbe83440311d54060031a8d3c821 100644 (file)
@@ -66,6 +66,12 @@ struct lxc_container {
         */
        char *configfile;
 
+       /*!
+        * \private
+        * File to store pid.
+        */
+       char *pidfile;
+
        /*!
         * \private
         * Container semaphore lock.