[lxc-devel] [PATCH 1/1] set close-all-fds by default
Stéphane Graber
stgraber at ubuntu.com
Mon Jan 12 21:21:35 UTC 2015
On Fri, Jan 09, 2015 at 04:33:42PM +0000, Serge Hallyn wrote:
> When containers request to be daemonized, close-all-fd is
> set to true. But when we switched ot daemonize-by-default we didn't
> set close-all-fd by default.
>
> Fix that. In order to do that we have to always have a lxc_conf
> object. As a consequence, after this patch we can drop a bunch
> of checks for c->lxc_conf existing. We should consider removing
> those. This patch does not do that.
>
> This should close https://github.com/lxc/lxc/issues/354
>
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>
Acked-by: Stéphane Graber <stgraber at ubuntu.com>
> ---
> src/lxc/lxccontainer.c | 17 ++++++++++++-----
> 1 file changed, 12 insertions(+), 5 deletions(-)
>
> diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
> index 406cead..878c483 100644
> --- a/src/lxc/lxccontainer.c
> +++ b/src/lxc/lxccontainer.c
> @@ -457,6 +457,14 @@ static bool lxcapi_load_config(struct lxc_container *c, const char *alt_file)
> return ret;
> }
>
> +static void do_set_daemonize(struct lxc_container *c, bool state)
> +{
> + c->daemonize = state;
> + /* daemonize implies close_all_fds so set it */
> + if (state)
> + c->lxc_conf->close_all_fds = 1;
> +}
> +
> static bool lxcapi_want_daemonize(struct lxc_container *c, bool state)
> {
> if (!c || !c->lxc_conf)
> @@ -465,10 +473,7 @@ static bool lxcapi_want_daemonize(struct lxc_container *c, bool state)
> ERROR("Error getting mem lock");
> return false;
> }
> - c->daemonize = state;
> - /* daemonize implies close_all_fds so set it */
> - if (state == 1)
> - c->lxc_conf->close_all_fds = 1;
> + do_set_daemonize(c, state);
> container_mem_unlock(c);
> return true;
> }
> @@ -4098,7 +4103,9 @@ struct lxc_container *lxc_container_new(const char *name, const char *configpath
> container_destroy(c);
> lxcapi_clear_config(c);
> }
> - c->daemonize = true;
> + if (!c->lxc_conf)
> + c->lxc_conf = lxc_conf_init();
> + do_set_daemonize(c, true);
> c->pidfile = NULL;
>
> // assign the member functions
> --
> 2.1.0
>
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel
--
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20150112/ed6160f2/attachment.sig>
More information about the lxc-devel
mailing list