From 7f64a1dc0f97f79a4f4193bbec9fa9ca071b34c6 Mon Sep 17 00:00:00 2001 From: liangxin1300 Date: Fri, 21 Aug 2020 00:13:11 +0800 Subject: [PATCH] cmapctl: return error on no result of print prefix return EXIT_FAILURE if no result print for ACTION_PRINT_PREFIX. Signed-off-by: liangxin1300 Reviewed-by: Jan Friesse --- tools/corosync-cmapctl.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/corosync-cmapctl.c b/tools/corosync-cmapctl.c index 0a9290a3..6c79c9ac 100644 --- a/tools/corosync-cmapctl.c +++ b/tools/corosync-cmapctl.c @@ -417,13 +417,14 @@ static void print_key(cmap_handle_t handle, printf("\n"); } -static void print_iter(cmap_handle_t handle, const char *prefix) +static int print_iter(cmap_handle_t handle, const char *prefix) { cmap_iter_handle_t iter_handle; char key_name[CMAP_KEYNAME_MAXLEN + 1]; size_t value_len; cmap_value_types_t type; cs_error_t err; + int no_result = 1; err = cmap_iter_init(handle, prefix, &iter_handle); if (err != CS_OK) { @@ -432,9 +433,12 @@ static void print_iter(cmap_handle_t handle, const char *prefix) } while ((err = cmap_iter_next(handle, iter_handle, key_name, &value_len, &type)) == CS_OK) { + no_result = 0; print_key(handle, key_name, value_len, NULL, type); } + cmap_iter_finalize(handle, iter_handle); + return no_result; } static void delete_with_prefix(cmap_handle_t handle, const char *prefix) @@ -818,6 +822,7 @@ int main(int argc, char *argv[]) int no_retries; char * clear_opt = NULL; char * settings_file = NULL; + int count_of_no_result = 0; action = ACTION_PRINT_PREFIX; track_prefix = 1; @@ -922,12 +927,16 @@ int main(int argc, char *argv[]) switch (action) { case ACTION_PRINT_PREFIX: if (argc == 0) { - print_iter(handle, NULL); + count_of_no_result = print_iter(handle, NULL); } else { for (i = 0; i < argc; i++) { - print_iter(handle, argv[i]); + count_of_no_result += print_iter(handle, argv[i]); } } + + if (count_of_no_result > 0 && count_of_no_result >= argc) { + return (EXIT_FAILURE); + } break; case ACTION_GET: for (i = 0; i < argc; i++) {