[PATCH 1/7] image: open_image_at -- Add O_OPT flag
Cyrill Gorcunov
gorcunov at openvz.org
Thu Mar 13 05:06:37 PDT 2014
This allows us to distinguish the situation where image
to be opened is missing but optional, thus no error message
should be printed.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
image.c | 5 +++++
include/image.h | 1 +
2 files changed, 6 insertions(+)
diff --git a/image.c b/image.c
index 630ac9b4a2ad..307c8beca154 100644
--- a/image.c
+++ b/image.c
@@ -184,16 +184,21 @@ struct cr_fdset *cr_glob_fdset_open(int mode)
int open_image_at(int dfd, int type, unsigned long flags, ...)
{
+ bool optional = !!(flags & O_OPT);
char path[PATH_MAX];
va_list args;
int ret;
+ flags &= ~O_OPT;
+
va_start(args, flags);
vsnprintf(path, PATH_MAX, fdset_template[type].fmt, args);
va_end(args);
ret = openat(dfd, path, flags, CR_FD_PERM);
if (ret < 0) {
+ if (optional && errno == ENOENT)
+ return -ENOENT;
pr_perror("Unable to open %s", path);
goto err;
}
diff --git a/include/image.h b/include/image.h
index af69de9b6ab0..a0ac8b112e93 100644
--- a/include/image.h
+++ b/include/image.h
@@ -68,6 +68,7 @@ extern bool ns_per_id;
#define O_DUMP (O_RDWR | O_CREAT | O_TRUNC)
#define O_SHOW (O_RDONLY)
#define O_RSTR (O_RDONLY)
+#define O_OPT (O_PATH)
extern int open_image_dir(char *dir);
extern void close_image_dir(void);
--
1.8.3.1
--qDbXVdCdHGoSgWSk--
More information about the CRIU
mailing list