From c3e489677659a88f0d06f9e3300f33105a2bab23 Mon Sep 17 00:00:00 2001 From: Christian Brauner Date: Thu, 10 Dec 2020 20:48:48 +0100 Subject: [PATCH] criu: cleanup load_tty_major_minor() Signed-off-by: Christian Brauner --- src/lxc/criu.c | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) 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; } -- 2.47.2