Commit 2e91a9c8 authored by Pavel Emelyanov's avatar Pavel Emelyanov

bfd: Don't flush read-only images

Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 1ef5ca82
......@@ -86,13 +86,14 @@ static void buf_put(struct xbuf *xb)
xb->data = NULL;
}
int bfdopen(struct bfd *f)
int bfdopen(struct bfd *f, int mode)
{
if (buf_get(&f->b)) {
close(f->fd);
return -1;
}
f->mode = mode;
return 0;
}
......@@ -107,13 +108,7 @@ int bfd_flush_images(void)
void bclose(struct bfd *f)
{
if (bfd_buffered(f)) {
/*
* FIXME -- when we bread from images we don't
* need to flush. This call doesn't fail simply
* becase we read _all_ data from them and the
* b->sz would be 0 by the time we close them.
*/
if (bflush(f) < 0) {
if ((f->mode != O_RDONLY) && bflush(f) < 0) {
/*
* This is to propagate error up. It's
* hardly possible by returning and
......
......@@ -235,7 +235,7 @@ struct cr_img *open_image_at(int dfd, int type, unsigned long flags, ...)
img->_x.fd = ret;
if (oflags & O_NOBUF)
bfd_setraw(&img->_x);
else if (bfdopen(&img->_x))
else if (bfdopen(&img->_x, flags))
goto err;
if (imgset_template[type].magic == RAW_IMAGE_MAGIC)
......
......@@ -13,6 +13,7 @@ struct xbuf {
struct bfd {
int fd;
int mode;
struct xbuf b;
};
......@@ -26,7 +27,7 @@ static inline void bfd_setraw(struct bfd *b)
b->b.mem = NULL;
}
int bfdopen(struct bfd *f);
int bfdopen(struct bfd *f, int mode);
void bclose(struct bfd *f);
char *breadline(struct bfd *f);
int bwrite(struct bfd *f, const void *buf, int sz);
......
......@@ -313,7 +313,7 @@ int parse_smaps(pid_t pid, struct vm_area_list *vma_area_list, bool use_map_file
if (f.fd < 0)
goto err_n;
if (bfdopen(&f))
if (bfdopen(&f, O_RDONLY))
goto err_n;
if (use_map_files) {
......@@ -1158,7 +1158,7 @@ static int parse_fdinfo_pid_s(int pid, int fd, int type,
return -1;
}
if (bfdopen(&f))
if (bfdopen(&f, O_RDONLY))
return -1;
while (1) {
......@@ -1613,7 +1613,7 @@ int parse_posix_timers(pid_t pid, struct proc_posix_timers_stat *args)
return -1;
}
if (bfdopen(&f))
if (bfdopen(&f, O_RDONLY))
return -1;
while (1) {
......
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