[lxc-devel] [PATCH cgmanager chown: don't do a gratuitous fork

Stéphane Graber stgraber at ubuntu.com
Wed Jan 29 16:21:56 UTC 2014


On Wed, Jan 29, 2014 at 04:17:09PM +0000, Serge Hallyn wrote:
> userns_exec_1() clones a new task to manipulate.  We don't
> need to fork before calling that.
> 
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

> ---
>  src/lxc/cgmanager.c | 16 +++-------------
>  1 file changed, 3 insertions(+), 13 deletions(-)
> 
> diff --git a/src/lxc/cgmanager.c b/src/lxc/cgmanager.c
> index 29c0e99..797e2ae 100644
> --- a/src/lxc/cgmanager.c
> +++ b/src/lxc/cgmanager.c
> @@ -247,7 +247,6 @@ static int chown_cgroup_wrapper(void *data)
>  static bool chown_cgroup(const char *controller, const char *cgroup_path,
>  			struct lxc_conf *conf)
>  {
> -	pid_t pid;
>  	struct chown_data data;
>  	data.controller = controller;
>  	data.cgroup_path = cgroup_path;
> @@ -258,20 +257,11 @@ static bool chown_cgroup(const char *controller, const char *cgroup_path,
>  		return true;
>  	}
>  
> -	if ((pid = fork()) < 0) {
> -		SYSERROR("fork");
> +	if (userns_exec_1(conf, chown_cgroup_wrapper, &data) < 0) {
> +		ERROR("Error requesting cgroup chown in new namespace");
>  		return false;
>  	}
> -	if (pid > 0) {
> -		if (wait_for_pid(pid)) {
> -			ERROR("Error chowning cgroup");
> -			return false;
> -		}
> -		return true;
> -	}
> -	if (userns_exec_1(conf, chown_cgroup_wrapper, &data) < 0)
> -		exit(1);
> -	exit(0);
> +	return true;
>  }
>  
>  struct cgm_data {
> -- 
> 1.8.5.3
> 
> _______________________________________________
> 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/20140129/f82d553f/attachment.pgp>


More information about the lxc-devel mailing list