From b609695b7a5c1cf7c1234143eeb35809d00ff741 Mon Sep 17 00:00:00 2001 From: Bruce Momjian Date: Fri, 12 Aug 2005 03:25:13 +0000 Subject: Add files to do read I/O on the cluster directory: pg_stat_file() pg_read_file() pg_ls_dir() pg_reload_conf() pg_rotate_logfile() Dave Page Andreas Pflug --- src/backend/utils/adt/misc.c | 56 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'src/backend/utils/adt/misc.c') diff --git a/src/backend/utils/adt/misc.c b/src/backend/utils/adt/misc.c index 867f7da7e2a..40b4c64cd12 100644 --- a/src/backend/utils/adt/misc.c +++ b/src/backend/utils/adt/misc.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.45 2005/07/04 04:51:50 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/adt/misc.c,v 1.46 2005/08/12 03:24:08 momjian Exp $ * *------------------------------------------------------------------------- */ @@ -21,14 +21,23 @@ #include "commands/dbcommands.h" #include "miscadmin.h" #include "storage/procarray.h" +#include "storage/pmsignal.h" #include "storage/fd.h" #include "utils/builtins.h" +#include "utils/elog.h" #include "funcapi.h" #include "catalog/pg_type.h" #include "catalog/pg_tablespace.h" +#include "postmaster/syslogger.h" #define atooid(x) ((Oid) strtoul((x), NULL, 10)) +typedef struct +{ + char *location; + DIR *dirdesc; +} directory_fctx; + /* * Check if data is Null @@ -107,6 +116,51 @@ pg_cancel_backend(PG_FUNCTION_ARGS) PG_RETURN_INT32(pg_signal_backend(PG_GETARG_INT32(0), SIGINT)); } + +Datum +pg_reload_conf(PG_FUNCTION_ARGS) +{ + if (!superuser()) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + (errmsg("must be superuser to signal the postmaster")))); + + if (kill(PostmasterPid, SIGHUP)) + { + ereport(WARNING, + (errmsg("failed to send signal to postmaster: %m"))); + + PG_RETURN_INT32(0); + } + + PG_RETURN_INT32(1); +} + + +/* + * Rotate log file + */ +Datum +pg_rotate_logfile(PG_FUNCTION_ARGS) +{ + if (!superuser()) + ereport(ERROR, + (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE), + (errmsg("must be superuser to rotate log files")))); + + if (!Redirect_stderr) + { + ereport(NOTICE, + (errcode(ERRCODE_WARNING), + errmsg("no logfile configured; rotation not supported"))); + PG_RETURN_INT32(0); + } + + SendPostmasterSignal(PMSIGNAL_ROTATE_LOGFILE); + + PG_RETURN_INT32(0); +} + #ifdef NOT_USED /* Disabled in 8.0 due to reliability concerns; FIXME someday */ -- cgit v1.2.3