Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 1 | From 56d65ecb1c6d814929f6ff3159ade09dc203cc83 Mon Sep 17 00:00:00 2001 |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 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 | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 21 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 22 | --- |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 23 | libmultipath/dict.c | 29 ++++++++++++++++++++++------- |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 24 | libmultipath/parser.c | 13 +++++++++++++ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 25 | libmultipath/parser.h | 1 + |
| 26 | 3 files changed, 36 insertions(+), 7 deletions(-) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 27 | |
| 28 | diff --git a/libmultipath/dict.c b/libmultipath/dict.c |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 29 | index eaad4f1..fb30577 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 30 | --- a/libmultipath/dict.c |
| 31 | +++ b/libmultipath/dict.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 32 | @@ -59,6 +59,21 @@ set_str(vector strvec, void *ptr) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static int |
| 36 | +set_regex(vector strvec, void *ptr) |
| 37 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 38 | + char **str_ptr = (char **)ptr; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 39 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 40 | + if (*str_ptr) |
| 41 | + FREE(*str_ptr); |
| 42 | + *str_ptr = set_regex_value(strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 43 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 44 | + if (!*str_ptr) |
| 45 | + return 1; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 46 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 47 | + return 0; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 48 | +} |
| 49 | + |
| 50 | +static int |
| 51 | set_yes_no(vector strvec, void *ptr) |
| 52 | { |
| 53 | char * buff; |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 54 | @@ -1373,8 +1388,8 @@ ble_ ## option ## _handler (struct config *conf, vector strvec) \ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 55 | \ |
| 56 | if (!conf->option) \ |
| 57 | return 1; \ |
| 58 | - \ |
| 59 | - buff = set_value(strvec); \ |
| 60 | + \ |
| 61 | + buff = set_regex_value(strvec); \ |
| 62 | if (!buff) \ |
| 63 | return 1; \ |
| 64 | \ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 65 | @@ -1390,7 +1405,7 @@ ble_ ## option ## _ ## name ## _handler (struct config *conf, vector strvec) \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 66 | if (!conf->option) \ |
| 67 | return 1; \ |
| 68 | \ |
| 69 | - buff = set_value(strvec); \ |
| 70 | + buff = set_regex_value(strvec); \ |
| 71 | if (!buff) \ |
| 72 | return 1; \ |
| 73 | \ |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 74 | @@ -1493,16 +1508,16 @@ device_handler(struct config *conf, vector strvec) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 75 | return 0; |
| 76 | } |
| 77 | |
| 78 | -declare_hw_handler(vendor, set_str) |
| 79 | +declare_hw_handler(vendor, set_regex) |
| 80 | declare_hw_snprint(vendor, print_str) |
| 81 | |
| 82 | -declare_hw_handler(product, set_str) |
| 83 | +declare_hw_handler(product, set_regex) |
| 84 | declare_hw_snprint(product, print_str) |
| 85 | |
| 86 | -declare_hw_handler(revision, set_str) |
| 87 | +declare_hw_handler(revision, set_regex) |
| 88 | declare_hw_snprint(revision, print_str) |
| 89 | |
| 90 | -declare_hw_handler(bl_product, set_str) |
| 91 | +declare_hw_handler(bl_product, set_regex) |
| 92 | declare_hw_snprint(bl_product, print_str) |
| 93 | |
| 94 | declare_hw_handler(hwhandler, set_str) |
| 95 | diff --git a/libmultipath/parser.c b/libmultipath/parser.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 96 | index 92ef7cf..0e2cf49 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 97 | --- a/libmultipath/parser.c |
| 98 | +++ b/libmultipath/parser.c |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 99 | @@ -384,6 +384,19 @@ set_value(vector strvec) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 100 | return alloc; |
| 101 | } |
| 102 | |
| 103 | +void * |
| 104 | +set_regex_value(vector strvec) |
| 105 | +{ |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 106 | + char *buff = set_value(strvec); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 107 | + |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 108 | + if (buff && strcmp("*", buff) == 0) { |
| 109 | + condlog(0, "Invalid regular expression \"*\" in multipath.conf. Using \".*\""); |
| 110 | + FREE(buff); |
| 111 | + return strdup(".*"); |
| 112 | + } |
| 113 | + return buff; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 114 | +} |
| 115 | + |
| 116 | /* non-recursive configuration stream handler */ |
| 117 | static int kw_level = 0; |
| 118 | |
| 119 | diff --git a/libmultipath/parser.h b/libmultipath/parser.h |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 120 | index 62906e9..b791705 100644 |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 121 | --- a/libmultipath/parser.h |
| 122 | +++ b/libmultipath/parser.h |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame^] | 123 | @@ -77,6 +77,7 @@ 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 | c342db3 | 2019-05-15 21:57:59 -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, |