]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
criu: cleanup load_tty_major_minor() 3595/head
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 10 Dec 2020 19:48:48 +0000 (20:48 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 10 Dec 2020 19:49:45 +0000 (20:49 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/criu.c

index c0caffa1b033db27419a361deae9d6f1d3a049a5..31961d0f07ac92e69b415924c2c29c8bc21328b0 100644 (file)
@@ -79,36 +79,26 @@ struct criu_opts {
 
 static int load_tty_major_minor(char *directory, char *output, int len)
 {
-       FILE *f;
        char path[PATH_MAX];
-       int ret;
+       ssize_t ret;
 
        ret = snprintf(path, sizeof(path), "%s/tty.info", directory);
-       if (ret < 0 || ret >= sizeof(path)) {
-               ERROR("snprintf'd too many characters: %d", ret);
-               return -1;
-       }
+       if (ret < 0 || (size_t)ret >= sizeof(path))
+               return ret_errno(EIO);
 
-       f = fopen(path, "re");
-       if (!f) {
-               /* This means we're coming from a liblxc which didn't export
+       ret = lxc_read_from_file(path, output, len);
+       if (ret < 0) {
+               /*
+                * This means we're coming from a liblxc which didn't export
                 * the tty info. In this case they had to have lxc.console.path
                 * = * none, so there's no problem restoring.
                 */
                if (errno == ENOENT)
                        return 0;
 
-               SYSERROR("couldn't open %s", path);
-               return -1;
+               return log_error_errno(-errno, errno, "Failed to open \"%s\"", path);
        }
 
-       if (!fgets(output, len, f)) {
-               fclose(f);
-               SYSERROR("couldn't read %s", path);
-               return -1;
-       }
-
-       fclose(f);
        return 0;
 }