conf: cleanup macros remount_all_slave

parent 3275932b
...@@ -3279,9 +3279,10 @@ void tmp_proc_unmount(struct lxc_conf *lxc_conf) ...@@ -3279,9 +3279,10 @@ void tmp_proc_unmount(struct lxc_conf *lxc_conf)
void remount_all_slave(void) void remount_all_slave(void)
{ {
__do_free char *line = NULL; __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; ssize_t copied;
FILE *f;
size_t len = 0; size_t len = 0;
mntinfo_fd = open("/proc/self/mountinfo", O_RDONLY | O_CLOEXEC); mntinfo_fd = open("/proc/self/mountinfo", O_RDONLY | O_CLOEXEC);
...@@ -3296,13 +3297,11 @@ void remount_all_slave(void) ...@@ -3296,13 +3297,11 @@ void remount_all_slave(void)
if (errno != ENOSYS) { if (errno != ENOSYS) {
SYSERROR("Failed to create temporary in-memory file"); SYSERROR("Failed to create temporary in-memory file");
close(mntinfo_fd);
return; return;
} }
memfd = lxc_make_tmpfile(template, true); memfd = lxc_make_tmpfile(template, true);
if (memfd < 0) { if (memfd < 0) {
close(mntinfo_fd);
WARN("Failed to create temporary file"); WARN("Failed to create temporary file");
return; return;
} }
...@@ -3315,30 +3314,27 @@ again: ...@@ -3315,30 +3314,27 @@ again:
goto again; goto again;
SYSERROR("Failed to copy \"/proc/self/mountinfo\""); SYSERROR("Failed to copy \"/proc/self/mountinfo\"");
close(mntinfo_fd);
close(memfd);
return; 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); ret = lseek(memfd, 0, SEEK_SET);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to reset file descriptor offset"); SYSERROR("Failed to reset file descriptor offset");
close(memfd);
return; return;
} }
f = fdopen(memfd, "r"); f = fdopen(memfd, "r");
if (!f) { if (!f) {
SYSERROR("Failed to open copy of \"/proc/self/mountinfo\" to mark " SYSERROR("Failed to open copy of \"/proc/self/mountinfo\" to mark all shared. Continuing");
"all shared. Continuing");
close(memfd);
return; 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) { while (getline(&line, &len, f) != -1) {
char *opts, *target; char *opts, *target;
...@@ -3363,7 +3359,6 @@ again: ...@@ -3363,7 +3359,6 @@ again:
} }
TRACE("Remounted \"%s\" as MS_SLAVE", target); TRACE("Remounted \"%s\" as MS_SLAVE", target);
} }
fclose(f);
TRACE("Remounted all mount table entries as MS_SLAVE"); TRACE("Remounted all mount table entries as MS_SLAVE");
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment