From e9f5e045f743fd3220f1c8d9ba68214f1feb7359 Mon Sep 17 00:00:00 2001 From: Guy Harris Date: Sun, 23 Apr 2017 01:18:02 -0700 Subject: [PATCH] Just have read_cap_file()/read_file() return a success/failure indication. No need to report the precise error code - it's already reported the error. Change-Id: Ib52daf094253deac2a10d16793ebf0f42581afd6 Reviewed-on: https://code.wireshark.org/review/21292 Reviewed-by: Guy Harris --- tfshark.c | 17 +++++++++-------- tshark.c | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/tfshark.c b/tfshark.c index b58d71dd9a..5dc3843ad6 100644 --- a/tfshark.c +++ b/tfshark.c @@ -136,7 +136,7 @@ static output_fields_t* output_fields = NULL; /* The line separator used between packets, changeable via the -S option */ static const char *separator = ""; -static int read_file(capture_file *, int, gint64); +static gboolean read_file(capture_file *, int, gint64); static gboolean process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, struct wtap_pkthdr *whdr, const guchar *pd, guint tap_flags); @@ -336,6 +336,7 @@ main(int argc, char *argv[]) gboolean arg_error = FALSE; int err; + gboolean success; volatile int exit_status = 0; gboolean quiet = FALSE; gchar *volatile cf_name = NULL; @@ -981,7 +982,7 @@ main(int argc, char *argv[]) /* Process the packets in the file */ TRY { /* XXX - for now there is only 1 packet */ - err = read_file(&cfile, 1, 0); + success = read_file(&cfile, 1, 0); } CATCH(OutOfMemoryError) { fprintf(stderr, @@ -991,11 +992,11 @@ main(int argc, char *argv[]) "\n" "Some infos / workarounds can be found at:\n" "https://wiki.wireshark.org/KnownBugs/OutOfMemory\n"); - err = ENOMEM; + success = FALSE; } ENDTRY; - if (err != 0) { + if (!success) { /* We still dump out the results of taps, etc., as we might have read some packets; however, we exit with an error status. */ exit_status = 2; @@ -1294,7 +1295,7 @@ local_wtap_read(capture_file *cf, struct wtap_pkthdr* file_phdr _U_, int *err, g return TRUE; /* success */ } -static int +static gboolean read_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) { guint32 framenum; @@ -1423,7 +1424,7 @@ read_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) #else if (!process_packet_second_pass(cf, edt, fdata, &cf->phdr, &buf, tap_flags)) - return 2; + return FALSE; #endif } @@ -1479,7 +1480,7 @@ read_file(capture_file *cf, int max_packet_count, gint64 max_byte_count) if (!process_packet_single_pass(cf, edt, data_offset, &file_phdr/*wtap_phdr(cf->wth)*/, raw_data, tap_flags)) - return 2; + return FALSE; /* Stop reading if we have the maximum number of packets; * When the -c option has not been used, max_packet_count @@ -1580,7 +1581,7 @@ out: wtap_close(cf->wth); cf->wth = NULL; - return err; + return (err != 0); } static gboolean diff --git a/tshark.c b/tshark.c index 269d1d2c42..82ca3197fe 100644 --- a/tshark.c +++ b/tshark.c @@ -228,7 +228,7 @@ static char *output_file_name; #endif /* HAVE_LIBPCAP */ -static int read_cap_file(capture_file *, char *, int, gboolean, int, gint64); +static gboolean read_cap_file(capture_file *, char *, int, gboolean, int, gint64); static gboolean process_packet_single_pass(capture_file *cf, epan_dissect_t *edt, gint64 offset, struct wtap_pkthdr *whdr, const guchar *pd, guint tap_flags); @@ -650,6 +650,7 @@ main(int argc, char *argv[]) #endif /* _WIN32 */ int err; + gboolean success; volatile int exit_status = EXIT_SUCCESS; #ifdef HAVE_LIBPCAP gboolean list_link_layer_types = FALSE; @@ -1951,11 +1952,11 @@ main(int argc, char *argv[]) tshark_debug("tshark: invoking read_cap_file() to process the packets"); TRY { #ifdef HAVE_LIBPCAP - err = read_cap_file(&cfile, global_capture_opts.save_file, out_file_type, out_file_name_res, + success = read_cap_file(&cfile, global_capture_opts.save_file, out_file_type, out_file_name_res, global_capture_opts.has_autostop_packets ? global_capture_opts.autostop_packets : 0, global_capture_opts.has_autostop_filesize ? global_capture_opts.autostop_filesize : 0); #else - err = read_cap_file(&cfile, output_file_name, out_file_type, out_file_name_res, 0, 0); + success = read_cap_file(&cfile, output_file_name, out_file_type, out_file_name_res, 0, 0); #endif } CATCH(OutOfMemoryError) { @@ -1966,10 +1967,11 @@ main(int argc, char *argv[]) "\n" "More information and workarounds can be found at\n" "https://wiki.wireshark.org/KnownBugs/OutOfMemory\n"); - err = ENOMEM; + success = FALSE; } ENDTRY; - if (err != 0) { + + if (!success) { /* We still dump out the results of taps, etc., as we might have read some packets; however, we exit with an error status. */ exit_status = 2; @@ -2088,8 +2090,7 @@ main(int argc, char *argv[]) if (print_packet_info) { if (!write_finale()) { - err = errno; - show_print_file_io_error(err); + show_print_file_io_error(errno); } } #else @@ -2941,7 +2942,7 @@ process_packet_second_pass(capture_file *cf, epan_dissect_t *edt, return passed || fdata->flags.dependent_of_displayed; } -static int +static gboolean read_cap_file(capture_file *cf, char *save_file, int out_file_type, gboolean out_file_name_res, int max_packet_count, gint64 max_byte_count) { @@ -3329,7 +3330,7 @@ out: wtap_block_array_free(shb_hdrs); wtap_block_array_free(nrb_hdrs); - return err; + return (err == 0); } static gboolean