wiretap: have wtap_dump_flush(), and its callers, check for errors.

Change-Id: Ibcddf1a949f775afa49d36a2d165c3685556035d
Reviewed-on: https://code.wireshark.org/review/38104
Petri-Dish: Guy Harris <gharris@sonic.net>
Tested-by: Petri Dish Buildbot
Reviewed-by: Guy Harris <gharris@sonic.net>
This commit is contained in:
Guy Harris 2020-08-09 14:41:11 -07:00
parent fcd7492566
commit 74e917fc6c
6 changed files with 35 additions and 10 deletions

View File

@ -1192,7 +1192,10 @@ snort_dissector(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data
current_session.working = FALSE;
return 0;
}
wtap_dump_flush(current_session.pdh);
if (!wtap_dump_flush(current_session.pdh, &write_err)) {
current_session.working = FALSE;
return 0;
}
/* Give the io channel a chance to deliver alerts.
TODO: g_main_context_iteration(NULL, FALSE); causes crashes sometimes when Qt events get to execute.. */

View File

@ -298,10 +298,14 @@ WSLUA_METHOD Dumper_flush(lua_State* L) {
Writes all unsaved data of a dumper to the disk.
*/
Dumper d = checkDumper(L,1);
int err;
if (!d) return 0;
wtap_dump_flush(d);
if (!wtap_dump_flush(d, &err)) {
luaL_error(L,"error while dumping: %s",
wtap_strerror(err));
}
return 0;
}

View File

@ -460,7 +460,10 @@ static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) {
exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
}
extcap_dumper.encap = encap;
wtap_dump_flush(extcap_dumper.dumper.wtap);
if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
cfile_dump_open_failure_message("androiddump", fifo, err, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC);
exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
}
#endif
return extcap_dumper;
@ -521,7 +524,11 @@ static gboolean extcap_dumper_dump(struct extcap_dumper extcap_dumper,
return FALSE;
}
wtap_dump_flush(extcap_dumper.dumper.wtap);
if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
cfile_write_failure_message("androiddump", NULL, fifo, err, NULL,
0, WTAP_FILE_TYPE_SUBTYPE_PCAP_NSEC);
return FALSE;
}
#endif
return TRUE;

View File

@ -626,7 +626,11 @@ void randpkt_loop(randpkt_example* example, guint64 produce_count, guint64 packe
}
if (packet_delay_ms) {
g_usleep(1000 * (gulong)packet_delay_ms);
wtap_dump_flush(example->dump);
if (!wtap_dump_flush(example->dump, &err)) {
cfile_write_failure_message("randpkt", NULL,
example->filename, err, NULL, 0,
WTAP_FILE_TYPE_SUBTYPE_PCAP);
}
}
}

View File

@ -2668,17 +2668,24 @@ wtap_dump(wtap_dumper *wdh, const wtap_rec *rec,
return (wdh->subtype_write)(wdh, rec, pd, err, err_info);
}
void
wtap_dump_flush(wtap_dumper *wdh)
gboolean
wtap_dump_flush(wtap_dumper *wdh, int *err)
{
#ifdef HAVE_ZLIB
if (wdh->compression_type == WTAP_GZIP_COMPRESSED) {
gzwfile_flush((GZWFILE_T)wdh->fh);
if (gzwfile_flush((GZWFILE_T)wdh->fh) == -1) {
*err = gzwfile_geterr((GZWFILE_T)wdh->fh);
return FALSE;
}
} else
#endif
{
fflush((FILE *)wdh->fh);
if (fflush((FILE *)wdh->fh) == EOF) {
*err = errno;
return FALSE;
}
}
return TRUE;
}
gboolean

View File

@ -2172,7 +2172,7 @@ WS_DLL_PUBLIC
gboolean wtap_dump(wtap_dumper *, const wtap_rec *, const guint8 *,
int *err, gchar **err_info);
WS_DLL_PUBLIC
void wtap_dump_flush(wtap_dumper *);
gboolean wtap_dump_flush(wtap_dumper *, int *);
WS_DLL_PUBLIC
gint64 wtap_get_bytes_dumped(wtap_dumper *);
WS_DLL_PUBLIC