From e2dea6ef8da3db74e87e904a1b252aca2477975a Mon Sep 17 00:00:00 2001 From: Bobbie Soedirgo Date: Mon, 22 Jan 2024 17:44:07 +0800 Subject: [PATCH] fix: disable extension constraints on macos --- Makefile | 9 ++++++--- src/constrained_extensions.c | 8 ++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b6f013b..f3b774c 100644 --- a/Makefile +++ b/Makefile @@ -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)) diff --git a/src/constrained_extensions.c b/src/constrained_extensions.c index c06c86a..f0e8730 100644 --- a/src/constrained_extensions.c +++ b/src/constrained_extensions.c @@ -13,7 +13,9 @@ #include #include +#ifdef __linux__ #include +#endif #include #include @@ -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; @@ -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), @@ -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,