Skip to content

Commit

Permalink
Merge pull request #11 from keithf4/pg15
Browse files Browse the repository at this point in the history
Make compatible with PG15
  • Loading branch information
keithf4 authored Oct 20, 2022
2 parents 4925f11 + c74db1f commit fb67d6a
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
15 changes: 13 additions & 2 deletions cgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
#include <sys/vfs.h>
#include <unistd.h>

#if PG_VERSION_NUM < 150000
#include "utils/int8.h"
#endif
#if PG_VERSION_NUM >= 110000
#include "catalog/pg_type_d.h"
#else
Expand All @@ -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"
Expand Down Expand Up @@ -150,8 +151,18 @@ cgmembers(int64 **pids)
{
bool success = false;
int64 result;
#if PG_VERSION_NUM >= 150000
char *endptr = NULL;
#endif

#if PG_VERSION_NUM < 150000
success = scanint8(lines[i], true, &result);
#else
errno = 0;
result = strtoi64(lines[i], &endptr, 10);
if (errno == 0 && *endptr == '\0')
success = true;
#endif
if (!success)
ereport(ERROR,
(errcode_for_file_access(),
Expand Down
14 changes: 13 additions & 1 deletion parseutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@

#include <float.h>

#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"
Expand Down Expand Up @@ -552,6 +554,9 @@ get_int64_from_file(char *ftr)
char *rawstr;
bool success = false;
int64 result;
#if PG_VERSION_NUM >= 150000
char *endptr = NULL;
#endif

rawstr = read_one_nlsv(ftr);

Expand All @@ -560,7 +565,14 @@ get_int64_from_file(char *ftr)
result = PG_INT64_MAX;
else
{
#if PG_VERSION_NUM < 150000
success = scanint8(rawstr, true, &result);
#else
errno = 0;
result = strtoi64(rawstr, &endptr, 10);
if (errno == 0 && *endptr == '\0')
success = true;
#endif
if (!success)
ereport(ERROR,
(errcode_for_file_access(),
Expand Down
1 change: 1 addition & 0 deletions pgnodemx--1.3--1.4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- No SQL code changes. This file is provided to allow extension update path to version 1.4.
File renamed without changes.
14 changes: 13 additions & 1 deletion pgnodemx.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
#endif
#include <unistd.h>

#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"
Expand All @@ -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"
Expand Down Expand Up @@ -596,11 +598,21 @@ 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 = NULL;
#endif

/* Limit use to members of special role */
pgnodemx_check_role();

#if PG_VERSION_NUM < 150000
success = scanint8(value, true, &result);
#else
errno = 0;
result = strtoi64(value, &endptr, 10);
if (errno == 0 && *endptr == '\0')
success = true;
#endif
if (!success)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
Expand Down
2 changes: 1 addition & 1 deletion pgnodemx.control
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit fb67d6a

Please sign in to comment.