mirror of
https://github.com/postgres/postgres.git
synced 2025-11-12 05:01:15 +03:00
Massive commit to run PGINDENT on all *.c and *.h files.
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* enbl.c--
|
||||
* POSTGRES module enable and disable support code.
|
||||
* POSTGRES module enable and disable support code.
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/enbl.c,v 1.1.1.1 1996/07/09 06:22:08 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/enbl.c,v 1.2 1997/09/07 04:53:42 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -16,15 +16,15 @@
|
||||
|
||||
/*
|
||||
* BypassEnable --
|
||||
* False iff enable/disable processing is required given on and "*countP."
|
||||
* False iff enable/disable processing is required given on and "*countP."
|
||||
*
|
||||
* Note:
|
||||
* As a side-effect, *countP is modified. It should be 0 initially.
|
||||
* As a side-effect, *countP is modified. It should be 0 initially.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadState if called with pointer to value 0 and false.
|
||||
* BadArg if "countP" is invalid pointer.
|
||||
* BadArg if on is invalid.
|
||||
* BadState if called with pointer to value 0 and false.
|
||||
* BadArg if "countP" is invalid pointer.
|
||||
* BadArg if on is invalid.
|
||||
*/
|
||||
bool
|
||||
BypassEnable(int *enableCountInOutP, bool on)
|
||||
@@ -32,14 +32,15 @@ BypassEnable(int *enableCountInOutP, bool on)
|
||||
AssertArg(PointerIsValid(enableCountInOutP));
|
||||
AssertArg(BoolIsValid(on));
|
||||
|
||||
if (on) {
|
||||
if (on)
|
||||
{
|
||||
*enableCountInOutP += 1;
|
||||
return ((bool)(*enableCountInOutP >= 2));
|
||||
return ((bool) (*enableCountInOutP >= 2));
|
||||
}
|
||||
|
||||
AssertState(*enableCountInOutP >= 1);
|
||||
|
||||
*enableCountInOutP -= 1;
|
||||
|
||||
return ((bool)(*enableCountInOutP >= 1));
|
||||
return ((bool) (*enableCountInOutP >= 1));
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.5 1997/08/27 03:48:38 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.6 1997/09/07 04:53:45 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -19,213 +19,230 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "postgres.h"
|
||||
#include "miscadmin.h" /* for DebugLvl */
|
||||
#include "miscadmin.h" /* for DebugLvl */
|
||||
|
||||
#ifndef S_IRUSR /* XXX [TRH] should be in a header */
|
||||
# define S_IRUSR S_IREAD
|
||||
# define S_IWUSR S_IWRITE
|
||||
# define S_IXUSR S_IEXEC
|
||||
# define S_IRGRP ((S_IRUSR)>>3)
|
||||
# define S_IWGRP ((S_IWUSR)>>3)
|
||||
# define S_IXGRP ((S_IXUSR)>>3)
|
||||
# define S_IROTH ((S_IRUSR)>>6)
|
||||
# define S_IWOTH ((S_IWUSR)>>6)
|
||||
# define S_IXOTH ((S_IXUSR)>>6)
|
||||
#ifndef S_IRUSR /* XXX [TRH] should be in a header */
|
||||
#define S_IRUSR S_IREAD
|
||||
#define S_IWUSR S_IWRITE
|
||||
#define S_IXUSR S_IEXEC
|
||||
#define S_IRGRP ((S_IRUSR)>>3)
|
||||
#define S_IWGRP ((S_IWUSR)>>3)
|
||||
#define S_IXGRP ((S_IXUSR)>>3)
|
||||
#define S_IROTH ((S_IRUSR)>>6)
|
||||
#define S_IWOTH ((S_IWUSR)>>6)
|
||||
#define S_IXOTH ((S_IXUSR)>>6)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ValidateBackend -- validate "path" as a POSTGRES executable file
|
||||
*
|
||||
* returns 0 if the file is found and no error is encountered.
|
||||
* -1 if the regular file "path" does not exist or cannot be executed.
|
||||
* -2 if the file is otherwise valid but cannot be read.
|
||||
* -1 if the regular file "path" does not exist or cannot be executed.
|
||||
* -2 if the file is otherwise valid but cannot be read.
|
||||
*/
|
||||
int
|
||||
ValidateBackend(char *path)
|
||||
{
|
||||
struct stat buf;
|
||||
uid_t euid;
|
||||
struct group *gp;
|
||||
struct passwd *pwp;
|
||||
int i;
|
||||
int is_r = 0;
|
||||
int is_x = 0;
|
||||
int in_grp = 0;
|
||||
|
||||
/*
|
||||
* Ensure that the file exists and is a regular file.
|
||||
*
|
||||
* XXX if you have a broken system where stat() looks at the symlink
|
||||
* instead of the underlying file, you lose.
|
||||
*/
|
||||
if (strlen(path) >= MAXPGPATH) {
|
||||
if (DebugLvl > 1)
|
||||
fprintf(stderr, "ValidateBackend: pathname \"%s\" is too long\n",
|
||||
path);
|
||||
return(-1);
|
||||
}
|
||||
struct stat buf;
|
||||
uid_t euid;
|
||||
struct group *gp;
|
||||
struct passwd *pwp;
|
||||
int i;
|
||||
int is_r = 0;
|
||||
int is_x = 0;
|
||||
int in_grp = 0;
|
||||
|
||||
if (stat(path, &buf) < 0) {
|
||||
if (DebugLvl > 1)
|
||||
fprintf(stderr, "ValidateBackend: can't stat \"%s\"\n",
|
||||
path);
|
||||
return(-1);
|
||||
}
|
||||
if (!(buf.st_mode & S_IFREG)) {
|
||||
if (DebugLvl > 1)
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not a regular file\n",
|
||||
path);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure that we are using an authorized backend.
|
||||
*
|
||||
* XXX I'm open to suggestions here. I would like to enforce ownership
|
||||
* of backends by user "postgres" but people seem to like to run
|
||||
* as users other than "postgres"...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ensure that the file is both executable and readable (required for
|
||||
* dynamic loading).
|
||||
*
|
||||
* We use the effective uid here because the backend will not have
|
||||
* executed setuid() by the time it calls this routine.
|
||||
*/
|
||||
euid = geteuid();
|
||||
if (euid == buf.st_uid) {
|
||||
is_r = buf.st_mode & S_IRUSR;
|
||||
is_x = buf.st_mode & S_IXUSR;
|
||||
if (DebugLvl > 1 && !(is_r && is_x))
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not user read/execute\n",
|
||||
path);
|
||||
return(is_x ? (is_r ? 0 : -2) : -1);
|
||||
}
|
||||
pwp = getpwuid(euid);
|
||||
if (pwp) {
|
||||
if (pwp->pw_gid == buf.st_gid) {
|
||||
++in_grp;
|
||||
} else if (pwp->pw_name &&
|
||||
(gp = getgrgid(buf.st_gid))) {
|
||||
for (i = 0; gp->gr_mem[i]; ++i) {
|
||||
if (!strcmp(gp->gr_mem[i], pwp->pw_name)) {
|
||||
++in_grp;
|
||||
break;
|
||||
/*
|
||||
* Ensure that the file exists and is a regular file.
|
||||
*
|
||||
* XXX if you have a broken system where stat() looks at the symlink
|
||||
* instead of the underlying file, you lose.
|
||||
*/
|
||||
if (strlen(path) >= MAXPGPATH)
|
||||
{
|
||||
if (DebugLvl > 1)
|
||||
fprintf(stderr, "ValidateBackend: pathname \"%s\" is too long\n",
|
||||
path);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
if (stat(path, &buf) < 0)
|
||||
{
|
||||
if (DebugLvl > 1)
|
||||
fprintf(stderr, "ValidateBackend: can't stat \"%s\"\n",
|
||||
path);
|
||||
return (-1);
|
||||
}
|
||||
if (!(buf.st_mode & S_IFREG))
|
||||
{
|
||||
if (DebugLvl > 1)
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not a regular file\n",
|
||||
path);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Ensure that we are using an authorized backend.
|
||||
*
|
||||
* XXX I'm open to suggestions here. I would like to enforce ownership
|
||||
* of backends by user "postgres" but people seem to like to run as
|
||||
* users other than "postgres"...
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ensure that the file is both executable and readable (required for
|
||||
* dynamic loading).
|
||||
*
|
||||
* We use the effective uid here because the backend will not have
|
||||
* executed setuid() by the time it calls this routine.
|
||||
*/
|
||||
euid = geteuid();
|
||||
if (euid == buf.st_uid)
|
||||
{
|
||||
is_r = buf.st_mode & S_IRUSR;
|
||||
is_x = buf.st_mode & S_IXUSR;
|
||||
if (DebugLvl > 1 && !(is_r && is_x))
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not user read/execute\n",
|
||||
path);
|
||||
return (is_x ? (is_r ? 0 : -2) : -1);
|
||||
}
|
||||
pwp = getpwuid(euid);
|
||||
if (pwp)
|
||||
{
|
||||
if (pwp->pw_gid == buf.st_gid)
|
||||
{
|
||||
++in_grp;
|
||||
}
|
||||
else if (pwp->pw_name &&
|
||||
(gp = getgrgid(buf.st_gid)))
|
||||
{
|
||||
for (i = 0; gp->gr_mem[i]; ++i)
|
||||
{
|
||||
if (!strcmp(gp->gr_mem[i], pwp->pw_name))
|
||||
{
|
||||
++in_grp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (in_grp)
|
||||
{
|
||||
is_r = buf.st_mode & S_IRGRP;
|
||||
is_x = buf.st_mode & S_IXGRP;
|
||||
if (DebugLvl > 1 && !(is_r && is_x))
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not group read/execute\n",
|
||||
path);
|
||||
return (is_x ? (is_r ? 0 : -2) : -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (in_grp) {
|
||||
is_r = buf.st_mode & S_IRGRP;
|
||||
is_x = buf.st_mode & S_IXGRP;
|
||||
if (DebugLvl > 1 && !(is_r && is_x))
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not group read/execute\n",
|
||||
path);
|
||||
return(is_x ? (is_r ? 0 : -2) : -1);
|
||||
}
|
||||
}
|
||||
is_r = buf.st_mode & S_IROTH;
|
||||
is_x = buf.st_mode & S_IXOTH;
|
||||
if (DebugLvl > 1 && !(is_r && is_x))
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not other read/execute\n",
|
||||
path);
|
||||
return(is_x ? (is_r ? 0 : -2) : -1);
|
||||
is_r = buf.st_mode & S_IROTH;
|
||||
is_x = buf.st_mode & S_IXOTH;
|
||||
if (DebugLvl > 1 && !(is_r && is_x))
|
||||
fprintf(stderr, "ValidateBackend: \"%s\" is not other read/execute\n",
|
||||
path);
|
||||
return (is_x ? (is_r ? 0 : -2) : -1);
|
||||
}
|
||||
|
||||
/*
|
||||
* FindBackend -- find an absolute path to a valid backend executable
|
||||
*
|
||||
* The reason we have to work so hard to find an absolute path is that
|
||||
* we need to feed the backend server the location of its actual
|
||||
* we need to feed the backend server the location of its actual
|
||||
* executable file -- otherwise, we can't do dynamic loading.
|
||||
*/
|
||||
int
|
||||
FindBackend(char *backend, char *argv0)
|
||||
{
|
||||
char buf[MAXPGPATH + 2];
|
||||
char *p;
|
||||
char *path, *startp, *endp;
|
||||
int pathlen;
|
||||
|
||||
/*
|
||||
* for the postmaster:
|
||||
* First try: use the backend that's located in the same directory
|
||||
* as the postmaster, if it was invoked with an explicit path.
|
||||
* Presumably the user used an explicit path because it wasn't in
|
||||
* PATH, and we don't want to use incompatible executables.
|
||||
*
|
||||
* This has the neat property that it works for installed binaries,
|
||||
* old source trees (obj/support/post{master,gres}) and new marc
|
||||
* source trees (obj/post{master,gres}) because they all put the
|
||||
* two binaries in the same place.
|
||||
*
|
||||
* for the backend server:
|
||||
* First try: if we're given some kind of path, use it (making sure
|
||||
* that a relative path is made absolute before returning it).
|
||||
*/
|
||||
if (argv0 && (p = strrchr(argv0, '/')) && *++p) {
|
||||
if (*argv0 == '/' || !getcwd(buf, MAXPGPATH))
|
||||
buf[0] = '\0';
|
||||
else
|
||||
strcat(buf, "/");
|
||||
strcat(buf, argv0);
|
||||
p = strrchr(buf, '/');
|
||||
strcpy(++p, "postgres");
|
||||
if (!ValidateBackend(buf)) {
|
||||
strncpy(backend, buf, MAXPGPATH);
|
||||
if (DebugLvl)
|
||||
fprintf(stderr, "FindBackend: found \"%s\" using argv[0]\n",
|
||||
backend);
|
||||
return(0);
|
||||
}
|
||||
fprintf(stderr, "FindBackend: invalid backend \"%s\"\n",
|
||||
buf);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Second try: since no explicit path was supplied, the user must
|
||||
* have been relying on PATH. We'll use the same PATH.
|
||||
*/
|
||||
if ((p = getenv("PATH")) && *p) {
|
||||
if (DebugLvl)
|
||||
fprintf(stderr, "FindBackend: searching PATH ...\n");
|
||||
pathlen = strlen(p);
|
||||
path = malloc(pathlen + 1);
|
||||
strcpy(path, p);
|
||||
for (startp = path, endp = strchr(path, ':');
|
||||
startp && *startp;
|
||||
startp = endp + 1, endp = strchr(startp, ':')) {
|
||||
if (startp == endp) /* it's a "::" */
|
||||
continue;
|
||||
if (endp)
|
||||
*endp = '\0';
|
||||
if (*startp == '/' || !getcwd(buf, MAXPGPATH))
|
||||
buf[0] = '\0';
|
||||
strcat(buf, startp);
|
||||
strcat(buf, "/postgres");
|
||||
switch (ValidateBackend(buf)) {
|
||||
case 0: /* found ok */
|
||||
strncpy(backend, buf, MAXPGPATH);
|
||||
if (DebugLvl)
|
||||
fprintf(stderr, "FindBackend: found \"%s\" using PATH\n",
|
||||
backend);
|
||||
free(path);
|
||||
return(0);
|
||||
case -1: /* wasn't even a candidate, keep looking */
|
||||
break;
|
||||
case -2: /* found but disqualified */
|
||||
fprintf(stderr, "FindBackend: could not read backend \"%s\"\n",
|
||||
buf);
|
||||
free(path);
|
||||
return(-1);
|
||||
}
|
||||
if (!endp) /* last one */
|
||||
break;
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
char buf[MAXPGPATH + 2];
|
||||
char *p;
|
||||
char *path,
|
||||
*startp,
|
||||
*endp;
|
||||
int pathlen;
|
||||
|
||||
fprintf(stderr, "FindBackend: could not find a backend to execute...\n");
|
||||
return(-1);
|
||||
/*
|
||||
* for the postmaster: First try: use the backend that's located in
|
||||
* the same directory as the postmaster, if it was invoked with an
|
||||
* explicit path. Presumably the user used an explicit path because it
|
||||
* wasn't in PATH, and we don't want to use incompatible executables.
|
||||
*
|
||||
* This has the neat property that it works for installed binaries, old
|
||||
* source trees (obj/support/post{master,gres}) and new marc source
|
||||
* trees (obj/post{master,gres}) because they all put the two binaries
|
||||
* in the same place.
|
||||
*
|
||||
* for the backend server: First try: if we're given some kind of path,
|
||||
* use it (making sure that a relative path is made absolute before
|
||||
* returning it).
|
||||
*/
|
||||
if (argv0 && (p = strrchr(argv0, '/')) && *++p)
|
||||
{
|
||||
if (*argv0 == '/' || !getcwd(buf, MAXPGPATH))
|
||||
buf[0] = '\0';
|
||||
else
|
||||
strcat(buf, "/");
|
||||
strcat(buf, argv0);
|
||||
p = strrchr(buf, '/');
|
||||
strcpy(++p, "postgres");
|
||||
if (!ValidateBackend(buf))
|
||||
{
|
||||
strncpy(backend, buf, MAXPGPATH);
|
||||
if (DebugLvl)
|
||||
fprintf(stderr, "FindBackend: found \"%s\" using argv[0]\n",
|
||||
backend);
|
||||
return (0);
|
||||
}
|
||||
fprintf(stderr, "FindBackend: invalid backend \"%s\"\n",
|
||||
buf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Second try: since no explicit path was supplied, the user must have
|
||||
* been relying on PATH. We'll use the same PATH.
|
||||
*/
|
||||
if ((p = getenv("PATH")) && *p)
|
||||
{
|
||||
if (DebugLvl)
|
||||
fprintf(stderr, "FindBackend: searching PATH ...\n");
|
||||
pathlen = strlen(p);
|
||||
path = malloc(pathlen + 1);
|
||||
strcpy(path, p);
|
||||
for (startp = path, endp = strchr(path, ':');
|
||||
startp && *startp;
|
||||
startp = endp + 1, endp = strchr(startp, ':'))
|
||||
{
|
||||
if (startp == endp) /* it's a "::" */
|
||||
continue;
|
||||
if (endp)
|
||||
*endp = '\0';
|
||||
if (*startp == '/' || !getcwd(buf, MAXPGPATH))
|
||||
buf[0] = '\0';
|
||||
strcat(buf, startp);
|
||||
strcat(buf, "/postgres");
|
||||
switch (ValidateBackend(buf))
|
||||
{
|
||||
case 0: /* found ok */
|
||||
strncpy(backend, buf, MAXPGPATH);
|
||||
if (DebugLvl)
|
||||
fprintf(stderr, "FindBackend: found \"%s\" using PATH\n",
|
||||
backend);
|
||||
free(path);
|
||||
return (0);
|
||||
case -1: /* wasn't even a candidate, keep looking */
|
||||
break;
|
||||
case -2: /* found but disqualified */
|
||||
fprintf(stderr, "FindBackend: could not read backend \"%s\"\n",
|
||||
buf);
|
||||
free(path);
|
||||
return (-1);
|
||||
}
|
||||
if (!endp) /* last one */
|
||||
break;
|
||||
}
|
||||
free(path);
|
||||
}
|
||||
|
||||
fprintf(stderr, "FindBackend: could not find a backend to execute...\n");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* globals.c--
|
||||
* global variable declarations
|
||||
* global variable declarations
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.10 1997/08/14 16:11:21 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.11 1997/09/07 04:53:48 momjian Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Globals used all over the place should be declared here and not
|
||||
* in other modules.
|
||||
* Globals used all over the place should be declared here and not
|
||||
* in other modules.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -24,7 +24,7 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "postgres.h"
|
||||
#include "miscadmin.h" /* where the declarations go */
|
||||
#include "miscadmin.h" /* where the declarations go */
|
||||
|
||||
#include <storage/backendid.h>
|
||||
#include "access/heapam.h"
|
||||
@@ -36,83 +36,86 @@
|
||||
|
||||
#include "catalog/catname.h"
|
||||
|
||||
int Portfd = -1;
|
||||
int Noversion = 0;
|
||||
int Quiet = 1;
|
||||
int Portfd = -1;
|
||||
int Noversion = 0;
|
||||
int Quiet = 1;
|
||||
|
||||
int MasterPid;
|
||||
char *DataDir;
|
||||
/* The PGDATA directory user says to use, or defaults to via environment
|
||||
variable. NULL if no option given and no environment variable set
|
||||
int MasterPid;
|
||||
char *DataDir;
|
||||
|
||||
/*
|
||||
* The PGDATA directory user says to use, or defaults to via environment
|
||||
* variable. NULL if no option given and no environment variable set
|
||||
*/
|
||||
Relation reldesc; /* current relation descriptor */
|
||||
|
||||
char OutputFileName[MAXPGPATH] = "";
|
||||
Relation reldesc; /* current relation descriptor */
|
||||
|
||||
BackendId MyBackendId;
|
||||
BackendTag MyBackendTag;
|
||||
char OutputFileName[MAXPGPATH] = "";
|
||||
|
||||
char *UserName = NULL;
|
||||
char *DatabaseName = NULL;
|
||||
char *DatabasePath = NULL;
|
||||
BackendId MyBackendId;
|
||||
BackendTag MyBackendTag;
|
||||
|
||||
bool MyDatabaseIdIsInitialized = false;
|
||||
Oid MyDatabaseId = InvalidOid;
|
||||
bool TransactionInitWasProcessed = false;
|
||||
char *UserName = NULL;
|
||||
char *DatabaseName = NULL;
|
||||
char *DatabasePath = NULL;
|
||||
|
||||
bool IsUnderPostmaster = false;
|
||||
bool IsPostmaster = false;
|
||||
bool MyDatabaseIdIsInitialized = false;
|
||||
Oid MyDatabaseId = InvalidOid;
|
||||
bool TransactionInitWasProcessed = false;
|
||||
|
||||
short DebugLvl = 0;
|
||||
bool IsUnderPostmaster = false;
|
||||
bool IsPostmaster = false;
|
||||
|
||||
int DateStyle = USE_POSTGRES_DATES;
|
||||
bool EuroDates = false;
|
||||
bool HasCTZSet = false;
|
||||
bool CDayLight = false;
|
||||
int CTimeZone = 0;
|
||||
char CTZName[MAXTZLEN+1] = "";
|
||||
short DebugLvl = 0;
|
||||
|
||||
char DateFormat[20] = "%d-%m-%Y"; /* mjl: sizes! or better malloc? XXX */
|
||||
char FloatFormat[20] = "%f";
|
||||
int DateStyle = USE_POSTGRES_DATES;
|
||||
bool EuroDates = false;
|
||||
bool HasCTZSet = false;
|
||||
bool CDayLight = false;
|
||||
int CTimeZone = 0;
|
||||
char CTZName[MAXTZLEN + 1] = "";
|
||||
|
||||
int fsyncOff = 0;
|
||||
int SortMem = 512;
|
||||
char DateFormat[20] = "%d-%m-%Y"; /* mjl: sizes! or better
|
||||
* malloc? XXX */
|
||||
char FloatFormat[20] = "%f";
|
||||
|
||||
char *IndexedCatalogNames[] = {
|
||||
AttributeRelationName,
|
||||
ProcedureRelationName,
|
||||
TypeRelationName,
|
||||
RelationRelationName,
|
||||
0
|
||||
int fsyncOff = 0;
|
||||
int SortMem = 512;
|
||||
|
||||
char *IndexedCatalogNames[] = {
|
||||
AttributeRelationName,
|
||||
ProcedureRelationName,
|
||||
TypeRelationName,
|
||||
RelationRelationName,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
/* ----------------
|
||||
* we just do a linear search now so there's no requirement that the list
|
||||
* be ordered. The list is so small it shouldn't make much difference.
|
||||
* be ordered. The list is so small it shouldn't make much difference.
|
||||
* make sure the list is null-terminated
|
||||
* - jolly 8/19/95
|
||||
*
|
||||
* - jolly 8/19/95
|
||||
*
|
||||
* OLD COMMENT
|
||||
* WARNING WARNING WARNING WARNING WARNING WARNING
|
||||
* WARNING WARNING WARNING WARNING WARNING WARNING
|
||||
*
|
||||
* keep SharedSystemRelationNames[] in SORTED order! A binary search
|
||||
* is done on it in catalog.c!
|
||||
* keep SharedSystemRelationNames[] in SORTED order! A binary search
|
||||
* is done on it in catalog.c!
|
||||
*
|
||||
* XXX this is a serious hack which should be fixed -cim 1/26/90
|
||||
* XXX this is a serious hack which should be fixed -cim 1/26/90
|
||||
* ----------------
|
||||
*/
|
||||
char *SharedSystemRelationNames[] = {
|
||||
DatabaseRelationName,
|
||||
DefaultsRelationName,
|
||||
DemonRelationName,
|
||||
GroupRelationName,
|
||||
HostsRelationName,
|
||||
LogRelationName,
|
||||
MagicRelationName,
|
||||
ServerRelationName,
|
||||
TimeRelationName,
|
||||
UserRelationName,
|
||||
VariableRelationName,
|
||||
0
|
||||
char *SharedSystemRelationNames[] = {
|
||||
DatabaseRelationName,
|
||||
DefaultsRelationName,
|
||||
DemonRelationName,
|
||||
GroupRelationName,
|
||||
HostsRelationName,
|
||||
LogRelationName,
|
||||
MagicRelationName,
|
||||
ServerRelationName,
|
||||
TimeRelationName,
|
||||
UserRelationName,
|
||||
VariableRelationName,
|
||||
0
|
||||
};
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/*-------------------------------------------------------------------------
|
||||
*
|
||||
* miscinit.c--
|
||||
* miscellanious initialization support stuff
|
||||
* miscellanious initialization support stuff
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.6 1997/08/19 21:35:44 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.7 1997/09/07 04:53:49 momjian Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
#include <string.h>
|
||||
#include <sys/param.h> /* for MAXPATHLEN */
|
||||
#include <sys/param.h> /* for MAXPATHLEN */
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/file.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <grp.h> /* for getgrgid */
|
||||
#include <pwd.h> /* for getpwuid */
|
||||
#include <grp.h> /* for getgrgid */
|
||||
#include <pwd.h> /* for getpwuid */
|
||||
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/portal.h" /* for EnablePortalManager, etc. */
|
||||
#include "utils/exc.h" /* for EnableExceptionHandling, etc. */
|
||||
#include "utils/mcxt.h" /* for EnableMemoryContext, etc. */
|
||||
#include "utils/portal.h" /* for EnablePortalManager, etc. */
|
||||
#include "utils/exc.h" /* for EnableExceptionHandling, etc. */
|
||||
#include "utils/mcxt.h" /* for EnableMemoryContext, etc. */
|
||||
#include "utils/elog.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
#include "miscadmin.h" /* where the declarations go */
|
||||
#include "miscadmin.h" /* where the declarations go */
|
||||
|
||||
#include "catalog/catname.h"
|
||||
#include "catalog/pg_user.h"
|
||||
#include "catalog/pg_proc.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
#include "storage/fd.h" /* for O_ */
|
||||
#include "storage/fd.h" /* for O_ */
|
||||
|
||||
/*
|
||||
* EnableAbortEnvVarName --
|
||||
* Enables system abort iff set to a non-empty string in environment.
|
||||
* Enables system abort iff set to a non-empty string in environment.
|
||||
*/
|
||||
#define EnableAbortEnvVarName "POSTGRESABORT"
|
||||
|
||||
extern char *getenv(const char *name); /* XXX STDLIB */
|
||||
extern char *getenv(const char *name); /* XXX STDLIB */
|
||||
|
||||
/* from globals.c */
|
||||
extern char *DatabaseName;
|
||||
extern char *UserName;
|
||||
extern char *DatabasePath;
|
||||
/* from globals.c */
|
||||
extern char *DatabaseName;
|
||||
extern char *UserName;
|
||||
extern char *DatabasePath;
|
||||
|
||||
|
||||
/*
|
||||
@@ -59,282 +59,286 @@ extern char *DatabasePath;
|
||||
#define USE_ENVIRONMENT
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* some of the 19 ways to leave postgres
|
||||
* some of the 19 ways to leave postgres
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* ExitPostgres --
|
||||
* Exit POSTGRES with a status code.
|
||||
* Exit POSTGRES with a status code.
|
||||
*
|
||||
* Note:
|
||||
* This function never returns.
|
||||
* ...
|
||||
* This function never returns.
|
||||
* ...
|
||||
*
|
||||
* Side effects:
|
||||
* ...
|
||||
* ...
|
||||
*
|
||||
* Exceptions:
|
||||
* none
|
||||
* none
|
||||
*/
|
||||
void
|
||||
ExitPostgres(ExitStatus status)
|
||||
{
|
||||
#ifdef __SABER__
|
||||
saber_stop();
|
||||
saber_stop();
|
||||
#endif
|
||||
exitpg(status);
|
||||
exitpg(status);
|
||||
}
|
||||
|
||||
/*
|
||||
* AbortPostgres --
|
||||
* Abort POSTGRES dumping core.
|
||||
* Abort POSTGRES dumping core.
|
||||
*
|
||||
* Note:
|
||||
* This function never returns.
|
||||
* ...
|
||||
* This function never returns.
|
||||
* ...
|
||||
*
|
||||
* Side effects:
|
||||
* Core is dumped iff EnableAbortEnvVarName is set to a non-empty string.
|
||||
* ...
|
||||
* Core is dumped iff EnableAbortEnvVarName is set to a non-empty string.
|
||||
* ...
|
||||
*
|
||||
* Exceptions:
|
||||
* none
|
||||
* none
|
||||
*/
|
||||
#ifdef NOT_USED
|
||||
void
|
||||
AbortPostgres()
|
||||
{
|
||||
char *abortValue = getenv(EnableAbortEnvVarName);
|
||||
|
||||
char *abortValue = getenv(EnableAbortEnvVarName);
|
||||
|
||||
#ifdef __SABER__
|
||||
saber_stop();
|
||||
saber_stop();
|
||||
#endif
|
||||
|
||||
if (PointerIsValid(abortValue) && abortValue[0] != '\0')
|
||||
abort();
|
||||
else
|
||||
exitpg(FatalExitStatus);
|
||||
|
||||
if (PointerIsValid(abortValue) && abortValue[0] != '\0')
|
||||
abort();
|
||||
else
|
||||
exitpg(FatalExitStatus);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ----------------
|
||||
* StatusBackendExit
|
||||
* StatusBackendExit
|
||||
* ----------------
|
||||
*/
|
||||
void
|
||||
StatusBackendExit(int status)
|
||||
{
|
||||
/* someday, do some real cleanup and then call the LISP exit */
|
||||
/* someday, call StatusPostmasterExit if running without postmaster */
|
||||
exitpg(status);
|
||||
/* someday, do some real cleanup and then call the LISP exit */
|
||||
/* someday, call StatusPostmasterExit if running without postmaster */
|
||||
exitpg(status);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* StatusPostmasterExit
|
||||
* StatusPostmasterExit
|
||||
* ----------------
|
||||
*/
|
||||
void
|
||||
StatusPostmasterExit(int status)
|
||||
{
|
||||
/* someday, do some real cleanup and then call the LISP exit */
|
||||
exitpg(status);
|
||||
/* someday, do some real cleanup and then call the LISP exit */
|
||||
exitpg(status);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* processing mode support stuff (used to be in pmod.c)
|
||||
* processing mode support stuff (used to be in pmod.c)
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
static ProcessingMode Mode = NoProcessing;
|
||||
static ProcessingMode Mode = NoProcessing;
|
||||
|
||||
/*
|
||||
* IsNoProcessingMode --
|
||||
* True iff processing mode is NoProcessing.
|
||||
* True iff processing mode is NoProcessing.
|
||||
*/
|
||||
bool
|
||||
IsNoProcessingMode()
|
||||
{
|
||||
return ((bool)(Mode == NoProcessing));
|
||||
return ((bool) (Mode == NoProcessing));
|
||||
}
|
||||
|
||||
/*
|
||||
* IsBootstrapProcessingMode --
|
||||
* True iff processing mode is BootstrapProcessing.
|
||||
* True iff processing mode is BootstrapProcessing.
|
||||
*/
|
||||
bool
|
||||
IsBootstrapProcessingMode()
|
||||
{
|
||||
return ((bool)(Mode == BootstrapProcessing));
|
||||
return ((bool) (Mode == BootstrapProcessing));
|
||||
}
|
||||
|
||||
/*
|
||||
* IsInitProcessingMode --
|
||||
* True iff processing mode is InitProcessing.
|
||||
* True iff processing mode is InitProcessing.
|
||||
*/
|
||||
bool
|
||||
IsInitProcessingMode()
|
||||
{
|
||||
return ((bool)(Mode == InitProcessing));
|
||||
return ((bool) (Mode == InitProcessing));
|
||||
}
|
||||
|
||||
/*
|
||||
* IsNormalProcessingMode --
|
||||
* True iff processing mode is NormalProcessing.
|
||||
* True iff processing mode is NormalProcessing.
|
||||
*/
|
||||
bool
|
||||
IsNormalProcessingMode()
|
||||
{
|
||||
return ((bool)(Mode == NormalProcessing));
|
||||
return ((bool) (Mode == NormalProcessing));
|
||||
}
|
||||
|
||||
/*
|
||||
* SetProcessingMode --
|
||||
* Sets mode of processing as specified.
|
||||
* Sets mode of processing as specified.
|
||||
*
|
||||
* Exceptions:
|
||||
* BadArg if called with invalid mode.
|
||||
* BadArg if called with invalid mode.
|
||||
*
|
||||
* Note:
|
||||
* Mode is NoProcessing before the first time this is called.
|
||||
* Mode is NoProcessing before the first time this is called.
|
||||
*/
|
||||
void
|
||||
SetProcessingMode(ProcessingMode mode)
|
||||
{
|
||||
AssertArg(mode == NoProcessing || mode == BootstrapProcessing ||
|
||||
mode == InitProcessing || mode == NormalProcessing);
|
||||
|
||||
Mode = mode;
|
||||
AssertArg(mode == NoProcessing || mode == BootstrapProcessing ||
|
||||
mode == InitProcessing || mode == NormalProcessing);
|
||||
|
||||
Mode = mode;
|
||||
}
|
||||
|
||||
ProcessingMode
|
||||
GetProcessingMode()
|
||||
{
|
||||
return (Mode);
|
||||
return (Mode);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* database path / name support stuff
|
||||
* database path / name support stuff
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/*
|
||||
* GetDatabasePath --
|
||||
* Returns path to database.
|
||||
* Returns path to database.
|
||||
*
|
||||
*/
|
||||
char*
|
||||
char *
|
||||
GetDatabasePath()
|
||||
{
|
||||
return DatabasePath;
|
||||
return DatabasePath;
|
||||
}
|
||||
|
||||
/*
|
||||
* GetDatabaseName --
|
||||
* Returns name of database.
|
||||
* Returns name of database.
|
||||
*/
|
||||
char*
|
||||
char *
|
||||
GetDatabaseName()
|
||||
{
|
||||
return DatabaseName;
|
||||
return DatabaseName;
|
||||
}
|
||||
|
||||
void
|
||||
SetDatabasePath(char *path)
|
||||
{
|
||||
/* use malloc since this is done before memory contexts are set up */
|
||||
if (DatabasePath)
|
||||
free(DatabasePath);
|
||||
DatabasePath = malloc(strlen(path)+1);
|
||||
strcpy(DatabasePath, path);
|
||||
/* use malloc since this is done before memory contexts are set up */
|
||||
if (DatabasePath)
|
||||
free(DatabasePath);
|
||||
DatabasePath = malloc(strlen(path) + 1);
|
||||
strcpy(DatabasePath, path);
|
||||
}
|
||||
|
||||
void
|
||||
SetDatabaseName(char *name)
|
||||
{
|
||||
if (DatabaseName)
|
||||
free (DatabaseName);
|
||||
DatabaseName = malloc(strlen(name)+1);
|
||||
strcpy(DatabaseName, name);
|
||||
if (DatabaseName)
|
||||
free(DatabaseName);
|
||||
DatabaseName = malloc(strlen(name) + 1);
|
||||
strcpy(DatabaseName, name);
|
||||
}
|
||||
|
||||
/* ----------------
|
||||
* GetPgUserName and SetPgUserName
|
||||
* GetPgUserName and SetPgUserName
|
||||
*
|
||||
* SetPgUserName must be called before InitPostgres, since the setuid()
|
||||
* is done there.
|
||||
* SetPgUserName must be called before InitPostgres, since the setuid()
|
||||
* is done there.
|
||||
*
|
||||
* Replace GetPgUserName() with a lower-case version
|
||||
* to allow use in new case-insensitive SQL (referenced
|
||||
* in pg_proc.h). Define GetPgUserName() as a macro - tgl 97/04/26
|
||||
* Replace GetPgUserName() with a lower-case version
|
||||
* to allow use in new case-insensitive SQL (referenced
|
||||
* in pg_proc.h). Define GetPgUserName() as a macro - tgl 97/04/26
|
||||
* ----------------
|
||||
*/
|
||||
char*
|
||||
char *
|
||||
getpgusername()
|
||||
{
|
||||
return UserName;
|
||||
return UserName;
|
||||
}
|
||||
|
||||
void
|
||||
SetPgUserName()
|
||||
{
|
||||
#ifndef NO_SECURITY
|
||||
char *p;
|
||||
struct passwd *pw;
|
||||
|
||||
if (IsUnderPostmaster) {
|
||||
/* use the (possibly) authenticated name that's provided */
|
||||
if (!(p = getenv("PG_USER")))
|
||||
elog(FATAL, "SetPgUserName: PG_USER environment variable unset");
|
||||
} else {
|
||||
/* setuid() has not yet been done, see above comment */
|
||||
if (!(pw = getpwuid(geteuid())))
|
||||
elog(FATAL, "SetPgUserName: no entry in passwd file");
|
||||
p = pw->pw_name;
|
||||
}
|
||||
if (UserName)
|
||||
free(UserName);
|
||||
UserName = malloc(strlen(p)+1);
|
||||
strcpy(UserName, p);
|
||||
#endif /* NO_SECURITY */
|
||||
char *p;
|
||||
struct passwd *pw;
|
||||
|
||||
if (IsUnderPostmaster)
|
||||
{
|
||||
/* use the (possibly) authenticated name that's provided */
|
||||
if (!(p = getenv("PG_USER")))
|
||||
elog(FATAL, "SetPgUserName: PG_USER environment variable unset");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* setuid() has not yet been done, see above comment */
|
||||
if (!(pw = getpwuid(geteuid())))
|
||||
elog(FATAL, "SetPgUserName: no entry in passwd file");
|
||||
p = pw->pw_name;
|
||||
}
|
||||
if (UserName)
|
||||
free(UserName);
|
||||
UserName = malloc(strlen(p) + 1);
|
||||
strcpy(UserName, p);
|
||||
#endif /* NO_SECURITY */
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
* GetUserId and SetUserId
|
||||
* GetUserId and SetUserId
|
||||
* ----------------------------------------------------------------
|
||||
*/
|
||||
static Oid UserId = InvalidOid;
|
||||
static Oid UserId = InvalidOid;
|
||||
|
||||
Oid
|
||||
GetUserId()
|
||||
{
|
||||
Assert(OidIsValid(UserId));
|
||||
return(UserId);
|
||||
Assert(OidIsValid(UserId));
|
||||
return (UserId);
|
||||
}
|
||||
|
||||
void
|
||||
SetUserId()
|
||||
{
|
||||
HeapTuple userTup;
|
||||
char *userName;
|
||||
|
||||
Assert(!OidIsValid(UserId)); /* only once */
|
||||
|
||||
/*
|
||||
* Don't do scans if we're bootstrapping, none of the system
|
||||
* catalogs exist yet, and they should be owned by postgres
|
||||
* anyway.
|
||||
*/
|
||||
if (IsBootstrapProcessingMode()) {
|
||||
UserId = geteuid();
|
||||
return;
|
||||
}
|
||||
|
||||
userName = GetPgUserName();
|
||||
userTup = SearchSysCacheTuple(USENAME, PointerGetDatum(userName),
|
||||
0,0,0);
|
||||
if (!HeapTupleIsValid(userTup))
|
||||
elog(FATAL, "SetUserId: user \"%s\" is not in \"%s\"",
|
||||
userName,
|
||||
UserRelationName);
|
||||
UserId = (Oid) ((Form_pg_user) GETSTRUCT(userTup))->usesysid;
|
||||
HeapTuple userTup;
|
||||
char *userName;
|
||||
|
||||
Assert(!OidIsValid(UserId));/* only once */
|
||||
|
||||
/*
|
||||
* Don't do scans if we're bootstrapping, none of the system catalogs
|
||||
* exist yet, and they should be owned by postgres anyway.
|
||||
*/
|
||||
if (IsBootstrapProcessingMode())
|
||||
{
|
||||
UserId = geteuid();
|
||||
return;
|
||||
}
|
||||
|
||||
userName = GetPgUserName();
|
||||
userTup = SearchSysCacheTuple(USENAME, PointerGetDatum(userName),
|
||||
0, 0, 0);
|
||||
if (!HeapTupleIsValid(userTup))
|
||||
elog(FATAL, "SetUserId: user \"%s\" is not in \"%s\"",
|
||||
userName,
|
||||
UserRelationName);
|
||||
UserId = (Oid) ((Form_pg_user) GETSTRUCT(userTup))->usesysid;
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user