]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
cgfsng: copy_parent_file()
authorChristian Brauner <christian.brauner@ubuntu.com>
Sat, 17 Feb 2018 18:04:05 +0000 (19:04 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Wed, 21 Feb 2018 14:48:18 +0000 (15:48 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c

index 4167fc2e3765cc29fdd2cbef1f296f3ba2b092c9..47c48682f4e634531a25eacf2894cffb59cd4f1b 100644 (file)
@@ -639,13 +639,14 @@ on_error:
 /* Copy contents of parent(@path)/@file to @path/@file */
 static bool copy_parent_file(char *path, char *file)
 {
-       char *lastslash, *value = NULL, *fpath, oldv;
-       int len = 0;
        int ret;
+       char *fpath, *lastslash, oldv;
+       int len = 0;
+       char *value = NULL;
 
        lastslash = strrchr(path, '/');
-       if (!lastslash) { /* bug...  this shouldn't be possible */
-               ERROR("cgfsng:copy_parent_file: bad path %s", path);
+       if (!lastslash) {
+               ERROR("Failed to detect \"/\" in \"%s\"", path);
                return false;
        }
        oldv = *lastslash;
@@ -653,22 +654,25 @@ static bool copy_parent_file(char *path, char *file)
        fpath = must_make_path(path, file, NULL);
        len = lxc_read_from_file(fpath, NULL, 0);
        if (len <= 0)
-               goto bad;
+               goto on_error;
+
        value = must_alloc(len + 1);
-       if (lxc_read_from_file(fpath, value, len) != len)
-               goto bad;
+       ret = lxc_read_from_file(fpath, value, len);
+       if (ret != len)
+               goto on_error;
        free(fpath);
+
        *lastslash = oldv;
        fpath = must_make_path(path, file, NULL);
        ret = lxc_write_to_file(fpath, value, len, false);
        if (ret < 0)
-               SYSERROR("Unable to write %s to %s", value, fpath);
+               SYSERROR("Failed to write \"%s\" to file \"%s\"", value, fpath);
        free(fpath);
        free(value);
        return ret >= 0;
 
-bad:
-       SYSERROR("Error reading '%s'", fpath);
+on_error:
+       SYSERROR("Failed to read file \"%s\"", fpath);
        free(fpath);
        free(value);
        return false;