From 2c495ae35a804e3c12cb9f4826c30295043986ce Mon Sep 17 00:00:00 2001 From: Serge Hallyn Date: Mon, 22 Jul 2013 23:59:18 -0500 Subject: [PATCH] cgroup_enter: catch write errors MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Serge Hallyn Acked-by: Stéphane Graber --- 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 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; -- 2.47.2