From 4678e84977ce0c5048f1a9b77c152bca2b5ccade Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Fri, 7 Oct 2022 16:26:51 -0400 Subject: [PATCH 01/10] Make compatible with PG15 --- cgroup.c | 18 ++++++++++++++++-- parseutils.c | 17 ++++++++++++++++- pgnodemx.c | 17 ++++++++++++++++- 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/cgroup.c b/cgroup.c index a745dc2..f98dd0d 100644 --- a/cgroup.c +++ b/cgroup.c @@ -38,6 +38,9 @@ #include #include +#if PG_VERSION_NUM < 150000 +#include "utils/int8.h" +#endif #if PG_VERSION_NUM >= 110000 #include "catalog/pg_type_d.h" #else @@ -52,12 +55,10 @@ #include "lib/stringinfo.h" #include "utils/builtins.h" #include "utils/guc_tables.h" -#include "utils/int8.h" #include "utils/memutils.h" #if PG_VERSION_NUM >= 100000 #include "utils/varlena.h" #endif - #include "fileutils.h" #include "genutils.h" #include "parseutils.h" @@ -150,8 +151,21 @@ cgmembers(int64 **pids) { bool success = false; int64 result; + #if PG_VERSION_NUM >= 150000 + char *endptr; + #endif + #if PG_VERSION_NUM < 150000 success = scanint8(lines[i], true, &result); + #endif + #if PG_VERSION_NUM >= 150000 + errno = 0; + result = strtoi64(lines[i], &endptr, 10); + if (errno == 0) + { + success = true; + } + #endif if (!success) ereport(ERROR, (errcode_for_file_access(), diff --git a/parseutils.c b/parseutils.c index 2de134b..94709a9 100644 --- a/parseutils.c +++ b/parseutils.c @@ -32,12 +32,14 @@ #include +#if PG_VERSION_NUM < 150000 +#include "utils/int8.h" +#endif #if PG_VERSION_NUM >= 120000 #include "utils/float.h" #else #include "utils/builtins.h" #endif -#include "utils/int8.h" #include "mb/pg_wchar.h" #include "fileutils.h" #include "kdapi.h" @@ -552,6 +554,9 @@ get_int64_from_file(char *ftr) char *rawstr; bool success = false; int64 result; + #if PG_VERSION_NUM >= 150000 + char *endptr; + #endif rawstr = read_one_nlsv(ftr); @@ -560,7 +565,17 @@ get_int64_from_file(char *ftr) result = PG_INT64_MAX; else { + #if PG_VERSION_NUM < 150000 success = scanint8(rawstr, true, &result); + #endif + #if PG_VERSION_NUM >= 150000 + errno = 0; + result = strtoi64(rawstr, &endptr, 10); + if (errno == 0) + { + success = true; + } + #endif if (!success) ereport(ERROR, (errcode_for_file_access(), diff --git a/pgnodemx.c b/pgnodemx.c index c883dc4..e4c0f1d 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -39,6 +39,9 @@ #endif #include +#if PG_VERSION_NUM < 150000 +#include "utils/int8.h" +#endif #include "catalog/pg_authid.h" #if PG_VERSION_NUM >= 110000 #include "catalog/pg_type_d.h" @@ -50,7 +53,6 @@ #include "utils/acl.h" #include "utils/builtins.h" #include "utils/guc_tables.h" -#include "utils/int8.h" #include "cgroup.h" #include "envutils.h" @@ -596,11 +598,24 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) int64 result; char *varname = text_to_cstring(PG_GETARG_TEXT_PP(0)); char *value = get_string_from_env(varname); + #if PG_VERSION_NUM >= 150000 + char *endptr; + #endif /* Limit use to members of special role */ pgnodemx_check_role(); + #if PG_VERSION_NUM < 150000 success = scanint8(value, true, &result); + #endif + #if PG_VERSION_NUM >= 150000 + errno = 0; + result = strtoi64(value, &endptr, 10); + if (errno == 0) + { + success = true; + } + #endif if (!success) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), From 4a4da8496c39a8f6097b2565857e2b5e1672d60c Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Fri, 7 Oct 2022 16:48:09 -0400 Subject: [PATCH 02/10] Convert spaces to tabs for consistency --- cgroup.c | 26 +++++++++++++------------- parseutils.c | 18 +++++++++--------- pgnodemx.c | 18 +++++++++--------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/cgroup.c b/cgroup.c index f98dd0d..4ffd86a 100644 --- a/cgroup.c +++ b/cgroup.c @@ -151,21 +151,21 @@ cgmembers(int64 **pids) { bool success = false; int64 result; - #if PG_VERSION_NUM >= 150000 - char *endptr; - #endif + #if PG_VERSION_NUM >= 150000 + char *endptr; + #endif - #if PG_VERSION_NUM < 150000 + #if PG_VERSION_NUM < 150000 success = scanint8(lines[i], true, &result); - #endif - #if PG_VERSION_NUM >= 150000 - errno = 0; - result = strtoi64(lines[i], &endptr, 10); - if (errno == 0) - { - success = true; - } - #endif + #endif + #if PG_VERSION_NUM >= 150000 + errno = 0; + result = strtoi64(lines[i], &endptr, 10); + if (errno == 0) + { + success = true; + } + #endif if (!success) ereport(ERROR, (errcode_for_file_access(), diff --git a/parseutils.c b/parseutils.c index 94709a9..2707cf4 100644 --- a/parseutils.c +++ b/parseutils.c @@ -567,15 +567,15 @@ get_int64_from_file(char *ftr) { #if PG_VERSION_NUM < 150000 success = scanint8(rawstr, true, &result); - #endif - #if PG_VERSION_NUM >= 150000 - errno = 0; - result = strtoi64(rawstr, &endptr, 10); - if (errno == 0) - { - success = true; - } - #endif + #endif + #if PG_VERSION_NUM >= 150000 + errno = 0; + result = strtoi64(rawstr, &endptr, 10); + if (errno == 0) + { + success = true; + } + #endif if (!success) ereport(ERROR, (errcode_for_file_access(), diff --git a/pgnodemx.c b/pgnodemx.c index e4c0f1d..7a7f95f 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -607,15 +607,15 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) #if PG_VERSION_NUM < 150000 success = scanint8(value, true, &result); - #endif - #if PG_VERSION_NUM >= 150000 - errno = 0; - result = strtoi64(value, &endptr, 10); - if (errno == 0) - { - success = true; - } - #endif + #endif + #if PG_VERSION_NUM >= 150000 + errno = 0; + result = strtoi64(value, &endptr, 10); + if (errno == 0) + { + success = true; + } + #endif if (!success) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), From 182d0cf468a9505f1ed01da11b500e3a6a8acc03 Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Fri, 7 Oct 2022 16:50:02 -0400 Subject: [PATCH 03/10] Convert spaces to tabs for consistency --- parseutils.c | 6 +++--- pgnodemx.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/parseutils.c b/parseutils.c index 2707cf4..18b6e8b 100644 --- a/parseutils.c +++ b/parseutils.c @@ -554,9 +554,9 @@ get_int64_from_file(char *ftr) char *rawstr; bool success = false; int64 result; - #if PG_VERSION_NUM >= 150000 - char *endptr; - #endif + #if PG_VERSION_NUM >= 150000 + char *endptr; + #endif rawstr = read_one_nlsv(ftr); diff --git a/pgnodemx.c b/pgnodemx.c index 7a7f95f..3400ea1 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -598,9 +598,9 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) int64 result; char *varname = text_to_cstring(PG_GETARG_TEXT_PP(0)); char *value = get_string_from_env(varname); - #if PG_VERSION_NUM >= 150000 - char *endptr; - #endif + #if PG_VERSION_NUM >= 150000 + char *endptr; + #endif /* Limit use to members of special role */ pgnodemx_check_role(); From 58a8e446054622e1073e602786a3f429fcef2405 Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Fri, 7 Oct 2022 16:51:11 -0400 Subject: [PATCH 04/10] Convert spaces to tabs for consistency --- pgnodemx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pgnodemx.c b/pgnodemx.c index 3400ea1..83b2685 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -605,7 +605,7 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) /* Limit use to members of special role */ pgnodemx_check_role(); - #if PG_VERSION_NUM < 150000 + #if PG_VERSION_NUM < 150000 success = scanint8(value, true, &result); #endif #if PG_VERSION_NUM >= 150000 From e333d10f45eb36f0532dec8b58443a7956fe362a Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Tue, 11 Oct 2022 15:28:30 -0400 Subject: [PATCH 05/10] Simplify if/else statements. Make indent consistent. Add extension update files. --- cgroup.c | 11 +++++------ parseutils.c | 7 +++---- pgnodemx--1.3--1.4.sql | 1 + pgnodemx--1.3.sql => pgnodemx--1.4.sql | 0 pgnodemx.c | 11 +++++------ pgnodemx.control | 2 +- 6 files changed, 15 insertions(+), 17 deletions(-) create mode 100644 pgnodemx--1.3--1.4.sql rename pgnodemx--1.3.sql => pgnodemx--1.4.sql (100%) diff --git a/cgroup.c b/cgroup.c index 4ffd86a..79bf74c 100644 --- a/cgroup.c +++ b/cgroup.c @@ -151,21 +151,20 @@ cgmembers(int64 **pids) { bool success = false; int64 result; - #if PG_VERSION_NUM >= 150000 +#if PG_VERSION_NUM >= 150000 char *endptr; - #endif +#endif - #if PG_VERSION_NUM < 150000 +#if PG_VERSION_NUM < 150000 success = scanint8(lines[i], true, &result); - #endif - #if PG_VERSION_NUM >= 150000 +#else errno = 0; result = strtoi64(lines[i], &endptr, 10); if (errno == 0) { success = true; } - #endif +#endif if (!success) ereport(ERROR, (errcode_for_file_access(), diff --git a/parseutils.c b/parseutils.c index 18b6e8b..e250608 100644 --- a/parseutils.c +++ b/parseutils.c @@ -565,17 +565,16 @@ get_int64_from_file(char *ftr) result = PG_INT64_MAX; else { - #if PG_VERSION_NUM < 150000 +#if PG_VERSION_NUM < 150000 success = scanint8(rawstr, true, &result); - #endif - #if PG_VERSION_NUM >= 150000 +#else errno = 0; result = strtoi64(rawstr, &endptr, 10); if (errno == 0) { success = true; } - #endif +#endif if (!success) ereport(ERROR, (errcode_for_file_access(), diff --git a/pgnodemx--1.3--1.4.sql b/pgnodemx--1.3--1.4.sql new file mode 100644 index 0000000..6cc673a --- /dev/null +++ b/pgnodemx--1.3--1.4.sql @@ -0,0 +1 @@ +-- No SQL code changes. This file is provided to allow extension update path to version 1.4. diff --git a/pgnodemx--1.3.sql b/pgnodemx--1.4.sql similarity index 100% rename from pgnodemx--1.3.sql rename to pgnodemx--1.4.sql diff --git a/pgnodemx.c b/pgnodemx.c index 83b2685..85cda93 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -598,24 +598,23 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) int64 result; char *varname = text_to_cstring(PG_GETARG_TEXT_PP(0)); char *value = get_string_from_env(varname); - #if PG_VERSION_NUM >= 150000 +#if PG_VERSION_NUM >= 150000 char *endptr; - #endif +#endif /* Limit use to members of special role */ pgnodemx_check_role(); - #if PG_VERSION_NUM < 150000 +#if PG_VERSION_NUM < 150000 success = scanint8(value, true, &result); - #endif - #if PG_VERSION_NUM >= 150000 +#else errno = 0; result = strtoi64(value, &endptr, 10); if (errno == 0) { success = true; } - #endif +#endif if (!success) ereport(ERROR, (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE), diff --git a/pgnodemx.control b/pgnodemx.control index 0b12efc..11791c3 100644 --- a/pgnodemx.control +++ b/pgnodemx.control @@ -1,5 +1,5 @@ # pgnodemx extension comment = 'SQL functions that allow capture of node OS metrics from PostgreSQL' -default_version = '1.3' +default_version = '1.4' module_pathname = '$libdir/pgnodemx' relocatable = true From daf93d050d514ecdded919cc3baab6a53de7d63d Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Tue, 11 Oct 2022 15:30:21 -0400 Subject: [PATCH 06/10] Update preprocessor indent --- parseutils.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/parseutils.c b/parseutils.c index e250608..138b32c 100644 --- a/parseutils.c +++ b/parseutils.c @@ -554,9 +554,9 @@ get_int64_from_file(char *ftr) char *rawstr; bool success = false; int64 result; - #if PG_VERSION_NUM >= 150000 +#if PG_VERSION_NUM >= 150000 char *endptr; - #endif +#endif rawstr = read_one_nlsv(ftr); From 063bc9cd75da473e5d666d6fa2db8d37e65fe60b Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Tue, 11 Oct 2022 15:57:04 -0400 Subject: [PATCH 07/10] Add more thorough check for error condition --- cgroup.c | 2 +- parseutils.c | 2 +- pgnodemx.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cgroup.c b/cgroup.c index 79bf74c..6aa7f70 100644 --- a/cgroup.c +++ b/cgroup.c @@ -160,7 +160,7 @@ cgmembers(int64 **pids) #else errno = 0; result = strtoi64(lines[i], &endptr, 10); - if (errno == 0) + if (errno == 0 && *endptr == '\0') { success = true; } diff --git a/parseutils.c b/parseutils.c index 138b32c..ed5f87f 100644 --- a/parseutils.c +++ b/parseutils.c @@ -570,7 +570,7 @@ get_int64_from_file(char *ftr) #else errno = 0; result = strtoi64(rawstr, &endptr, 10); - if (errno == 0) + if (errno == 0 && *endptr == '\0') { success = true; } diff --git a/pgnodemx.c b/pgnodemx.c index 85cda93..50e1805 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -610,7 +610,7 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) #else errno = 0; result = strtoi64(value, &endptr, 10); - if (errno == 0) + if (errno == 0 && *endptr == '\0') { success = true; } From efcfc1fe31309d99e151218cb0324b49be7203c0 Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Tue, 11 Oct 2022 16:10:50 -0400 Subject: [PATCH 08/10] Use consistent one line if statement format --- cgroup.c | 2 -- parseutils.c | 2 -- pgnodemx.c | 2 -- 3 files changed, 6 deletions(-) diff --git a/cgroup.c b/cgroup.c index 6aa7f70..61f4d87 100644 --- a/cgroup.c +++ b/cgroup.c @@ -161,9 +161,7 @@ cgmembers(int64 **pids) errno = 0; result = strtoi64(lines[i], &endptr, 10); if (errno == 0 && *endptr == '\0') - { success = true; - } #endif if (!success) ereport(ERROR, diff --git a/parseutils.c b/parseutils.c index ed5f87f..89bec92 100644 --- a/parseutils.c +++ b/parseutils.c @@ -571,9 +571,7 @@ get_int64_from_file(char *ftr) errno = 0; result = strtoi64(rawstr, &endptr, 10); if (errno == 0 && *endptr == '\0') - { success = true; - } #endif if (!success) ereport(ERROR, diff --git a/pgnodemx.c b/pgnodemx.c index 50e1805..9fccc59 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -611,9 +611,7 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) errno = 0; result = strtoi64(value, &endptr, 10); if (errno == 0 && *endptr == '\0') - { success = true; - } #endif if (!success) ereport(ERROR, From 57b40ffe2e5c74044b29828ef40afe7c13bdecea Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Wed, 12 Oct 2022 11:34:49 -0400 Subject: [PATCH 09/10] initialize endptr --- cgroup.c | 2 +- parseutils.c | 2 +- pgnodemx.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cgroup.c b/cgroup.c index 61f4d87..ef09451 100644 --- a/cgroup.c +++ b/cgroup.c @@ -152,7 +152,7 @@ cgmembers(int64 **pids) bool success = false; int64 result; #if PG_VERSION_NUM >= 150000 - char *endptr; + char *endptr = NULL; #endif #if PG_VERSION_NUM < 150000 diff --git a/parseutils.c b/parseutils.c index 89bec92..f327f1a 100644 --- a/parseutils.c +++ b/parseutils.c @@ -555,7 +555,7 @@ get_int64_from_file(char *ftr) bool success = false; int64 result; #if PG_VERSION_NUM >= 150000 - char *endptr; + char *endptr = NULL; #endif rawstr = read_one_nlsv(ftr); diff --git a/pgnodemx.c b/pgnodemx.c index 9fccc59..fe09c36 100644 --- a/pgnodemx.c +++ b/pgnodemx.c @@ -599,7 +599,7 @@ pgnodemx_envvar_bigint(PG_FUNCTION_ARGS) char *varname = text_to_cstring(PG_GETARG_TEXT_PP(0)); char *value = get_string_from_env(varname); #if PG_VERSION_NUM >= 150000 - char *endptr; + char *endptr = NULL; #endif /* Limit use to members of special role */ From c74db1f054bc92c9408285d29a4692a37199a4dd Mon Sep 17 00:00:00 2001 From: Keith Fiske Date: Wed, 12 Oct 2022 11:39:25 -0400 Subject: [PATCH 10/10] update makefile for 1.4 --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ad70b74..42c217b 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ EXTENSION = pgnodemx pg_proctab--0.0.10-compat else EXTENSION = pgnodemx pg_proctab--0.0.10-compat pg_proctab endif -DATA = pgnodemx--1.0--1.1.sql pgnodemx--1.1--1.2.sql pgnodemx--1.2--1.3.sql pgnodemx--1.3.sql pg_proctab--0.0.10-compat.sql +DATA = pgnodemx--1.0--1.1.sql pgnodemx--1.1--1.2.sql pgnodemx--1.2--1.3.sql pgnodemx--1.3--1.4.sql pgnodemx--1.4.sql pg_proctab--0.0.10-compat.sql GHASH := $(shell git rev-parse --short HEAD)