diff options
author | Bruce Momjian <bruce@momjian.us> | 1999-06-05 19:09:48 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1999-06-05 19:09:48 +0000 |
commit | 27b8143944dc0585597bdaa3ae5e5b49a4760def (patch) | |
tree | fb576673bee591564b1dedd300cd0732e341388c /contrib/miscutil | |
parent | 977108e8d9ae68cac5ec6f2908e03bd7b46fdbc7 (diff) | |
download | postgresql-27b8143944dc0585597bdaa3ae5e5b49a4760def.tar.gz |
Hi,
I have updated my contrib code for version 6.5. In the attachment you will
find the directories array, datetime, miscutil, string, tools and userlocks
which replace the corresponding directories under contrib.
In contrib/tools you will find some developement scripts which I use while
hacking the sources. I hope they will be useful for some other people.
I have also added a contrib/Makefile which tries to compile and install all
the contribs. Unfortunately many of them don't have a Makefile or don't
compile cleanly.
--
Massimo Dal Zotto
Diffstat (limited to 'contrib/miscutil')
-rw-r--r-- | contrib/miscutil/Makefile | 8 | ||||
-rw-r--r-- | contrib/miscutil/misc_utils.c | 83 | ||||
-rw-r--r-- | contrib/miscutil/misc_utils.h | 10 | ||||
-rw-r--r-- | contrib/miscutil/misc_utils.sql.in | 14 |
4 files changed, 96 insertions, 19 deletions
diff --git a/contrib/miscutil/Makefile b/contrib/miscutil/Makefile index ecb855e560..88372da0f7 100644 --- a/contrib/miscutil/Makefile +++ b/contrib/miscutil/Makefile @@ -20,6 +20,8 @@ CFLAGS += $(INCLUDE_OPT) $(CFLAGS_SL) MODNAME = misc_utils +SQLDEFS = $(MODNAME).sql + MODULE = $(MODNAME)$(DLSUFFIX) MODDIR = $(LIBDIR)/modules @@ -30,12 +32,12 @@ all: module sql module: $(MODULE) -sql: $(MODNAME).sql +sql: $(SQLDEFS) -install: $(MODULE) $(MODDIR) $(SQLDIR) +install: $(MODULE) $(SQLDEFS) $(MODDIR) $(SQLDIR) cp -p $(MODULE) $(MODDIR)/ strip $(MODDIR)/$(MODULE) - cp -p $(MODNAME).sql $(SQLDIR)/ + cp -p $(SQLDEFS) $(SQLDIR)/ $(MODDIR): mkdir -p $@ diff --git a/contrib/miscutil/misc_utils.c b/contrib/miscutil/misc_utils.c index 24d069f71c..7518443971 100644 --- a/contrib/miscutil/misc_utils.c +++ b/contrib/miscutil/misc_utils.c @@ -10,12 +10,27 @@ */ #include <unistd.h> +#include <signal.h> +#include <string.h> +#include <errno.h> #include "postgres.h" +#include "access/heapam.h" +#include "access/htup.h" +#include "access/relscan.h" +#include "access/skey.h" +#include "access/tupdesc.h" +#include "catalog/catname.h" +#include "catalog/pg_listener.h" +#include "storage/lmgr.h" +#include "utils/fmgr.h" #include "utils/palloc.h" +#include "utils/rel.h" +#include "utils/tqual.h" #include "misc_utils.h" -#include "assert_test.h" + +#define MIN(x,y) ((x)<=(y) ? (x) : (y)) extern int ExecutorLimit(int limit); extern void Async_Unlisten(char *relname, int pid); @@ -23,7 +38,6 @@ extern int assertTest(int val); #ifdef ASSERT_CHECKING_TEST extern int assertEnable(int val); - #endif int @@ -57,6 +71,62 @@ min(int x, int y) return ((x < y) ? x : y); } +/* + * Return the number of active listeners on a relation name. + */ +int +active_listeners(text *relname) +{ + HeapTuple lTuple; + Relation lRel; + HeapScanDesc sRel; + TupleDesc tdesc; + ScanKeyData key; + Datum d; + bool isnull; + int len, pid; + int count = 0; + int ourpid = getpid(); + char listen_name[NAMEDATALEN]; + + lRel = heap_openr(ListenerRelationName); + tdesc = RelationGetDescr(lRel); + LockRelation(lRel, AccessShareLock); + + if (relname && (VARSIZE(relname) > VARHDRSZ)) { + len = MIN(VARSIZE(relname)-VARHDRSZ, NAMEDATALEN-1); + strncpy(listen_name, VARDATA(relname), len); + listen_name[len] = '\0'; + ScanKeyEntryInitialize(&key, 0, + Anum_pg_listener_relname, + F_NAMEEQ, + PointerGetDatum(listen_name)); + sRel = heap_beginscan(lRel, 0, SnapshotNow, 1, &key); + } else { + sRel = heap_beginscan(lRel, 0, SnapshotNow, 0, (ScanKey)NULL); + } + + while (HeapTupleIsValid(lTuple = heap_getnext(sRel, 0))) + { + d = heap_getattr(lTuple, Anum_pg_listener_pid, tdesc, &isnull); + pid = DatumGetInt32(d); +#ifdef HAVE_KILL + if ((pid == ourpid) || (kill(pid, SIGTSTP) == 0)) { + /* elog(NOTICE, "%d ok", pid); */ + count++; + } +#else + count++; +#endif + } + heap_endscan(sRel); + + UnlockRelation(lRel, AccessShareLock); + heap_close(lRel); + + return count; +} + int assert_enable(int val) { @@ -69,15 +139,14 @@ assert_test(int val) { return assertTest(val); } - #endif /* end of file */ /* - * Local variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * Local Variables: + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/miscutil/misc_utils.h b/contrib/miscutil/misc_utils.h index e82fd4a29d..61217244a2 100644 --- a/contrib/miscutil/misc_utils.h +++ b/contrib/miscutil/misc_utils.h @@ -10,15 +10,15 @@ int assert_enable(int val); #ifdef ASSERT_CHECKING_TEST int assert_test(int val); - #endif +int active_listeners(text *relname); #endif /* - * Local variables: - * tab-width: 4 - * c-indent-level: 4 - * c-basic-offset: 4 + * Local Variables: + * tab-width: 4 + * c-indent-level: 4 + * c-basic-offset: 4 * End: */ diff --git a/contrib/miscutil/misc_utils.sql.in b/contrib/miscutil/misc_utils.sql.in index 1185d743e6..a0418898c6 100644 --- a/contrib/miscutil/misc_utils.sql.in +++ b/contrib/miscutil/misc_utils.sql.in @@ -43,16 +43,22 @@ create function max(int4,int4) returns int4 as 'MODULE_PATHNAME' language 'C'; +-- Return the number of active listeners on a relation +-- +create function active_listeners(text) returns int4 + as 'MODULE_PATHNAME' + language 'C'; + -- Enable/disable Postgres assert checking. -- create function assert_enable(int4) returns int4 - as 'MODULE_PATHNAME' - language 'C'; + as 'MODULE_PATHNAME' + language 'C'; -- Test Postgres assert checking. -- -- create function assert_test(int4) returns int4 --- as 'MODULE_PATHNAME' --- language 'C'; +-- as 'MODULE_PATHNAME' +-- language 'C'; -- end of file |