From f957d895cd0953e6cb8ea387fb514e3732b05dd9 Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Mon, 17 Oct 2022 18:53:57 +0000 Subject: [PATCH] zdump: consolidate error reporting MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consolidate error reporting to make sure that error messages are used consistently. In addition, don't call `zg_exit()` directly, but instead return the value 1 in `main()`. Signed-off-by: Marc Hartmayer Reviewed-by: Steffen Eiden Acked-by: Alexander Egorenkov Signed-off-by: Jan Höppner --- zdump/zgetdump.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/zdump/zgetdump.c b/zdump/zgetdump.c index 6096afee..e880c058 100644 --- a/zdump/zgetdump.c +++ b/zdump/zgetdump.c @@ -26,6 +26,7 @@ #include #include +#include "lib/zt_common.h" #include "zgetdump.h" #include "dt.h" #include "dfi.h" @@ -105,6 +106,12 @@ static void kdump_select_check(void) ERR_EXIT("%s", msg); } +static int dfi_init_error(int UNUSED(rc)) +{ + STDERR("Dump cannot be processed (is not complete)\n"); + return 1; +} + /* * Run "--umount" action */ @@ -129,10 +136,13 @@ static int do_device_info(void) */ static int do_dump_info(void) { - if (dfi_init() != 0) { + int rc; + + rc = dfi_init(); + if (rc != 0) { dfi_info_print(); - STDERR("\nERROR: Dump is not complete\n"); - zg_exit(1); + STDERR("\n"); + return dfi_init_error(rc); } kdump_select_check(); dfi_info_print(); @@ -147,8 +157,9 @@ static int do_mount(void) { int rc; - if (dfi_init() != 0) - ERR_EXIT("Dump cannot be processed (is not complete)"); + rc = dfi_init(); + if (rc != 0) + return dfi_init_error(rc); dfo_init(); kdump_select_check(); rc = zfuse_mount_dump(); @@ -189,8 +200,9 @@ static int do_copy(const char *output) FILE *stream; int rc; - if (dfi_init() != 0) - ERR_EXIT("Dump cannot be processed (is not complete)"); + rc = dfi_init(); + if (rc != 0) + return dfi_init_error(rc); dfo_init(); kdump_select_check(); stream = open_file_for_writing(output);