Skip to content

Commit

Permalink
fix: disable sysinfo checks on macos
Browse files Browse the repository at this point in the history
  • Loading branch information
soedirgo committed Jan 22, 2024
1 parent 7334c1b commit 6c2c7ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ OBJS = src/supautils.o src/privileged_extensions.o src/constrained_extensions.o

PG_VERSION = $(strip $(shell $(PG_CONFIG) --version | $(GREP) -oP '(?<=PostgreSQL )[0-9]+'))
PG_GE13 = $(shell test $(PG_VERSION) -ge 13; echo $$?)
SYSTEM = $(shell uname -s)

ifeq ($(PG_GE13),0)
TESTS = $(wildcard test/sql/*.sql)
else
ifneq ($(SYSTEM), Linux)
TESTS = $(filter-out test/sql/ge13_%.sql, $(wildcard test/sql/*.sql))
else ifneq ($(PG_GE13), 0)
TESTS = $(filter-out test/sql/ge13_%.sql, $(wildcard test/sql/*.sql))
else
TESTS = $(wildcard test/sql/*.sql)
endif

REGRESS = $(patsubst test/sql/%.sql,%,$(TESTS))
Expand Down
8 changes: 8 additions & 0 deletions src/constrained_extensions.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
#include <utils/builtins.h>
#include <utils/memutils.h>

#ifdef __linux__
#include <sys/sysinfo.h>
#endif
#include <sys/statvfs.h>
#include <errno.h>

Expand Down Expand Up @@ -192,13 +194,17 @@ void constrain_extension(
constrained_extension *cexts,
const size_t total_cexts
){
#ifdef __linux__
struct sysinfo info = {};
#endif
struct statvfs fsdata = {};

#ifdef __linux__
if(sysinfo(&info) < 0){
int save_errno = errno;
ereport(ERROR, errmsg("sysinfo call failed: %s", strerror(save_errno)));
}
#endif

if (statvfs(DataDir, &fsdata) < 0){
int save_errno = errno;
Expand All @@ -207,6 +213,7 @@ void constrain_extension(

for(size_t i = 0; i < total_cexts; i++){
if (strcmp(name, cexts[i].name) == 0) {
#ifdef __linux__
if(cexts[i].cpu != 0 && cexts[i].cpu > get_nprocs())
ereport(ERROR,
errdetail("required CPUs: %zu", cexts[i].cpu),
Expand All @@ -221,6 +228,7 @@ void constrain_extension(
errmsg("not enough memory for using this extension")
);
}
#endif
if(cexts[i].disk != 0 && cexts[i].disk > fsdata.f_bfree * fsdata.f_bsize){
char *pretty_size = text_to_cstring(DatumGetTextPP(DirectFunctionCall1(pg_size_pretty, Int64GetDatum(cexts[i].disk))));
ereport(ERROR,
Expand Down

0 comments on commit 6c2c7ef

Please sign in to comment.