From: Christian Brauner Date: Fri, 22 Feb 2019 20:49:48 +0000 (+0100) Subject: conf: cleanup macros remount_all_slave X-Git-Tag: lxc-3.2.0~131^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=003be47b9000af1ba32227493ea900b4b8981651;p=thirdparty%2Flxc.git conf: cleanup macros remount_all_slave Signed-off-by: Christian Brauner --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 129ead3df..5385e3285 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -3279,9 +3279,10 @@ void tmp_proc_unmount(struct lxc_conf *lxc_conf) void remount_all_slave(void) { __do_free char *line = NULL; - int memfd, mntinfo_fd, ret; + __do_fclose FILE *f = NULL; + __do_close_prot_errno int memfd = -EBADF, mntinfo_fd = -EBADF; + int ret; ssize_t copied; - FILE *f; size_t len = 0; mntinfo_fd = open("/proc/self/mountinfo", O_RDONLY | O_CLOEXEC); @@ -3296,13 +3297,11 @@ void remount_all_slave(void) if (errno != ENOSYS) { SYSERROR("Failed to create temporary in-memory file"); - close(mntinfo_fd); return; } memfd = lxc_make_tmpfile(template, true); if (memfd < 0) { - close(mntinfo_fd); WARN("Failed to create temporary file"); return; } @@ -3315,30 +3314,27 @@ again: goto again; SYSERROR("Failed to copy \"/proc/self/mountinfo\""); - close(mntinfo_fd); - close(memfd); return; } - close(mntinfo_fd); - /* After a successful fdopen() memfd will be closed when calling - * fclose(f). Calling close(memfd) afterwards is undefined. - */ ret = lseek(memfd, 0, SEEK_SET); if (ret < 0) { SYSERROR("Failed to reset file descriptor offset"); - close(memfd); return; } f = fdopen(memfd, "r"); if (!f) { - SYSERROR("Failed to open copy of \"/proc/self/mountinfo\" to mark " - "all shared. Continuing"); - close(memfd); + SYSERROR("Failed to open copy of \"/proc/self/mountinfo\" to mark all shared. Continuing"); return; } + /* + * After a successful fdopen() memfd will be closed when calling + * fclose(f). Calling close(memfd) afterwards is undefined. + */ + move_fd(memfd); + while (getline(&line, &len, f) != -1) { char *opts, *target; @@ -3363,7 +3359,6 @@ again: } TRACE("Remounted \"%s\" as MS_SLAVE", target); } - fclose(f); TRACE("Remounted all mount table entries as MS_SLAVE"); }