From: Qiang Huang Date: Wed, 22 Jan 2014 04:11:37 +0000 (+0800) Subject: lxc-start: store PID file to lxc_container X-Git-Tag: lxc-1.0.0.beta3~57 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=72cf75fa33b97104c5e9905aab1be8d335119e7b;p=thirdparty%2Flxc.git lxc-start: store PID file to lxc_container 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 Acked-by: Serge E. Hallyn --- diff --git a/src/lxc/lxc_start.c b/src/lxc/lxc_start.c index d5379daf7..fd2dc6ebd 100644 --- a/src/lxc/lxc_start.c +++ b/src/lxc/lxc_start.c @@ -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) diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c index 167708d7d..f1c98a4b6 100644 --- a/src/lxc/lxccontainer.c +++ b/src/lxc/lxccontainer.c @@ -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; diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h index f3c7d720b..84caa312a 100644 --- a/src/lxc/lxccontainer.h +++ b/src/lxc/lxccontainer.h @@ -66,6 +66,12 @@ struct lxc_container { */ char *configfile; + /*! + * \private + * File to store pid. + */ + char *pidfile; + /*! * \private * Container semaphore lock.