From: Christian Brauner Date: Thu, 10 Dec 2020 19:48:48 +0000 (+0100) Subject: criu: cleanup load_tty_major_minor() X-Git-Tag: lxc-5.0.0~330^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F3595%2Fhead;p=thirdparty%2Flxc.git criu: cleanup load_tty_major_minor() Signed-off-by: Christian Brauner --- diff --git a/src/lxc/criu.c b/src/lxc/criu.c index c0caffa1b..31961d0f0 100644 --- a/src/lxc/criu.c +++ b/src/lxc/criu.c @@ -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; }