* cache.c (bfd_cache_lookup_worker): Don't abort on failing to

reopen file.
	(cache_btell, cache_bseek, cache_bflush, cache_bstat): Return -1 on
	bfd_cache_lookup failure.
	(cache_bread, cache_bwrite): Return 0 on the same.
	* bfdwin.c (bfd_get_file_window): Likewise.
	* hppabsd-core.c (hppabsd_core_core_file_p): Likewise.
	* sco5-core.c (sco5_core_file_p): Likewise.
	* trad-core.c (trad_unix_core_file_p): Likewise.
This commit is contained in:
Alan Modra 2005-10-26 12:17:42 +00:00
parent 89feb2c412
commit 3dff57e847
6 changed files with 54 additions and 12 deletions

View file

@ -1,3 +1,15 @@
2005-10-26 Alan Modra <amodra@bigpond.net.au>
* cache.c (bfd_cache_lookup_worker): Don't abort on failing to
reopen file.
(cache_btell, cache_bseek, cache_bflush, cache_bstat): Return -1 on
bfd_cache_lookup failure.
(cache_bread, cache_bwrite): Return 0 on the same.
* bfdwin.c (bfd_get_file_window): Likewise.
* hppabsd-core.c (hppabsd_core_core_file_p): Likewise.
* sco5-core.c (sco5_core_file_p): Likewise.
* trad-core.c (trad_unix_core_file_p): Likewise.
2005-10-26 Alan Modra <amodra@bigpond.net.au> 2005-10-26 Alan Modra <amodra@bigpond.net.au>
* cache.c (bfd_cache_lookup_worker): Use bfd_error_handler * cache.c (bfd_cache_lookup_worker): Use bfd_error_handler

View file

@ -153,6 +153,8 @@ bfd_get_file_window (bfd *abfd,
abfd = abfd->my_archive; abfd = abfd->my_archive;
} }
f = bfd_cache_lookup (abfd); f = bfd_cache_lookup (abfd);
if (f == NULL)
return FALSE;
fd = fileno (f); fd = fileno (f);
/* Compute offsets and size for mmap and for the user's data. */ /* Compute offsets and size for mmap and for the user's data. */

View file

