[CRIU] [PATCH 01/28] dump: global image names introduced
Kinsbursky Stanislav
skinsbursky at openvz.org
Thu Mar 22 13:57:37 EDT 2012
From: Stanislav Kinsbursky <skinsbursky at openvz.org>
Signed-off-by: Stanislav Kinsbursky <skinsbursky at openvz.org>
---
crtools.c | 6 ++++++
include/crtools.h | 4 ++++
util.c | 11 ++++++++++-
3 files changed, 20 insertions(+), 1 deletions(-)
-------------- next part --------------
diff --git a/crtools.c b/crtools.c
index b461679..6f067c0 100644
--- a/crtools.c
+++ b/crtools.c
@@ -235,6 +235,12 @@ struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask)
return cr_fdset_open(pid, use_mask, O_RDONLY, NULL);
}
+struct cr_fdset *cr_glob_fdset_open(unsigned long use_mask,
+ struct cr_fdset *cr_fdset)
+{
+ return cr_fdset_open(0, use_mask, O_WRONLY | O_APPEND | O_CREAT, cr_fdset);
+}
+
static int parse_ns_string(const char *ptr, unsigned int *flags)
{
const char *end = ptr + strlen(ptr);
diff --git a/include/crtools.h b/include/crtools.h
index 90eec0d..3faba43 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -105,6 +105,9 @@ int open_image(int type, unsigned long flags, ...);
#define open_image_ro(type, ...) open_image(type, O_RDONLY, __VA_ARGS__);
extern int open_image_ro_nocheck(const char *fmt, int pid);
+#define open_glob_image_ro(type) open_image(type, O_RDONLY);
+#define open_glob_image_ro_nocheck(fmt) open_image_ro_nocheck(fmt, 0);
+
#define LAST_PID_PATH "/proc/sys/kernel/ns_last_pid"
#define LAST_PID_PERM 0666
@@ -143,6 +146,7 @@ int cr_check(void);
struct cr_fdset *cr_dump_fdset_open(int pid, unsigned long use_mask, struct cr_fdset *);
struct cr_fdset *cr_show_fdset_open(int pid, unsigned long use_mask);
+struct cr_fdset *cr_glob_fdset_open(unsigned long use_mask, struct cr_fdset *);
void close_cr_fdset(struct cr_fdset **cr_fdset);
void free_mappings(struct list_head *vma_area_list);
diff --git a/util.c b/util.c
index 44d264c..cb0ab65 100644
--- a/util.c
+++ b/util.c
@@ -167,6 +167,7 @@ int open_image(int type, unsigned long flags, ...)
char path[PATH_MAX];
va_list args;
int ret;
+ int write_magic = 1;
va_start(args, flags);
vsnprintf(path, PATH_MAX, fdset_template[type].fmt, args);
@@ -180,6 +181,14 @@ int open_image(int type, unsigned long flags, ...)
}
}
+ if (flags & O_APPEND) {
+ ret = faccessat(image_dir_fd, path, R_OK, 0);
+ if (!ret)
+ write_magic = 0;
+ else if (errno != ENOENT)
+ return ret;
+ }
+
ret = openat(image_dir_fd, path, flags, CR_FD_PERM);
if (ret < 0) {
pr_perror("Unable to open %s", path);
@@ -195,7 +204,7 @@ int open_image(int type, unsigned long flags, ...)
pr_err("Magic doesn't match for %s\n", path);
goto err;
}
- } else {
+ } else if (write_magic) {
if (write_img(ret, &fdset_template[type].magic))
goto err;
}
More information about the CRIU
mailing list