diff options
author | Dario Lombardo <lomato@gmail.com> | 2017-02-04 16:26:34 +0100 |
---|---|---|
committer | Dario Lombardo <lomato@gmail.com> | 2017-02-14 10:22:20 +0000 |
commit | 7c0c580c4b0093437ee81e11934ef5b8d27a5bb4 (patch) | |
tree | 45d46758e2ce26b82b8a5d066bd9b1f23e1165ec /randpkt.c | |
parent | ae0bdcc78c6cb2719e7aa5ae24e80584dec488a3 (diff) |
wiretap: add cleanup routine.
The cleanup routine has been added to exit section of the applications.
Those which required a exit restyle have been patched as well.
Change-Id: I3a8787f0718ac7fef00dc58176869c7510fda7b1
Reviewed-on: https://code.wireshark.org/review/19949
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Dario Lombardo <lomato@gmail.com>
Diffstat (limited to 'randpkt.c')
-rw-r--r-- | randpkt.c | 54 |
1 files changed, 39 insertions, 15 deletions
@@ -49,6 +49,10 @@ #include "randpkt_core/randpkt_core.h" +#define INVALID_OPTION 1 +#define INVALID_TYPE 2 +#define CLOSE_ERROR 2 + /* * General errors are reported with an console message in randpkt. */ @@ -104,9 +108,8 @@ usage(gboolean is_error) g_strfreev(longname_list); fprintf(output, "\nIf type is not specified, a random packet will be chosen\n\n"); - - exit(is_error ? 1 : 0); } + int main(int argc, char **argv) { @@ -120,6 +123,7 @@ main(int argc, char **argv) guint8* type = NULL; int allrandom = FALSE; wtap_dumper *savedump; + int ret = EXIT_SUCCESS; static const struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {0, 0, 0, 0 } @@ -174,7 +178,8 @@ main(int argc, char **argv) produce_max_bytes = get_positive_int(optarg, "max bytes"); if (produce_max_bytes > 65536) { cmdarg_err("max bytes is > 65536"); - return 1; + ret = INVALID_OPTION; + goto clean_exit; } break; @@ -188,6 +193,7 @@ main(int argc, char **argv) case 'h': usage(FALSE); + goto clean_exit; break; case 'r': @@ -196,6 +202,8 @@ main(int argc, char **argv) default: usage(TRUE); + ret = INVALID_OPTION; + goto clean_exit; break; } } @@ -206,6 +214,8 @@ main(int argc, char **argv) } else { usage(TRUE); + ret = INVALID_OPTION; + goto clean_exit; } if (!allrandom) { @@ -213,22 +223,31 @@ main(int argc, char **argv) g_free(type); example = randpkt_find_example(produce_type); - if (!example) - return 1; + if (!example) { + ret = INVALID_OPTION; + goto clean_exit; + } - randpkt_example_init(example, produce_filename, produce_max_bytes); + ret = randpkt_example_init(example, produce_filename, produce_max_bytes); + if (ret != EXIT_SUCCESS) + goto clean_exit; randpkt_loop(example, produce_count); } else { if (type) { fprintf(stderr, "Can't set type in random mode\n"); - return 2; + ret = INVALID_TYPE; + goto clean_exit; } produce_type = randpkt_parse_type(NULL); example = randpkt_find_example(produce_type); - if (!example) - return 1; - randpkt_example_init(example, produce_filename, produce_max_bytes); + if (!example) { + ret = INVALID_OPTION; + goto clean_exit; + } + ret = randpkt_example_init(example, produce_filename, produce_max_bytes); + if (ret != EXIT_SUCCESS) + goto clean_exit; while (produce_count-- > 0) { randpkt_loop(example, 1); @@ -237,15 +256,20 @@ main(int argc, char **argv) savedump = example->dump; example = randpkt_find_example(produce_type); - if (!example) - return 1; + if (!example) { + ret = INVALID_OPTION; + goto clean_exit; + } example->dump = savedump; } } - if (!randpkt_example_close(example)) - return 2; - return 0; + if (!randpkt_example_close(example)) { + ret = CLOSE_ERROR; + } +clean_exit: + wtap_cleanup(); + return ret; } /* |