[lxc-devel] [PATCH] cgroup_enter: catch write errors

Stéphane Graber stgraber at ubuntu.com
Tue Jul 23 08:29:09 UTC 2013


On Mon, Jul 22, 2013 at 11:59:18PM -0500, Serge Hallyn wrote:
> Signed-off-by: Serge Hallyn <serge.hallyn at ubuntu.com>

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

> ---
>  src/lxc/cgroup.c | 15 +++++++++++----
>  1 file changed, 11 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c
> index c707519..a61d210 100644
> --- a/src/lxc/cgroup.c
> +++ b/src/lxc/cgroup.c
> @@ -769,16 +769,23 @@ int lxc_cgroup_enter(const char *cgpath, pid_t pid)
>  		ret = snprintf(path, MAXPATHLEN, "%s/%s/tasks",
>  			       mntent_r.mnt_dir, cgpath);
>  		if (ret < 0 || ret >= MAXPATHLEN) {
> -			ERROR("entering cgroup");
> +			ERROR("Error entering cgroup");
>  			goto out;
>  		}
>  		fout = fopen(path, "w");
>  		if (!fout) {
> -			ERROR("entering cgroup");
> +			SYSERROR("Error entering cgroup");
> +			goto out;
> +		}
> +		if (fprintf(fout, "%d\n", (int)pid) < 0) {
> +			ERROR("Error writing pid to %s", path);
> +			fclose(fout);
> +			goto out;
> +		}
> +		if (fclose(fout) < 0) {
> +			SYSERROR("Error writing pid to %s", path);
>  			goto out;
>  		}
> -		fprintf(fout, "%d\n", (int)pid);
> -		fclose(fout);
>  	}
>  	retv = 0;
>  
> -- 
> 1.8.1.2
> 
> 
> ------------------------------------------------------------------------------
> See everything from the browser to the database with AppDynamics
> Get end-to-end visibility with application monitoring from AppDynamics
> Isolate bottlenecks and diagnose root cause in seconds.
> Start your free trial of AppDynamics Pro today!
> http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/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: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20130723/df445788/attachment.pgp>


More information about the lxc-devel mailing list