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

Serge Hallyn serge.hallyn at ubuntu.com
Tue Jul 23 04:59:18 UTC 2013


Signed-off-by: Serge Hallyn <serge.hallyn 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





More information about the lxc-devel mailing list