Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1 | From d16de70b76919269561b4e404825f78286ea9a40 Mon Sep 17 00:00:00 2001 |
| 2 | From: Changqing Li <changqing.li@windriver.com> |
| 3 | Date: Mon, 26 Nov 2018 10:31:30 +0800 |
| 4 | Subject: [PATCH] From 0000000000000000000000000000000000000000 Mon Sep 17 |
| 5 | 00:00:00 2001 From: Benjamin Marzinski <bmarzins@redhat.com> Date: Mon, 6 Nov |
| 6 | 2017 21:39:28 -0600 Subject: [PATCH] RH: warn on invalid regex instead of |
| 7 | failing |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 8 | |
| 9 | multipath.conf used to allow "*" as a match everything regular expression, |
| 10 | instead of requiring ".*". Instead of erroring when the old style |
| 11 | regular expressions are used, it should print a warning and convert |
| 12 | them. |
| 13 | |
| 14 | Signed-off-by: Benjamin Marzinski <bmarzins@redhat.com> |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 15 | |
| 16 | Upstream-Status: Pending |
| 17 | |
| 18 | update this patch to new version |
| 19 | |
| 20 | Signed-off-by: Changqing Li <changqing.li@windriver.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 21 | --- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 22 | libmultipath/dict.c | 29 ++++++++++++++++++++++------- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 23 | libmultipath/parser.c | 13 +++++++++++++ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 24 | libmultipath/parser.h | 2 +- |
| 25 | 3 files changed, 36 insertions(+), 8 deletions(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 26 | |
| 27 | diff --git a/libmultipath/dict.c b/libmultipath/dict.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 28 | index a81c051..0689763 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 29 | --- a/libmultipath/dict.c |
| 30 | +++ b/libmultipath/dict.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 31 | @@ -59,6 +59,21 @@ set_str(vector strvec, void *ptr) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | static int |
| 35 | +set_regex(vector strvec, void *ptr) |
| 36 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 37 | + char **str_ptr = (char **)ptr; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 38 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 39 | + if (*str_ptr) |
| 40 | + FREE(*str_ptr); |
| 41 | + *str_ptr = set_regex_value(strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 42 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 43 | + if (!*str_ptr) |
| 44 | + return 1; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 45 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 46 | + return 0; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 47 | +} |
| 48 | + |
| 49 | +static int |
| 50 | set_yes_no(vector strvec, void *ptr) |
| 51 | { |
| 52 | char * buff; |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 53 | @@ -1346,8 +1361,8 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \ |
| 54 | \ |
| 55 | if (!conf->option) \ |
| 56 | return 1; \ |
| 57 | - \ |
| 58 | - buff = set_value(strvec); \ |
| 59 | + \ |
| 60 | + buff = set_regex_value(strvec); \ |
| 61 | if (!buff) \ |
| 62 | return 1; \ |
| 63 | \ |
| 64 | @@ -1363,7 +1378,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 65 | if (!conf->option) \ |
| 66 | return 1; \ |
| 67 | \ |
| 68 | - buff = set_value(strvec); \ |
| 69 | + buff = set_regex_value(strvec); \ |
| 70 | if (!buff) \ |
| 71 | return 1; \ |
| 72 | \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 73 | @@ -1466,16 +1481,16 @@ device_handler(struct config *conf, vector strvec) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 74 | return 0; |
| 75 | } |
| 76 | |
| 77 | -declare_hw_handler(vendor, set_str) |
| 78 | +declare_hw_handler(vendor, set_regex) |
| 79 | declare_hw_snprint(vendor, print_str) |
| 80 | |
| 81 | -declare_hw_handler(product, set_str) |
| 82 | +declare_hw_handler(product, set_regex) |
| 83 | declare_hw_snprint(product, print_str) |
| 84 | |
| 85 | -declare_hw_handler(revision, set_str) |
| 86 | +declare_hw_handler(revision, set_regex) |
| 87 | declare_hw_snprint(revision, print_str) |
| 88 | |
| 89 | -declare_hw_handler(bl_product, set_str) |
| 90 | +declare_hw_handler(bl_product, set_regex) |
| 91 | declare_hw_snprint(bl_product, print_str) |
| 92 | |
| 93 | declare_hw_handler(hwhandler, set_str) |
| 94 | diff --git a/libmultipath/parser.c b/libmultipath/parser.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 95 | index 92ef7cf..0e2cf49 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 96 | --- a/libmultipath/parser.c |
| 97 | +++ b/libmultipath/parser.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 98 | @@ -384,6 +384,19 @@ set_value(vector strvec) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 99 | return alloc; |
| 100 | } |
| 101 | |
| 102 | +void * |
| 103 | +set_regex_value(vector strvec) |
| 104 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 105 | + char *buff = set_value(strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 106 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 107 | + if (buff && strcmp("*", buff) == 0) { |
| 108 | + condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\""); |
| 109 | + FREE(buff); |
| 110 | + return strdup(".*"); |
| 111 | + } |
| 112 | + return buff; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 113 | +} |
| 114 | + |
| 115 | /* non-recursive configuration stream handler */ |
| 116 | static int kw_level = 0; |
| 117 | |
| 118 | diff --git a/libmultipath/parser.h b/libmultipath/parser.h |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 119 | index 62906e9..b6899fc 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 120 | --- a/libmultipath/parser.h |
| 121 | +++ b/libmultipath/parser.h |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 122 | @@ -76,7 +76,7 @@ extern int _install_keyword(vector keywords, char *string, |
| 123 | extern void dump_keywords(vector keydump, int level); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 124 | extern void free_keywords(vector keywords); |
| 125 | extern vector alloc_strvec(char *string); |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 126 | -extern void *set_value(vector strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 127 | +extern void *set_regex_value(vector strvec); |
| 128 | extern int process_file(struct config *conf, char *conf_file); |
| 129 | extern struct keyword * find_keyword(vector keywords, vector v, char * name); |
| 130 | int snprint_keyword(char *buff, int len, char *fmt, struct keyword *kw, |
| 131 | -- |
| 132 | 2.7.4 |
| 133 | |