bfd: Don't flush read-only images

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
Pavel Emelyanov 2014-10-29 15:44:00 +04:00
parent 1ef5ca8235
commit 2e91a9c814
4 changed files with 9 additions and 13 deletions

11
bfd.c
View file

@ -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

View file

@ -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)

View file

@ -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);

View file

@ -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) {