diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/test/regress/regress.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/test/regress/regress.c b/src/test/regress/regress.c index e5136cfa7c8..acc5d7a59f2 100644 --- a/src/test/regress/regress.c +++ b/src/test/regress/regress.c @@ -6,6 +6,7 @@ #include <float.h> #include <math.h> +#include <signal.h> #include "access/transam.h" #include "access/xact.h" @@ -14,8 +15,10 @@ #include "commands/trigger.h" #include "executor/executor.h" #include "executor/spi.h" +#include "miscadmin.h" #include "utils/builtins.h" #include "utils/geo_decls.h" +#include "utils/memutils.h" #include "utils/rel.h" @@ -35,6 +38,8 @@ extern char *reverse_name(char *string); extern int oldstyle_length(int n, text *t); extern Datum int44in(PG_FUNCTION_ARGS); extern Datum int44out(PG_FUNCTION_ARGS); +extern Datum regress_putenv(PG_FUNCTION_ARGS); +extern Datum wait_pid(PG_FUNCTION_ARGS); #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; @@ -737,3 +742,44 @@ int44out(PG_FUNCTION_ARGS) *--walk = '\0'; PG_RETURN_CSTRING(result); } + +PG_FUNCTION_INFO_V1(regress_putenv); + +Datum +regress_putenv(PG_FUNCTION_ARGS) +{ + MemoryContext oldcontext; + char *envbuf; + + if (!superuser()) + elog(ERROR, "must be superuser to change environment variables"); + + oldcontext = MemoryContextSwitchTo(TopMemoryContext); + envbuf = text_to_cstring((text *) PG_GETARG_POINTER(0)); + MemoryContextSwitchTo(oldcontext); + + if (putenv(envbuf) != 0) + elog(ERROR, "could not set environment variable: %m"); + + PG_RETURN_VOID(); +} + +/* Sleep until no process has a given PID. */ +PG_FUNCTION_INFO_V1(wait_pid); + +Datum +wait_pid(PG_FUNCTION_ARGS) +{ + int pid = PG_GETARG_INT32(0); + + if (!superuser()) + elog(ERROR, "must be superuser to check PID liveness"); + + while (kill(pid, 0) == 0) + pg_usleep(50000); + + if (errno != ESRCH) + elog(ERROR, "could not check PID %d liveness: %m", pid); + + PG_RETURN_VOID(); +} |