@ -51,13 +51,19 @@ static bfd_boolean bfd_cache_delete (bfd *);
static file_ptr static file_ptr
cache_btell (struct bfd *abfd) cache_btell (struct bfd *abfd)
{ {
return real_ftell (bfd_cache_lookup (abfd)); FILE *f = bfd_cache_lookup (abfd);
if (f == NULL)
return -1;
return real_ftell (f);
} }
static int static int
cache_bseek (struct bfd *abfd, file_ptr offset, int whence) cache_bseek (struct bfd *abfd, file_ptr offset, int whence)
{ {
return real_fseek (bfd_cache_lookup (abfd), offset, whence); FILE *f = bfd_cache_lookup (abfd);
if (f == NULL)
return -1;
return real_fseek (f, offset, whence);
} }
/* Note that archive entries don't have streams; they share their parent's. /* Note that archive entries don't have streams; they share their parent's.
@ -70,6 +76,7 @@ cache_bseek (struct bfd *abfd, file_ptr offset, int whence)
static file_ptr static file_ptr
cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes) cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
{ {
FILE *f;
file_ptr nread; file_ptr nread;
/* FIXME - this looks like an optimization, but it's really to cover /* FIXME - this looks like an optimization, but it's really to cover
up for a feature of some OSs (not solaris - sigh) that up for a feature of some OSs (not solaris - sigh) that
@ -83,10 +90,14 @@ cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
if (nbytes == 0) if (nbytes == 0)
return 0; return 0;
f = bfd_cache_lookup (abfd);
if (f == NULL)
return 0;
#if defined (__VAX) && defined (VMS) #if defined (__VAX) && defined (VMS)
/* Apparently fread on Vax VMS does not keep the record length /* Apparently fread on Vax VMS does not keep the record length
information. */ information. */
nread = read (fileno (bfd_cache_lookup (abfd)), buf, nbytes); nread = read (fileno (f), buf, nbytes);
/* Set bfd_error if we did not read as much data as we expected. If /* Set bfd_error if we did not read as much data as we expected. If
the read failed due to an error set the bfd_error_system_call, the read failed due to an error set the bfd_error_system_call,
else set bfd_error_file_truncated. */ else set bfd_error_file_truncated. */
@ -96,11 +107,11 @@ cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
return -1; return -1;
} }
#else #else
nread = fread (buf, 1, nbytes, bfd_cache_lookup (abfd)); nread = fread (buf, 1, nbytes, f);
/* Set bfd_error if we did not read as much data as we expected. If /* Set bfd_error if we did not read as much data as we expected. If
the read failed due to an error set the bfd_error_system_call, the read failed due to an error set the bfd_error_system_call,
else set bfd_error_file_truncated. */ else set bfd_error_file_truncated. */
if (nread < nbytes && ferror (bfd_cache_lookup (abfd))) if (nread < nbytes && ferror (f))
{ {
bfd_set_error (bfd_error_system_call); bfd_set_error (bfd_error_system_call);
return -1; return -1;
@ -112,8 +123,12 @@ cache_bread (struct bfd *abfd, void *buf, file_ptr nbytes)
static file_ptr static file_ptr
cache_bwrite (struct bfd *abfd, const void *where, file_ptr nbytes) cache_bwrite (struct bfd *abfd, const void *where, file_ptr nbytes)
{ {
file_ptr nwrite = fwrite (where, 1, nbytes, bfd_cache_lookup (abfd)); file_ptr nwrite;
if (nwrite < nbytes && ferror (bfd_cache_lookup (abfd))) FILE *f = bfd_cache_lookup (abfd);
if (f == NULL)
return 0;
nwrite = fwrite (where, 1, nbytes, f);
if (nwrite < nbytes && ferror (f))
{ {
bfd_set_error (bfd_error_system_call); bfd_set_error (bfd_error_system_call);
return -1; return -1;
@ -130,7 +145,11 @@ cache_bclose (struct bfd *abfd)
static int static int
cache_bflush (struct bfd *abfd) cache_bflush (struct bfd *abfd)
{ {
int sts = fflush (bfd_cache_lookup (abfd)); int sts;
FILE *f = bfd_cache_lookup (abfd);
if (f == NULL)
return -1;
sts = fflush (f);
if (sts < 0) if (sts < 0)
bfd_set_error (bfd_error_system_call); bfd_set_error (bfd_error_system_call);
return sts; return sts;
@ -139,7 +158,11 @@ cache_bflush (struct bfd *abfd)
static int static int
cache_bstat (struct bfd *abfd, struct stat *sb) cache_bstat (struct bfd *abfd, struct stat *sb)
{ {
int sts = fstat (fileno (bfd_cache_lookup (abfd)), sb); int sts;
FILE *f = bfd_cache_lookup (abfd);
if (f == NULL)
return -1;
sts = fstat (fileno (f), sb);
if (sts < 0) if (sts < 0)
bfd_set_error (bfd_error_system_call); bfd_set_error (bfd_error_system_call);
return sts; return sts;
@ -470,8 +493,8 @@ DESCRIPTION
quick answer. Find a file descriptor for @var{abfd}. If quick answer. Find a file descriptor for @var{abfd}. If
necessary, it open it. If there are already more than necessary, it open it. If there are already more than
<<BFD_CACHE_MAX_OPEN>> files open, it tries to close one first, to <<BFD_CACHE_MAX_OPEN>> files open, it tries to close one first, to
avoid running out of file descriptors. It will abort rather than avoid running out of file descriptors. It will return NULL
returning NULL if it is unable to (re)open the @var{abfd}. if it is unable to (re)open the @var{abfd}.
*/ */
FILE * FILE *
@ -504,6 +527,5 @@ bfd_cache_lookup_worker (bfd *abfd)
(*_bfd_error_handler) (_("reopening %B: %s\n"), (*_bfd_error_handler) (_("reopening %B: %s\n"),
orig_bfd, bfd_errmsg (bfd_get_error ())); orig_bfd, bfd_errmsg (bfd_get_error ()));
abort ();
return NULL; return NULL;
} }

View file

@ -140,6 +140,8 @@ hppabsd_core_core_file_p (abfd)
FILE *stream = bfd_cache_lookup (abfd); FILE *stream = bfd_cache_lookup (abfd);
struct stat statbuf; struct stat statbuf;
if (stream == NULL)
return NULL;
if (fstat (fileno (stream), &statbuf) < 0) if (fstat (fileno (stream), &statbuf) < 0)
{ {
bfd_set_error (bfd_error_system_call); bfd_set_error (bfd_error_system_call);

View file

@ -129,6 +129,8 @@ sco5_core_file_p (abfd)
FILE *stream = bfd_cache_lookup (abfd); FILE *stream = bfd_cache_lookup (abfd);
struct stat statbuf; struct stat statbuf;
if (stream == NULL)
return NULL;
if (fstat (fileno (stream), &statbuf) < 0) if (fstat (fileno (stream), &statbuf) < 0)
{ {
bfd_set_error (bfd_error_system_call); bfd_set_error (bfd_error_system_call);

View file

@ -112,6 +112,8 @@ trad_unix_core_file_p (abfd)
FILE *stream = bfd_cache_lookup (abfd); FILE *stream = bfd_cache_lookup (abfd);
struct stat statbuf; struct stat statbuf;
if (stream == NULL)
return 0;
if (fstat (fileno (stream), &statbuf) < 0) if (fstat (fileno (stream), &statbuf) < 0)
{ {
bfd_set_error (bfd_error_system_call); bfd_set_error (bfd_error_system_call);