[CRIU] [PATCH] image: open_img_dir(): add more informative var names and error handling
Ruslan Kuprieiev
kupruser at gmail.com
Sun Nov 17 12:10:23 PST 2013
Add informative names for fds and add one exit point.
Signed-off-by: Ruslan Kuprieiev <kupruser at gmail.com>
---
image.c | 44 +++++++++++++++++++++++++-------------------
1 file changed, 25 insertions(+), 19 deletions(-)
diff --git a/image.c b/image.c
index d696bdb..614478c 100644
--- a/image.c
+++ b/image.c
@@ -231,41 +231,47 @@ err:
int open_image_dir(char *dir)
{
- int fd1, fd2, ret;
+ int imgs_dir_fd, parent_dir_fd;
+ int ret = 0;
- fd1 = open(dir, O_RDONLY);
- if (fd1 < 0) {
+ imgs_dir_fd = open(dir, O_RDONLY);
+ if (imgs_dir_fd < 0) {
pr_perror("Can't open dir %s", dir);
- return -1;
+ goto exit;
}
- ret = install_service_fd(IMG_FD_OFF, fd1);
+ ret = install_service_fd(IMG_FD_OFF, imgs_dir_fd);
+ if (ret < 0) {
+ pr_perror("Can't install images dir fd");
+ goto exit;
+ }
if (opts.img_parent) {
- ret = symlinkat(opts.img_parent, fd1, CR_PARENT_LINK);
+ ret = symlinkat(opts.img_parent, imgs_dir_fd, CR_PARENT_LINK);
if (ret < 0) {
pr_perror("Can't link parent snapshot.");
- goto err;
+ goto exit;
}
- fd2 = openat(fd1, CR_PARENT_LINK, O_RDONLY);
- if (fd2 < 0) {
+ parent_dir_fd = openat(imgs_dir_fd, CR_PARENT_LINK, O_RDONLY);
+ if (parent_dir_fd < 0) {
pr_perror("Can't open parent snapshot.");
- goto err;
+ goto exit;
}
- ret = install_service_fd(PARENT_FD_OFF, fd2);
-
- close(fd2);
+ ret = install_service_fd(PARENT_FD_OFF, parent_dir_fd);
+ if (ret < 0) {
+ pr_perror("Can't install parent snapshot dir fd");
+ goto exit;
+ }
}
- close(fd1);
-
+exit:
+ close_safe(&imgs_dir_fd);
+ close_safe(&parent_dir_fd);
+ if (ret < 0)
+ close_image_dir();
return ret;
-
-err:
- close_image_dir();
- return -1;
}
void close_image_dir(void)
--
1.8.1.2
More information about the CRIU
mailing list