aboutsummaryrefslogtreecommitdiffstats
path: root/ringbuffer.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2004-06-02 18:49:40 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2004-06-02 18:49:40 +0000
commit3d7822ee9e8aee0518060f5f153fde7c121b4e34 (patch)
tree9b6ad66791960b728f7ecc8999e5536b6a1700be /ringbuffer.c
parent611362ce68cf5c7e93358a9724da6326431ee4c5 (diff)
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). git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@11075 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'ringbuffer.c')
-rw-r--r--ringbuffer.c23
1 files changed, 14 insertions, 9 deletions
diff --git a/ringbuffer.c b/ringbuffer.c
index 453697e6d0..0828449461 100644
--- a/ringbuffer.c
+++ b/ringbuffer.c
@@ -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;