From 0503a4a59fafd255169037bda19d3d9a04ea4d79 Mon Sep 17 00:00:00 2001 From: Sviatoslav Ermilin Date: Thu, 2 Dec 2021 13:25:46 +0500 Subject: [PATCH] fix of errors excluding --- constants.h | 2 +- logerrors.c | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/constants.h b/constants.h index 386d1c1..43f9547 100644 --- a/constants.h +++ b/constants.h @@ -5,7 +5,7 @@ const char error_names[error_codes_count][error_name_max_length] = {"NOT_KNOWN_ #define not_known_error_code 3 // Error codes in same order const int error_codes[error_codes_count] = {not_known_error_code, 0, 64, 318767168, 134217792, 50331712, 117440576, 100663360, 67108928, 16908352, 128, 16777344, 192, 512, 50332160, 100663808, 16777728, 67109376, 117441024, 16908800, 576, 1088, 1152, 1408, 16778624, 1792, 16910080, 2048, 2688, 33557120, 2, 66, 130, 352845954, 17301634, 134217858, 33816706, 83886210, 301990018, 34078850, 84148354, 352583810, 67371138, 100925570, 369361026, 386138242, 134480002, 117440642, 151257218, 335544450, 84410498, 100794498, 262274, 50856066, 302252162, 654573698, 671350914, 403177602, 386400386, 150995074, 318767234, 385876098, 67108994, 33554562, 50331778, 402653314, 101187714, 16777346, 17039490, 117964930, 67633282, 369098882, 16908418, 33685634, 50462850, 67240066, 84017282, 469762178, 486539394, 503316610, 587202690, 603979906, 16777410, 33575106, 50352322, 83906754, 67391682, 16908482, 258, 322, 16777538, 33554754, 134218050, 50331970, 67109186, 83886402, 100663618, 117440834, 16908610, 33685826, 50463042, 386, 450, 514, 16908802, 1154, 16909442, 1282, 1410, 83887490, 33555842, 50333058, 67110274, 259, 515, 16777731, 33554947, 50332163, 67109379, 579, 16777795, 67109443, 16908867, 33686083, 50463299, 1155, 16778371, 1283, 1411, 4, 33554436, 16777220, 50331652, 16908292, 132, 16801924, 16797828, 101744772, 50364548, 655492, 151388292, 819332, 33579140, 34103428, 151818372, 67141764, 134611076, 17432708, 34209924, 151027844, 156008580, 50360452, 52461700, 16908420, 33685636, 67137668, 16806020, 50462852, 67240068, 50884740, 84017284, 100794500, 117571716, 33845380, 290948, 33583236, 84439172, 134348932, 151126148, 393348, 17064068, 17170564, 33947780, 50724996, 67502212, 84279428, 101056644, 117833860, 260, 197, 4293, 8389, 12485, 16581, 261, 16777477, 17039621, 50856197, 325, 100663621, 33685829, 50463045, 453, 67371461, 16908741, 33685957, 50463173, 67240389, 517, 786949, 16908805, 33686021, 135, 22, 16777238, 2456, 83888536, 33556888, 264600, 17303960, 67635608, 117442968, 134220184, 67111320, 100665752, 19138968, 301992344, 318769560, 335546776, 2361752, 285215128, 150997400, 67373464, 16779672, 536873368, 436210072, 452987288, 553650584, 570427800, 469764504, 486541720, 503318936, 32, 16777248, 33554464, 50331680, 67108896, 2600, 16779816, 33557032, 16847075, 33624291, 50401507, 67178723, 83955939, 16851171, 33628387, 50405603, 67182819, 83960035, 100737251, 117514467, 16888035, 33665251, 50442467, 16896227, 33673443, 50450659, 67227875, 84005091, 16859363, 33636579, 16941283, 33718499}; -#define max_length_of_error_code 9 +#define len_sqlstate_str 5 const int excluded_errcodes[] = {ERRCODE_CRASH_SHUTDOWN}; #define message_types_count 3 diff --git a/logerrors.c b/logerrors.c index 3f415cb..479358b 100644 --- a/logerrors.c +++ b/logerrors.c @@ -122,11 +122,10 @@ void logerrors_main(Datum) pg_attribute_noreturn(); static void global_variables_init() { - long errcode; - char* end; + int sqlstate; int errcodes_count; char* excluded_errcode_str; - char excluded_errcodes_copy[error_codes_count * (max_length_of_error_code + 1)]; + char excluded_errcodes_copy[error_codes_count * (len_sqlstate_str + 1)]; global_variables->intervals_count = intervals_count; /* +5 because we don't want take lock on MessagesBuffer while pg_log_errors_stats is running */ global_variables->actual_intervals_count = intervals_count + 5; @@ -141,24 +140,27 @@ global_variables_init() if (excluded_errcodes_str == NULL) return; memset(&excluded_errcodes_copy, '\0', sizeof(excluded_errcodes_copy)); - strlcpy(&excluded_errcodes_copy[0], excluded_errcodes_str, error_codes_count * max_length_of_error_code - 1); + strlcpy(&excluded_errcodes_copy[0], excluded_errcodes_str, error_codes_count * (len_sqlstate_str + 1) - 1); excluded_errcode_str = strtok(excluded_errcodes_copy, ","); while (excluded_errcode_str != NULL) { - errno = 0; - errcode = strtol(excluded_errcode_str, &end, 10); - /* Ignore incorrect codes */ - if (errno != 0) { - excluded_errcode_str = strtok(NULL, " "); - elog(ERROR, "Invalid value of logerrors.excluded_errcodes"); - break; + if (strlen(excluded_errcode_str) != len_sqlstate_str) { + elog(WARNING, "logerrors: errcode length should be equal to %d", len_sqlstate_str); + excluded_errcode_str = strtok(NULL, ","); + continue; } - global_variables->excluded_errcodes[global_variables->excluded_errcodes_count] = errcode; + sqlstate = MAKE_SQLSTATE(excluded_errcode_str[0], + excluded_errcode_str[1], + excluded_errcode_str[2], + excluded_errcode_str[3], + excluded_errcode_str[4]); + + global_variables->excluded_errcodes[global_variables->excluded_errcodes_count] = sqlstate; global_variables->excluded_errcodes_count += 1; if (global_variables->excluded_errcodes_count == error_codes_count - 1) break; - excluded_errcode_str = strtok(NULL, " "); + excluded_errcode_str = strtok(NULL, ","); } }