]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgroup_enter: catch write errors
authorSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 23 Jul 2013 04:59:18 +0000 (23:59 -0500)
committerSerge Hallyn <serge.hallyn@ubuntu.com>
Tue, 23 Jul 2013 13:09:43 +0000 (08:09 -0500)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
src/lxc/cgroup.c

index c7075193b55411ac2c71b558a15df8bb9b767322..a61d21058021c935b90bf16d6eb501316d9d2ca3 100644 (file)
@@ -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;