From 448727115fe591bf97fe9f1ca427f9dd07673959 Mon Sep 17 00:00:00 2001 From: liupei Date: Mon, 18 Mar 2024 19:22:56 +0800 Subject: [PATCH] postparse: improve "file:line: error message" reporting (cherry picked from commit 1b2818a7679e419b05b28710a3e63503b1c9bd24) --- drbd.spec | 8 +- ...ve-file-line-error-message-reporting.patch | 115 ++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 postparse-improve-file-line-error-message-reporting.patch diff --git a/drbd.spec b/drbd.spec index d2d7b83..6682e99 100644 --- a/drbd.spec +++ b/drbd.spec @@ -1,10 +1,12 @@ Name: drbd Summary: DRBD user-land tools and scripts Version: 9.27.0 -Release: 1 +Release: 2 Source0: http://www.linbit.com/downloads/%{name}/utils/%{name}-utils-%{version}.tar.gz Patch0: drbd-utils-9.12.2-disable_xsltproc_network_read.patch Patch1: drbd-utils-9.15.0-make_configure-workaround.patch +Patch2: postparse-improve-file-line-error-message-reporting.patch +# https://github.com/LINBIT/drbd-utils/commit/60003dc13d0ce1533a831ec2d4cd3e4c7697ffa0 License: GPL-2.0-or-later ExclusiveOS: linux @@ -41,6 +43,7 @@ This is a virtual package, installing the full user-land suite. # Don't let xsltproc make network calls during build %patch 0 -p1 %patch 1 -p1 +%patch 2 -p1 %build %configure \ @@ -216,6 +219,9 @@ management utility. %systemd_preun drbd.service %changelog +* Mon Mar 18 2024 liupei - 9.27.0-2 +- postparse: improve "file:line: error message" reporting + * Fri Mar 15 2024 liupei - 9.27.0-1 - update to 9.27.0 diff --git a/postparse-improve-file-line-error-message-reporting.patch b/postparse-improve-file-line-error-message-reporting.patch new file mode 100644 index 0000000..07a7d98 --- /dev/null +++ b/postparse-improve-file-line-error-message-reporting.patch @@ -0,0 +1,115 @@ +From 60003dc13d0ce1533a831ec2d4cd3e4c7697ffa0 Mon Sep 17 00:00:00 2001 +From: Lars Ellenberg +Date: Wed, 29 Nov 2023 16:06:29 +0100 +Subject: [PATCH 01/10] postparse: improve "file:line: error message" reporting + +For some errors detected during the post-parse stage, +we reported the last line of the main config file, +when we meant to report the file and line +where the resource definition can be found. + +Also reset the line, not only the config file name +when parsing the argument to --config-to-test. +Re-use "include_file()" for that instead of open-coding it. + +We could potentially even re-use "include_stmt()" here +to allow globbing in --config-to-test. +--- + user/v9/drbdadm_main.c | 17 ++++------------- + user/v9/drbdadm_postparse.c | 12 ++++++------ + 2 files changed, 10 insertions(+), 19 deletions(-) + +diff --git a/user/v9/drbdadm_main.c b/user/v9/drbdadm_main.c +index 29d548a7..19addea9 100644 +--- a/user/v9/drbdadm_main.c ++++ b/user/v9/drbdadm_main.c +@@ -3490,24 +3490,15 @@ int main(int argc, char **argv) + config_save = canonify_path(config_file); + + my_parse(); ++ fclose(yyin); + + if (config_test) { +- char *saved_config_file = config_file; +- char *saved_config_save = config_save; +- +- config_file = config_test; +- config_save = canonify_path(config_test); +- +- fclose(yyin); +- yyin = fopen(config_test, "r"); +- if (!yyin) { ++ FILE *f = fopen(config_test, "r"); ++ if (!f) { + log_err("Can not open '%s'.\n.", config_test); + exit(E_EXEC_ERROR); + } +- my_parse(); +- +- config_file = saved_config_file; +- config_save = saved_config_save; ++ include_file(f, config_test); + } + + if (!config_valid) +diff --git a/user/v9/drbdadm_postparse.c b/user/v9/drbdadm_postparse.c +index 72ffba63..ca4f7c60 100644 +--- a/user/v9/drbdadm_postparse.c ++++ b/user/v9/drbdadm_postparse.c +@@ -198,7 +198,7 @@ static void _set_host_info_in_host_address_pairs(struct d_resource *res, + log_err("%s:%d: in resource %s a hostname (\"%s\") is given\n" + "with a \"host\" keyword, has no \"address\" keyword, and no matching\n" + "host section (\"on\" keyword)\n", +- config_file, ha->config_line, res->name, ha->name); ++ res->config_file, ha->config_line, res->name, ha->name); + config_valid = 0; + /* Can't continue. */ + return; +@@ -225,7 +225,7 @@ static void _set_host_info_in_host_address_pairs(struct d_resource *res, + if (!(have_address && have_port)) { + log_err("%s:%d: Resource %s, host %s: " + "cannot determine which %s%s%s to use\n", +- config_file, ha->config_line, res->name, ++ res->config_file, ha->config_line, res->name, + ha->name, have_address ? "" : "address", + have_address != have_port ? "" : " and ", + have_port ? "" : "port"); +@@ -707,7 +707,7 @@ static void check_volume_sets_equal(struct d_resource *res, struct d_host_info * + while (a || b) { + while (a && (!b || a->vnr < b->vnr)) { + log_err("%s:%d: in resource %s, on %s { ... }: volume %d not defined on %s\n", +- config_file, line, res->name, ++ res->config_file, res->start_line, res->name, + names_to_str(&host1->on_hosts), a->vnr, + compare_stacked ? host1->lower->name : names_to_str(&host2->on_hosts)); + a = STAILQ_NEXT(a, link); +@@ -721,7 +721,7 @@ static void check_volume_sets_equal(struct d_resource *res, struct d_host_info * + if (!(compare_stacked && no_tty)) + log_err("%s:%d: in resource %s, on %s { ... }: " + "volume %d missing (present on %s)\n", +- config_file, line, res->name, ++ res->config_file, res->start_line, res->name, + names_to_str(&host1->on_hosts), b->vnr, + compare_stacked ? host1->lower->name : names_to_str(&host2->on_hosts)); + if (!compare_stacked) +@@ -731,7 +731,7 @@ static void check_volume_sets_equal(struct d_resource *res, struct d_host_info * + if (a && b && a->vnr == b->vnr) { + if (a->implicit != b->implicit) { + log_err("%s:%d: in resource %s, on %s resp. %s: volume %d must not be implicit on one but not the other\n", +- config_file, line, res->name, ++ res->config_file, res->start_line, res->name, + names_to_str(&host1->on_hosts), + compare_stacked ? host1->lower->name : names_to_str(&host2->on_hosts), + a->vnr); +@@ -1151,7 +1151,7 @@ void post_parse(struct resources *resources, enum pp_flags flags) + + if (any_implicit && any_non_zero_vnr) { + log_err("%s:%d: in resource %s: you must not mix implicit and explicit volumes\n", +- config_file, line, res->name); ++ res->config_file, res->start_line, res->name); + config_valid = 0; + } + } +-- +2.33.1.windows.1 + -- Gitee