From: Serge Hallyn Date: Tue, 23 Jul 2013 04:59:18 +0000 (-0500) Subject: cgroup_enter: catch write errors X-Git-Tag: lxc-1.0.0.alpha1~1^2~108 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c495ae35a804e3c12cb9f4826c30295043986ce;p=thirdparty%2Flxc.git cgroup_enter: catch write errors Signed-off-by: Serge Hallyn Acked-by: Stéphane Graber --- diff --git a/src/lxc/cgroup.c b/src/lxc/cgroup.c index c7075193b..a61d21058 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;