If, when rotating capture files, the attempt to close the current file

fails, set "rb_data.pdh" to NULL, so we know it's not open (if
"wtap_dump_close()" fails, the wtap_dumper_t is still closed - and the
file descriptor for it is probably closed, too, as, if "close()" fails,
the FD is probably closed; the Single UNIX Specification Version 3 says
the state of the FD is unspecified, but in practice most OSes probably
still close it).

If we try to close the current file, first check to make sure it's open,
i.e. that "rb_data.pdh" is non-null.  (Or perhaps we should avoid trying
to close it if the open *or* the most recent attempt to rotate the
capture files failed.)

Note that if "wtap_dump_close()" fails we might not need to close the
underlying file descriptor (and, even if we do, there's no guarantee
that attempt won't also fail and leave the FD still open - which is why
I suspect that a failed "close()" leaves the FD closed on most OSes).

svn path=/trunk/; revision=11075
This commit is contained in:
Guy Harris 2004-06-02 18:49:40 +00:00
parent d643814e7e
commit 782e8b798b
1 changed files with 14 additions and 9 deletions

View File

@ -1,7 +1,7 @@
/* ringbuffer.c
* Routines for packet capture windows
*
* $Id: ringbuffer.c,v 1.9 2004/02/25 05:52:37 guy Exp $
* $Id: ringbuffer.c,v 1.10 2004/06/02 18:49:40 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@ -259,7 +259,8 @@ ringbuf_switch_file(capture_file *cf, wtap_dumper **pdh, int *err)
/* close current file */
if (!wtap_dump_close(rb_data.pdh, err)) {
close(rb_data.fd);
close(rb_data.fd); /* XXX - the above should have closed this already */
rb_data.pdh = NULL; /* it's still closed, we just got an error while closing */
rb_data.fd = -1;
return FALSE;
}
@ -298,16 +299,18 @@ ringbuf_wtap_dump_close(capture_file *cf, int *err)
{
gboolean ret_val = TRUE;
/* close current file */
/* close current file, if it's open */
if (rb_data.pdh != NULL) {
if (!wtap_dump_close(rb_data.pdh, err)) {
close(rb_data.fd);
ret_val = FALSE;
}
if (!wtap_dump_close(rb_data.pdh, err)) {
close(rb_data.fd);
ret_val = FALSE;
rb_data.pdh = NULL;
rb_data.fd = -1;
}
rb_data.pdh = NULL;
rb_data.fd = -1;
/* set the save file name to the current file */
cf->save_file = rb_data.files[rb_data.curr_file_num].name;
return ret_val;
}
@ -357,6 +360,8 @@ ringbuf_error_cleanup(void)
}
/* close directly if still open */
/* XXX - it shouldn't still be open; "wtap_dump_close()" should leave the
file closed even if it fails */
if (rb_data.fd != -1) {
close(rb_data.fd);
rb_data.fd = -1;