1
0
mirror of https://github.com/postgres/postgres.git synced 2025-09-02 04:21:28 +03:00

pgindent run before 6.3 release, with Thomas' requested changes.

This commit is contained in:
Bruce Momjian
1998-02-26 04:46:47 +00:00
parent 757bf69a2e
commit a32450a585
430 changed files with 12390 additions and 10292 deletions

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.28 1998/01/31 04:38:17 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/async.c,v 1.29 1998/02/26 04:30:47 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -84,7 +84,7 @@
#include <libpq/libpq.h>
#ifndef HAVE_STRDUP
# include <port-protos.h> /* for strdup() */
#include <port-protos.h> /* for strdup() */
#endif
#include <storage/lmgr.h>
@@ -97,7 +97,7 @@ static Dllist *pendingNotifies = NULL;
static int AsyncExistsPendingNotify(char *);
static void ClearPendingNotify(void);
static void Async_NotifyFrontEnd(void);
void Async_Unlisten(char *relname, int pid);
void Async_Unlisten(char *relname, int pid);
static void Async_UnlistenOnExit(int code, char *relname);
/*
@@ -617,7 +617,7 @@ Async_NotifyFrontEnd()
if (whereToSendOutput == Remote)
{
pq_putnchar("A", 1);
pq_putint((int32)MyProcPid, sizeof(int32));
pq_putint((int32) MyProcPid, sizeof(int32));
pq_putstr(DatumGetName(d)->data);
pq_flush();
}

View File

@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.22 1998/01/10 05:19:03 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.23 1998/02/26 04:30:49 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -212,8 +212,8 @@ copy_heap(Oid OIDOldHeap)
OldHeapDesc = RelationGetTupleDescriptor(OldHeap);
/*
* Need to make a copy of the tuple descriptor, heap_create_with_catalog
* modifies it.
* Need to make a copy of the tuple descriptor,
* heap_create_with_catalog modifies it.
*/
tupdesc = CreateTupleDescCopy(OldHeapDesc);

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.25 1998/02/07 21:41:52 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.26 1998/02/26 04:30:49 momjian Exp $
*
* NOTES
* The PortalExecutorHeapMemory crap needs to be eliminated
@@ -97,10 +97,10 @@ PerformPortalFetch(char *name,
char *tag,
CommandDest dest)
{
Portal portal;
int feature;
QueryDesc *queryDesc;
MemoryContext context;
Portal portal;
int feature;
QueryDesc *queryDesc;
MemoryContext context;
/* ----------------
* sanity checks
@@ -148,16 +148,16 @@ PerformPortalFetch(char *name,
* ----------------
*/
queryDesc = PortalGetQueryDesc(portal);
if ( dest == None ) /* MOVE */
if (dest == None) /* MOVE */
{
QueryDesc *qdesc = (QueryDesc *) palloc (sizeof (QueryDesc));
memcpy (qdesc, queryDesc, sizeof (QueryDesc));
QueryDesc *qdesc = (QueryDesc *) palloc(sizeof(QueryDesc));
memcpy(qdesc, queryDesc, sizeof(QueryDesc));
qdesc->dest = dest;
queryDesc = qdesc;
}
BeginCommand(name,
queryDesc->operation,
portal->attinfo, /* QueryDescGetTypeInfo(queryDesc),
@@ -178,9 +178,9 @@ PerformPortalFetch(char *name,
ExecutorRun(queryDesc, PortalGetState(portal), feature, count);
if ( dest == None ) /* MOVE */
pfree (queryDesc);
if (dest == None) /* MOVE */
pfree(queryDesc);
/* ----------------
* Note: the "end-of-command" tag is returned by higher-level
* utility code

View File

@@ -6,7 +6,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.43 1998/02/25 13:06:08 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.44 1998/02/26 04:30:52 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -48,7 +48,8 @@ static Oid GetOutputFunction(Oid type);
static Oid GetTypeElement(Oid type);
static Oid GetInputFunction(Oid type);
static Oid IsTypeByVal(Oid type);
static void GetIndexRelations(Oid main_relation_oid,
static void
GetIndexRelations(Oid main_relation_oid,
int *n_indices,
Relation **index_rels);
@@ -64,7 +65,7 @@ static void CopyAttributeOut(FILE *fp, char *string, char *delim);
static int CountTuples(Relation relation);
extern FILE *Pfout,
*Pfin;
*Pfin;
static int lineno;
@@ -275,7 +276,7 @@ CopyTo(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
if (!isnull)
{
string = (char *) (*fmgr_faddr(&out_functions[i]))
(value, elements[i], typmod[i]);
(value, elements[i], typmod[i]);
CopyAttributeOut(fp, string, delim);
pfree(string);
}
@@ -582,8 +583,8 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
{
values[i] =
(Datum) (*fmgr_faddr(&in_functions[i])) (string,
elements[i],
typmod[i]);
elements[i],
typmod[i]);
/*
* Sanity check - by reference attributes cannot
@@ -592,7 +593,7 @@ CopyFrom(Relation rel, bool binary, bool oids, FILE *fp, char *delim)
if (!PointerIsValid(values[i]) &&
!(rel->rd_att->attrs[i]->attbyval))
{
elog(ERROR, "copy from line %d: Bad file format",lineno);
elog(ERROR, "copy from line %d: Bad file format", lineno);
}
}
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.25 1998/02/10 04:00:18 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.26 1998/02/26 04:30:55 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -58,7 +58,7 @@ DefineRelation(CreateStmt *stmt)
if (strlen(stmt->relname) >= NAMEDATALEN)
elog(ERROR, "the relation name %s is >= %d characters long", stmt->relname,
NAMEDATALEN);
StrNCpy(relname, stmt->relname, NAMEDATALEN); /* make full length for
StrNCpy(relname, stmt->relname, NAMEDATALEN); /* make full length for
* copy */
/* ----------------
@@ -253,7 +253,7 @@ MergeAttributes(List *schema, List *supers, List **supconstr)
if (relation == NULL)
{
elog(ERROR,
"MergeAttr: Can't inherit from non-existent superclass '%s'", name);
"MergeAttr: Can't inherit from non-existent superclass '%s'", name);
}
if (relation->rd_rel->relkind == 'S')
{
@@ -334,7 +334,8 @@ MergeAttributes(List *schema, List *supers, List **supconstr)
for (i = 0; i < constr->num_check; i++)
{
Constraint *cdef = (Constraint *) makeNode(Constraint); /* palloc(sizeof(Constraint)); */
Constraint *cdef = (Constraint *) makeNode(Constraint); /* palloc(sizeof(Constrai
* nt)); */
cdef->contype = CONSTR_CHECK;
if (check[i].ccname[0] == '$')

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.7 1998/02/25 13:06:09 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.8 1998/02/26 04:30:56 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -61,10 +61,10 @@ createdb(char *dbname, char *dbpath)
closeAllVfds();
/* Now create directory for this new database */
if ((dbpath != NULL) && (strcmp(dbpath,dbname) != 0))
if ((dbpath != NULL) && (strcmp(dbpath, dbname) != 0))
{
if (*(dbpath+strlen(dbpath)-1) == SEP_CHAR)
*(dbpath+strlen(dbpath)-1) = '\0';
if (*(dbpath + strlen(dbpath) - 1) == SEP_CHAR)
*(dbpath + strlen(dbpath) - 1) = '\0';
sprintf(loc, "%s%c%s", dbpath, SEP_CHAR, dbname);
}
else
@@ -75,12 +75,12 @@ createdb(char *dbname, char *dbpath)
lp = ExpandDatabasePath(loc);
if (lp == NULL)
elog(ERROR,"Unable to locate path '%s'"
"\n\tThis may be due to a missing environment variable"
" in the server",loc);
elog(ERROR, "Unable to locate path '%s'"
"\n\tThis may be due to a missing environment variable"
" in the server", loc);
if (mkdir(lp,S_IRWXU) != 0)
elog(ERROR,"Unable to create database directory %s",lp);
if (mkdir(lp, S_IRWXU) != 0)
elog(ERROR, "Unable to create database directory %s", lp);
sprintf(buf, "%s %s%cbase%ctemplate1%c* %s",
COPY_CMD, DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, lp);
@@ -93,7 +93,7 @@ createdb(char *dbname, char *dbpath)
#endif
sprintf(buf, "insert into pg_database (datname, datdba, datpath)"
" values (\'%s\', \'%d\', \'%s\');", dbname, user_id, loc);
" values (\'%s\', \'%d\', \'%s\');", dbname, user_id, loc);
pg_exec_query(buf, (char **) NULL, (Oid *) NULL, 0);
}
@@ -104,7 +104,7 @@ destroydb(char *dbname)
Oid user_id,
db_id;
char *path;
char dbpath[MAXPGPATH+1];
char dbpath[MAXPGPATH + 1];
char buf[512];
/*
@@ -122,10 +122,10 @@ destroydb(char *dbname)
stop_vacuum(dbpath, dbname);
path = ExpandDatabasePath(dbpath);
if (path == NULL)
elog(ERROR,"Unable to locate path '%s'"
"\n\tThis may be due to a missing environment variable"
" in the server",dbpath);
if (path == NULL)
elog(ERROR, "Unable to locate path '%s'"
"\n\tThis may be due to a missing environment variable"
" in the server", dbpath);
/*
* remove the pg_database tuple FIRST, this may fail due to
@@ -206,7 +206,7 @@ check_permissions(char *command,
bool use_super;
char *userName;
text *dbtext;
char path[MAXPGPATH+1];
char path[MAXPGPATH + 1];
userName = GetPgUserName();
utup = SearchSysCacheTuple(USENAME, PointerGetDatum(userName),
@@ -264,12 +264,12 @@ check_permissions(char *command,
(char *) NULL);
*dbIdP = dbtup->t_oid;
dbtext = (text *) heap_getattr(dbtup,
Anum_pg_database_datpath,
RelationGetTupleDescriptor(dbrel),
(char *) NULL);
Anum_pg_database_datpath,
RelationGetTupleDescriptor(dbrel),
(char *) NULL);
strncpy(path, VARDATA(dbtext), (VARSIZE(dbtext)-VARHDRSZ));
*(path+VARSIZE(dbtext)-VARHDRSZ) = '\0';
strncpy(path, VARDATA(dbtext), (VARSIZE(dbtext) - VARHDRSZ));
*(path + VARSIZE(dbtext) - VARHDRSZ) = '\0';
}
else
{
@@ -304,7 +304,7 @@ check_permissions(char *command,
if (dbfound && !strcmp(command, "destroydb"))
strcpy(dbpath, path);
} /* check_permissions() */
} /* check_permissions() */
/*
* stop_vacuum() -- stop the vacuum daemon on the database, if one is running.
@@ -319,7 +319,7 @@ stop_vacuum(char *dbpath, char *dbname)
if (strchr(dbpath, SEP_CHAR) != 0)
{
sprintf(filename, "%s%cbase%c%s%c%s.vacuum", DataDir, SEP_CHAR, SEP_CHAR,
dbname, SEP_CHAR, dbname);
dbname, SEP_CHAR, dbname);
}
else
{

View File

@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.23 1998/02/25 13:06:12 scrappy Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/define.c,v 1.24 1998/02/26 04:30:57 momjian Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
@@ -265,39 +265,42 @@ CreateFunction(ProcedureStmt *stmt, CommandDest dest)
}
else
{
HeapTuple languageTuple;
Form_pg_language languageStruct;
HeapTuple languageTuple;
Form_pg_language languageStruct;
/* Lookup the language in the system cache */
/* Lookup the language in the system cache */
languageTuple = SearchSysCacheTuple(LANNAME,
PointerGetDatum(languageName),
0, 0, 0);
if (!HeapTupleIsValid(languageTuple)) {
PointerGetDatum(languageName),
0, 0, 0);
elog(ERROR,
"Unrecognized language specified in a CREATE FUNCTION: "
"'%s'. Recognized languages are sql, C, internal "
"and the created procedural languages.",
languageName);
if (!HeapTupleIsValid(languageTuple))
{
elog(ERROR,
"Unrecognized language specified in a CREATE FUNCTION: "
"'%s'. Recognized languages are sql, C, internal "
"and the created procedural languages.",
languageName);
}
/* Check that this language is a PL */
languageStruct = (Form_pg_language) GETSTRUCT(languageTuple);
if (!(languageStruct->lanispl)) {
elog(ERROR,
"Language '%s' isn't defined as PL", languageName);
if (!(languageStruct->lanispl))
{
elog(ERROR,
"Language '%s' isn't defined as PL", languageName);
}
/*
* Functions in untrusted procedural languages are
* restricted to be defined by postgres superusers only
* Functions in untrusted procedural languages are restricted to
* be defined by postgres superusers only
*/
if (languageStruct->lanpltrusted == false && !superuser()) {
elog(ERROR, "Only users with Postgres superuser privilege "
"are permitted to create a function in the '%s' "
"language.",
languageName);
if (languageStruct->lanpltrusted == false && !superuser())
{
elog(ERROR, "Only users with Postgres superuser privilege "
"are permitted to create a function in the '%s' "
"language.",
languageName);
}
lanisPL = true;

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.17 1998/02/13 03:21:30 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.18 1998/02/26 04:30:58 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -204,23 +204,23 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
appendStringInfo(str, buf);
}
appendStringInfo(str, "\n");
/* initPlan-s */
if (plan->initPlan)
{
List *saved_rtable = es->rtable;
List *lst;
List *saved_rtable = es->rtable;
List *lst;
for (i = 0; i < indent; i++)
appendStringInfo(str, " ");
appendStringInfo(str, " InitPlan\n");
foreach (lst, plan->initPlan)
foreach(lst, plan->initPlan)
{
es->rtable = ((SubPlan*) lfirst(lst))->rtable;
es->rtable = ((SubPlan *) lfirst(lst))->rtable;
for (i = 0; i < indent; i++)
appendStringInfo(str, " ");
appendStringInfo(str, " -> ");
explain_outNode(str, ((SubPlan*) lfirst(lst))->plan, indent + 4, es);
explain_outNode(str, ((SubPlan *) lfirst(lst))->plan, indent + 4, es);
}
es->rtable = saved_rtable;
}
@@ -242,23 +242,23 @@ explain_outNode(StringInfo str, Plan *plan, int indent, ExplainState *es)
appendStringInfo(str, " -> ");
explain_outNode(str, innerPlan(plan), indent + 3, es);
}
/* subPlan-s */
if (plan->subPlan)
{
List *saved_rtable = es->rtable;
List *lst;
List *saved_rtable = es->rtable;
List *lst;
for (i = 0; i < indent; i++)
appendStringInfo(str, " ");
appendStringInfo(str, " SubPlan\n");
foreach (lst, plan->subPlan)
foreach(lst, plan->subPlan)
{
es->rtable = ((SubPlan*) lfirst(lst))->rtable;
es->rtable = ((SubPlan *) lfirst(lst))->rtable;
for (i = 0; i < indent; i++)
appendStringInfo(str, " ");
appendStringInfo(str, " -> ");
explain_outNode(str, ((SubPlan*) lfirst(lst))->plan, indent + 4, es);
explain_outNode(str, ((SubPlan *) lfirst(lst))->plan, indent + 4, es);
}
es->rtable = saved_rtable;
}

View File

@@ -43,7 +43,7 @@ case_translate_language_name(const char *input, char *output)
* ---------------------------------------------------------------------
*/
void
CreateProceduralLanguage(CreatePLangStmt * stmt)
CreateProceduralLanguage(CreatePLangStmt *stmt)
{
char languageName[NAMEDATALEN];
HeapTuple langTup;
@@ -139,7 +139,7 @@ CreateProceduralLanguage(CreatePLangStmt * stmt)
* ---------------------------------------------------------------------
*/
void
DropProceduralLanguage(DropPLangStmt * stmt)
DropProceduralLanguage(DropPLangStmt *stmt)
{
char languageName[NAMEDATALEN];
HeapTuple langTup;

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/recipe.c,v 1.19 1998/02/10 04:00:24 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/recipe.c,v 1.20 1998/02/26 04:30:59 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -493,9 +493,9 @@ tg_replaceNumberedParam(Node *expression,
{
newVar = makeVar(rt_ind,
0, /* the whole tuple */
TypeGet(teeRelName, &defined),
TypeGet(teeRelName, &defined),
-1,
0,
0,
rt_ind,
0);
return (Node *) newVar;
@@ -504,9 +504,9 @@ tg_replaceNumberedParam(Node *expression,
newVar = makeVar(rt_ind,
1, /* just the first field,
* which is 'result' */
TypeGet(teeRelName, &defined),
TypeGet(teeRelName, &defined),
-1,
0,
0,
rt_ind,
0);
return (Node *) newVar;
@@ -1052,7 +1052,7 @@ tg_parseSubQuery(TgRecipe * r, TgNode * n, TeeInfo * teeInfo)
tupdesc = rel->rd_att;
relid = heap_create_with_catalog(
child->nodeElem->outTypes->val[0], tupdesc);
child->nodeElem->outTypes->val[0], tupdesc);
}
else
{
@@ -1077,7 +1077,7 @@ tg_parseSubQuery(TgRecipe * r, TgNode * n, TeeInfo * teeInfo)
else
{
relid = heap_create_with_catalog(
child->nodeElem->outTypes->val[0], tupdesc);
child->nodeElem->outTypes->val[0], tupdesc);
}
}
}

View File

@@ -38,7 +38,7 @@ TriggerData *CurrentTriggerData = NULL;
void RelationBuildTriggers(Relation relation);
void FreeTriggerDesc(Relation relation);
static void DescribeTrigger(TriggerDesc * trigdesc, Trigger * trigger);
static void DescribeTrigger(TriggerDesc *trigdesc, Trigger *trigger);
static HeapTuple
GetTupleForTrigger(Relation relation, ItemPointer tid,
bool before);
@@ -46,7 +46,7 @@ GetTupleForTrigger(Relation relation, ItemPointer tid,
extern GlobalMemory CacheCxt;
void
CreateTrigger(CreateTrigStmt * stmt)
CreateTrigger(CreateTrigStmt *stmt)
{
int16 tgtype;
int16 tgattr[8] = {0};
@@ -249,7 +249,7 @@ CreateTrigger(CreateTrigStmt * stmt)
}
void
DropTrigger(DropTrigStmt * stmt)
DropTrigger(DropTrigStmt *stmt)
{
Relation rel;
Relation tgrel;
@@ -519,7 +519,7 @@ FreeTriggerDesc(Relation relation)
}
static void
DescribeTrigger(TriggerDesc * trigdesc, Trigger * trigger)
DescribeTrigger(TriggerDesc *trigdesc, Trigger *trigger)
{
uint16 *n;
Trigger ***t,
@@ -593,7 +593,7 @@ DescribeTrigger(TriggerDesc * trigdesc, Trigger * trigger)
}
static HeapTuple
ExecCallTriggerFunc(Trigger * trigger)
ExecCallTriggerFunc(Trigger *trigger)
{
if (trigger->tgfunc.fn_addr == NULL)
@@ -601,9 +601,10 @@ ExecCallTriggerFunc(Trigger * trigger)
fmgr_info(trigger->tgfoid, &trigger->tgfunc);
}
if (trigger->tgfunc.fn_plhandler != NULL) {
if (trigger->tgfunc.fn_plhandler != NULL)
{
return (HeapTuple) (*(trigger->tgfunc.fn_plhandler))
(&trigger->tgfunc);
(&trigger->tgfunc);
}
return (HeapTuple) ((*fmgr_faddr(&trigger->tgfunc)) ());

View File

@@ -43,34 +43,39 @@ static void CheckPgUserAclNotNull(void);
*---------------------------------------------------------------------
*/
static
void UpdatePgPwdFile(char* sql) {
void
UpdatePgPwdFile(char *sql)
{
char* filename;
char* tempname;
char *filename;
char *tempname;
/* Create a temporary filename to be renamed later. This prevents the
* backend from clobbering the pg_pwd file while the postmaster might be
* reading from it.
*/
filename = crypt_getpwdfilename();
tempname = (char*)malloc(strlen(filename) + 12);
sprintf(tempname, "%s.%d", filename, MyProcPid);
/*
* Create a temporary filename to be renamed later. This prevents the
* backend from clobbering the pg_pwd file while the postmaster might
* be reading from it.
*/
filename = crypt_getpwdfilename();
tempname = (char *) malloc(strlen(filename) + 12);
sprintf(tempname, "%s.%d", filename, MyProcPid);
/* Copy the contents of pg_shadow to the pg_pwd ASCII file using a the SEPCHAR
* character as the delimiter between fields. Then rename the file to its
* final name.
*/
sprintf(sql, "copy %s to '%s' using delimiters %s", ShadowRelationName, tempname, CRYPT_PWD_FILE_SEPCHAR);
pg_exec_query(sql, (char**)NULL, (Oid*)NULL, 0);
rename(tempname, filename);
free((void*)tempname);
/*
* Copy the contents of pg_shadow to the pg_pwd ASCII file using a the
* SEPCHAR character as the delimiter between fields. Then rename the
* file to its final name.
*/
sprintf(sql, "copy %s to '%s' using delimiters %s", ShadowRelationName, tempname, CRYPT_PWD_FILE_SEPCHAR);
pg_exec_query(sql, (char **) NULL, (Oid *) NULL, 0);
rename(tempname, filename);
free((void *) tempname);
/* Create a flag file the postmaster will detect the next time it tries to
* authenticate a user. The postmaster will know to reload the pg_pwd file
* contents.
*/
filename = crypt_getpwdreloadfilename();
creat(filename, S_IRUSR | S_IWUSR);
/*
* Create a flag file the postmaster will detect the next time it
* tries to authenticate a user. The postmaster will know to reload
* the pg_pwd file contents.
*/
filename = crypt_getpwdreloadfilename();
creat(filename, S_IRUSR | S_IWUSR);
}
/*---------------------------------------------------------------------
@@ -80,352 +85,407 @@ void UpdatePgPwdFile(char* sql) {
* user is specified in the desired groups of defined in pg_group.
*---------------------------------------------------------------------
*/
void DefineUser(CreateUserStmt *stmt) {
void
DefineUser(CreateUserStmt *stmt)
{
char* pg_user;
Relation pg_shadow_rel;
TupleDesc pg_shadow_dsc;
HeapScanDesc scan;
HeapTuple tuple;
Datum datum;
Buffer buffer;
char sql[512];
char* sql_end;
bool exists = false,
n,
inblock;
int max_id = -1;
char *pg_user;
Relation pg_shadow_rel;
TupleDesc pg_shadow_dsc;
HeapScanDesc scan;
HeapTuple tuple;
Datum datum;
Buffer buffer;
char sql[512];
char *sql_end;
bool exists = false,
n,
inblock;
int max_id = -1;
if (stmt->password)
CheckPgUserAclNotNull();
if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock();
if (stmt->password)
CheckPgUserAclNotNull();
if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock();
/* Make sure the user attempting to create a user can insert into the pg_shadow
* relation.
*/
pg_user = GetPgUserName();
if (pg_aclcheck(ShadowRelationName, pg_user, ACL_RD | ACL_WR | ACL_AP) != ACLCHECK_OK) {
UserAbortTransactionBlock();
elog(ERROR, "defineUser: user \"%s\" does not have SELECT and INSERT privilege for \"%s\"",
pg_user, ShadowRelationName);
return;
}
/*
* Make sure the user attempting to create a user can insert into the
* pg_shadow relation.
*/
pg_user = GetPgUserName();
if (pg_aclcheck(ShadowRelationName, pg_user, ACL_RD | ACL_WR | ACL_AP) != ACLCHECK_OK)
{
UserAbortTransactionBlock();
elog(ERROR, "defineUser: user \"%s\" does not have SELECT and INSERT privilege for \"%s\"",
pg_user, ShadowRelationName);
return;
}
/* Scan the pg_shadow relation to be certain the user doesn't already exist.
*/
pg_shadow_rel = heap_openr(ShadowRelationName);
pg_shadow_dsc = RelationGetTupleDescriptor(pg_shadow_rel);
/* Secure a write lock on pg_shadow so we can be sure of what the next usesysid
* should be.
*/
RelationSetLockForWrite(pg_shadow_rel);
/*
* Scan the pg_shadow relation to be certain the user doesn't already
* exist.
*/
pg_shadow_rel = heap_openr(ShadowRelationName);
pg_shadow_dsc = RelationGetTupleDescriptor(pg_shadow_rel);
scan = heap_beginscan(pg_shadow_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) {
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n);
/*
* Secure a write lock on pg_shadow so we can be sure of what the next
* usesysid should be.
*/
RelationSetLockForWrite(pg_shadow_rel);
if (!exists && !strncmp((char*)datum, stmt->user, strlen(stmt->user)))
exists = true;
scan = heap_beginscan(pg_shadow_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
{
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n);
datum = heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_shadow_dsc, &n);
if ((int)datum > max_id)
max_id = (int)datum;
if (!exists && !strncmp((char *) datum, stmt->user, strlen(stmt->user)))
exists = true;
ReleaseBuffer(buffer);
}
heap_endscan(scan);
datum = heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_shadow_dsc, &n);
if ((int) datum > max_id)
max_id = (int) datum;
if (exists) {
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UserAbortTransactionBlock();
elog(ERROR, "defineUser: user \"%s\" has already been created", stmt->user);
return;
}
ReleaseBuffer(buffer);
}
heap_endscan(scan);
/* Build the insert statment to be executed.
*/
sprintf(sql, "insert into %s(usename,usesysid,usecreatedb,usetrace,usesuper,usecatupd,passwd", ShadowRelationName);
/* if (stmt->password)
strcat(sql, ",passwd"); -- removed so that insert empty string when no password */
if (stmt->validUntil)
strcat(sql, ",valuntil");
if (exists)
{
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UserAbortTransactionBlock();
elog(ERROR, "defineUser: user \"%s\" has already been created", stmt->user);
return;
}
sql_end = sql + strlen(sql);
sprintf(sql_end, ") values('%s',%d", stmt->user, max_id + 1);
if (stmt->createdb && *stmt->createdb)
strcat(sql_end, ",'t','t'");
else
strcat(sql_end, ",'f','t'");
if (stmt->createuser && *stmt->createuser)
strcat(sql_end, ",'t','t'");
else
strcat(sql_end, ",'f','t'");
sql_end += strlen(sql_end);
if (stmt->password) {
sprintf(sql_end, ",'%s'", stmt->password);
sql_end += strlen(sql_end);
} else {
strcpy(sql_end, ",''");
sql_end += strlen(sql_end);
}
if (stmt->validUntil) {
sprintf(sql_end, ",'%s'", stmt->validUntil);
sql_end += strlen(sql_end);
}
strcat(sql_end, ")");
/*
* Build the insert statment to be executed.
*/
sprintf(sql, "insert into %s(usename,usesysid,usecreatedb,usetrace,usesuper,usecatupd,passwd", ShadowRelationName);
/* if (stmt->password)
strcat(sql, ",passwd"); -- removed so that insert empty string when no password */
if (stmt->validUntil)
strcat(sql, ",valuntil");
pg_exec_query(sql, (char**)NULL, (Oid*)NULL, 0);
sql_end = sql + strlen(sql);
sprintf(sql_end, ") values('%s',%d", stmt->user, max_id + 1);
if (stmt->createdb && *stmt->createdb)
strcat(sql_end, ",'t','t'");
else
strcat(sql_end, ",'f','t'");
if (stmt->createuser && *stmt->createuser)
strcat(sql_end, ",'t','t'");
else
strcat(sql_end, ",'f','t'");
sql_end += strlen(sql_end);
if (stmt->password)
{
sprintf(sql_end, ",'%s'", stmt->password);
sql_end += strlen(sql_end);
}
else
{
strcpy(sql_end, ",''");
sql_end += strlen(sql_end);
}
if (stmt->validUntil)
{
sprintf(sql_end, ",'%s'", stmt->validUntil);
sql_end += strlen(sql_end);
}
strcat(sql_end, ")");
/* Add the stuff here for groups.
*/
pg_exec_query(sql, (char **) NULL, (Oid *) NULL, 0);
UpdatePgPwdFile(sql);
/*
* Add the stuff here for groups.
*/
/* This goes after the UpdatePgPwdFile to be certain that two backends to not
* attempt to write to the pg_pwd file at the same time.
*/
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UpdatePgPwdFile(sql);
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
/*
* This goes after the UpdatePgPwdFile to be certain that two backends
* to not attempt to write to the pg_pwd file at the same time.
*/
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
}
extern void AlterUser(AlterUserStmt *stmt) {
extern void
AlterUser(AlterUserStmt *stmt)
{
char* pg_user;
Relation pg_shadow_rel;
TupleDesc pg_shadow_dsc;
HeapScanDesc scan;
HeapTuple tuple;
Datum datum;
Buffer buffer;
char sql[512];
char* sql_end;
bool exists = false,
n,
inblock;
char *pg_user;
Relation pg_shadow_rel;
TupleDesc pg_shadow_dsc;
HeapScanDesc scan;
HeapTuple tuple;
Datum datum;
Buffer buffer;
char sql[512];
char *sql_end;
bool exists = false,
n,
inblock;
if (stmt->password)
CheckPgUserAclNotNull();
if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock();
if (stmt->password)
CheckPgUserAclNotNull();
if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock();
/* Make sure the user attempting to create a user can insert into the pg_shadow
* relation.
*/
pg_user = GetPgUserName();
if (pg_aclcheck(ShadowRelationName, pg_user, ACL_RD | ACL_WR) != ACLCHECK_OK) {
UserAbortTransactionBlock();
elog(ERROR, "alterUser: user \"%s\" does not have SELECT and UPDATE privilege for \"%s\"",
pg_user, ShadowRelationName);
return;
}
/*
* Make sure the user attempting to create a user can insert into the
* pg_shadow relation.
*/
pg_user = GetPgUserName();
if (pg_aclcheck(ShadowRelationName, pg_user, ACL_RD | ACL_WR) != ACLCHECK_OK)
{
UserAbortTransactionBlock();
elog(ERROR, "alterUser: user \"%s\" does not have SELECT and UPDATE privilege for \"%s\"",
pg_user, ShadowRelationName);
return;
}
/* Scan the pg_shadow relation to be certain the user exists.
*/
pg_shadow_rel = heap_openr(ShadowRelationName);
pg_shadow_dsc = RelationGetTupleDescriptor(pg_shadow_rel);
/* Secure a write lock on pg_shadow so we can be sure that when the dump of
* the pg_pwd file is done, there is not another backend doing the same.
*/
RelationSetLockForWrite(pg_shadow_rel);
/*
* Scan the pg_shadow relation to be certain the user exists.
*/
pg_shadow_rel = heap_openr(ShadowRelationName);
pg_shadow_dsc = RelationGetTupleDescriptor(pg_shadow_rel);
scan = heap_beginscan(pg_shadow_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) {
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n);
/*
* Secure a write lock on pg_shadow so we can be sure that when the
* dump of the pg_pwd file is done, there is not another backend doing
* the same.
*/
RelationSetLockForWrite(pg_shadow_rel);
if (!strncmp((char*)datum, stmt->user, strlen(stmt->user))) {
exists = true;
ReleaseBuffer(buffer);
break;
}
}
heap_endscan(scan);
scan = heap_beginscan(pg_shadow_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
{
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_shadow_dsc, &n);
if (!exists) {
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UserAbortTransactionBlock();
elog(ERROR, "alterUser: user \"%s\" does not exist", stmt->user);
return;
}
if (!strncmp((char *) datum, stmt->user, strlen(stmt->user)))
{
exists = true;
ReleaseBuffer(buffer);
break;
}
}
heap_endscan(scan);
/* Create the update statement to modify the user.
*/
sprintf(sql, "update %s set", ShadowRelationName);
sql_end = sql;
if (stmt->password) {
sql_end += strlen(sql_end);
sprintf(sql_end, " passwd = '%s'", stmt->password);
}
if (stmt->createdb) {
if (sql_end != sql)
strcat(sql_end, ",");
sql_end += strlen(sql_end);
if (*stmt->createdb)
strcat(sql_end, " usecreatedb = 't'");
else
strcat(sql_end, " usecreatedb = 'f'");
}
if (stmt->createuser) {
if (sql_end != sql)
strcat(sql_end, ",");
sql_end += strlen(sql_end);
if (*stmt->createuser)
strcat(sql_end, " usesuper = 't'");
else
strcat(sql_end, " usesuper = 'f'");
}
if (stmt->validUntil) {
if (sql_end != sql)
strcat(sql_end, ",");
sql_end += strlen(sql_end);
sprintf(sql_end, " valuntil = '%s'", stmt->validUntil);
}
if (sql_end != sql) {
sql_end += strlen(sql_end);
sprintf(sql_end, " where usename = '%s'", stmt->user);
pg_exec_query(sql, (char**)NULL, (Oid*)NULL, 0);
}
if (!exists)
{
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UserAbortTransactionBlock();
elog(ERROR, "alterUser: user \"%s\" does not exist", stmt->user);
return;
}
/* do the pg_group stuff here */
/*
* Create the update statement to modify the user.
*/
sprintf(sql, "update %s set", ShadowRelationName);
sql_end = sql;
if (stmt->password)
{
sql_end += strlen(sql_end);
sprintf(sql_end, " passwd = '%s'", stmt->password);
}
if (stmt->createdb)
{
if (sql_end != sql)
strcat(sql_end, ",");
sql_end += strlen(sql_end);
if (*stmt->createdb)
strcat(sql_end, " usecreatedb = 't'");
else
strcat(sql_end, " usecreatedb = 'f'");
}
if (stmt->createuser)
{
if (sql_end != sql)
strcat(sql_end, ",");
sql_end += strlen(sql_end);
if (*stmt->createuser)
strcat(sql_end, " usesuper = 't'");
else
strcat(sql_end, " usesuper = 'f'");
}
if (stmt->validUntil)
{
if (sql_end != sql)
strcat(sql_end, ",");
sql_end += strlen(sql_end);
sprintf(sql_end, " valuntil = '%s'", stmt->validUntil);
}
if (sql_end != sql)
{
sql_end += strlen(sql_end);
sprintf(sql_end, " where usename = '%s'", stmt->user);
pg_exec_query(sql, (char **) NULL, (Oid *) NULL, 0);
}
UpdatePgPwdFile(sql);
/* do the pg_group stuff here */
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UpdatePgPwdFile(sql);
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
}
extern void RemoveUser(char* user) {
extern void
RemoveUser(char *user)
{
char* pg_user;
Relation pg_shadow_rel,
pg_rel;
TupleDesc pg_dsc;
HeapScanDesc scan;
HeapTuple tuple;
Datum datum;
Buffer buffer;
char sql[512];
bool n,
inblock;
int usesysid = -1,
ndbase = 0;
char** dbase = NULL;
char *pg_user;
Relation pg_shadow_rel,
pg_rel;
TupleDesc pg_dsc;
HeapScanDesc scan;
HeapTuple tuple;
Datum datum;
Buffer buffer;
char sql[512];
bool n,
inblock;
int usesysid = -1,
ndbase = 0;
char **dbase = NULL;
if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock();
if (!(inblock = IsTransactionBlock()))
BeginTransactionBlock();
/* Make sure the user attempting to create a user can delete from the pg_shadow
* relation.
*/
pg_user = GetPgUserName();
if (pg_aclcheck(ShadowRelationName, pg_user, ACL_RD | ACL_WR) != ACLCHECK_OK) {
UserAbortTransactionBlock();
elog(ERROR, "removeUser: user \"%s\" does not have SELECT and DELETE privilege for \"%s\"",
pg_user, ShadowRelationName);
return;
}
/*
* Make sure the user attempting to create a user can delete from the
* pg_shadow relation.
*/
pg_user = GetPgUserName();
if (pg_aclcheck(ShadowRelationName, pg_user, ACL_RD | ACL_WR) != ACLCHECK_OK)
{
UserAbortTransactionBlock();
elog(ERROR, "removeUser: user \"%s\" does not have SELECT and DELETE privilege for \"%s\"",
pg_user, ShadowRelationName);
return;
}
/* Perform a scan of the pg_shadow relation to find the usesysid of the user to
* be deleted. If it is not found, then return a warning message.
*/
pg_shadow_rel = heap_openr(ShadowRelationName);
pg_dsc = RelationGetTupleDescriptor(pg_shadow_rel);
/* Secure a write lock on pg_shadow so we can be sure that when the dump of
* the pg_pwd file is done, there is not another backend doing the same.
*/
RelationSetLockForWrite(pg_shadow_rel);
/*
* Perform a scan of the pg_shadow relation to find the usesysid of
* the user to be deleted. If it is not found, then return a warning
* message.
*/
pg_shadow_rel = heap_openr(ShadowRelationName);
pg_dsc = RelationGetTupleDescriptor(pg_shadow_rel);
scan = heap_beginscan(pg_shadow_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) {
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_dsc, &n);
/*
* Secure a write lock on pg_shadow so we can be sure that when the
* dump of the pg_pwd file is done, there is not another backend doing
* the same.
*/
RelationSetLockForWrite(pg_shadow_rel);
if (!strncmp((char*)datum, user, strlen(user))) {
usesysid = (int)heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_dsc, &n);
ReleaseBuffer(buffer);
break;
}
ReleaseBuffer(buffer);
}
heap_endscan(scan);
scan = heap_beginscan(pg_shadow_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
{
datum = heap_getattr(tuple, Anum_pg_shadow_usename, pg_dsc, &n);
if (usesysid == -1) {
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UserAbortTransactionBlock();
elog(ERROR, "removeUser: user \"%s\" does not exist", user);
return;
}
if (!strncmp((char *) datum, user, strlen(user)))
{
usesysid = (int) heap_getattr(tuple, Anum_pg_shadow_usesysid, pg_dsc, &n);
ReleaseBuffer(buffer);
break;
}
ReleaseBuffer(buffer);
}
heap_endscan(scan);
/* Perform a scan of the pg_database relation to find the databases owned by
* usesysid. Then drop them.
*/
pg_rel = heap_openr(DatabaseRelationName);
pg_dsc = RelationGetTupleDescriptor(pg_rel);
if (usesysid == -1)
{
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UserAbortTransactionBlock();
elog(ERROR, "removeUser: user \"%s\" does not exist", user);
return;
}
scan = heap_beginscan(pg_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer))) {
datum = heap_getattr(tuple, Anum_pg_database_datdba, pg_dsc, &n);
/*
* Perform a scan of the pg_database relation to find the databases
* owned by usesysid. Then drop them.
*/
pg_rel = heap_openr(DatabaseRelationName);
pg_dsc = RelationGetTupleDescriptor(pg_rel);
if ((int)datum == usesysid) {
datum = heap_getattr(tuple, Anum_pg_database_datname, pg_dsc, &n);
if (memcmp((void*)datum, "template1", 9)) {
dbase = (char**)realloc((void*)dbase, sizeof(char*) * (ndbase + 1));
dbase[ndbase] = (char*)malloc(NAMEDATALEN + 1);
memcpy((void*)dbase[ndbase], (void*)datum, NAMEDATALEN);
dbase[ndbase++][NAMEDATALEN] = '\0';
}
}
ReleaseBuffer(buffer);
}
heap_endscan(scan);
heap_close(pg_rel);
scan = heap_beginscan(pg_rel, false, false, 0, NULL);
while (HeapTupleIsValid(tuple = heap_getnext(scan, 0, &buffer)))
{
datum = heap_getattr(tuple, Anum_pg_database_datdba, pg_dsc, &n);
while (ndbase--) {
elog(NOTICE, "Dropping database %s", dbase[ndbase]);
sprintf(sql, "drop database %s", dbase[ndbase]);
free((void*)dbase[ndbase]);
pg_exec_query(sql, (char**)NULL, (Oid*)NULL, 0);
}
if (dbase)
free((void*)dbase);
if ((int) datum == usesysid)
{
datum = heap_getattr(tuple, Anum_pg_database_datname, pg_dsc, &n);
if (memcmp((void *) datum, "template1", 9))
{
dbase = (char **) realloc((void *) dbase, sizeof(char *) * (ndbase + 1));
dbase[ndbase] = (char *) malloc(NAMEDATALEN + 1);
memcpy((void *) dbase[ndbase], (void *) datum, NAMEDATALEN);
dbase[ndbase++][NAMEDATALEN] = '\0';
}
}
ReleaseBuffer(buffer);
}
heap_endscan(scan);
heap_close(pg_rel);
/* Since pg_shadow is global over all databases, one of two things must be done
* to insure complete consistency. First, pg_shadow could be made non-global.
* This would elminate the code above for deleting database and would require
* the addition of code to delete tables, views, etc owned by the user.
*
* The second option would be to create a means of deleting tables, view,
* etc. owned by the user from other databases. Pg_user is global and so
* this must be done at some point.
*
* Let us not forget that the user should be removed from the pg_groups also.
*
* Todd A. Brandys 11/18/1997
*
*/
while (ndbase--)
{
elog(NOTICE, "Dropping database %s", dbase[ndbase]);
sprintf(sql, "drop database %s", dbase[ndbase]);
free((void *) dbase[ndbase]);
pg_exec_query(sql, (char **) NULL, (Oid *) NULL, 0);
}
if (dbase)
free((void *) dbase);
/* Remove the user from the pg_shadow table
*/
sprintf(sql, "delete from %s where usename = '%s'", ShadowRelationName, user);
pg_exec_query(sql, (char**)NULL, (Oid*)NULL, 0);
/*
* Since pg_shadow is global over all databases, one of two things
* must be done to insure complete consistency. First, pg_shadow
* could be made non-global. This would elminate the code above for
* deleting database and would require the addition of code to delete
* tables, views, etc owned by the user.
*
* The second option would be to create a means of deleting tables, view,
* etc. owned by the user from other databases. Pg_user is global and
* so this must be done at some point.
*
* Let us not forget that the user should be removed from the pg_groups
* also.
*
* Todd A. Brandys 11/18/1997
*
*/
UpdatePgPwdFile(sql);
/*
* Remove the user from the pg_shadow table
*/
sprintf(sql, "delete from %s where usename = '%s'", ShadowRelationName, user);
pg_exec_query(sql, (char **) NULL, (Oid *) NULL, 0);
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
UpdatePgPwdFile(sql);
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
RelationUnsetLockForWrite(pg_shadow_rel);
heap_close(pg_shadow_rel);
if (IsTransactionBlock() && !inblock)
EndTransactionBlock();
}
/*
@@ -433,9 +493,10 @@ extern void RemoveUser(char* user) {
*
* check to see if there is an ACL on pg_shadow
*/
static void CheckPgUserAclNotNull()
static void
CheckPgUserAclNotNull()
{
HeapTuple htp;
HeapTuple htp;
htp = SearchSysCacheTuple(RELNAME, PointerGetDatum(ShadowRelationName),
0, 0, 0);
@@ -451,6 +512,6 @@ HeapTuple htp;
elog(NOTICE, "so normal users can not read the passwords.");
elog(ERROR, "Try 'REVOKE ALL ON pg_shadow FROM PUBLIC'");
}
return;
}

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.62 1998/02/25 23:40:32 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.63 1998/02/26 04:31:03 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -54,9 +54,9 @@
#include <sys/resource.h>
#endif
/* #include <port-protos.h> */ /* Why? */
/* #include <port-protos.h> *//* Why? */
extern int BlowawayRelationBuffers(Relation rdesc, BlockNumber block);
extern int BlowawayRelationBuffers(Relation rdesc, BlockNumber block);
bool VacuumRunning = false;
@@ -136,7 +136,7 @@ vacuum(char *vacrel, bool verbose, bool analyze, List *va_spec)
old = MemoryContextSwitchTo((MemoryContext) pmem);
if (va_spec != NIL && !analyze)
elog(ERROR,"Can't vacuum columns, only tables. You can 'vacuum analyze' columns.");
elog(ERROR, "Can't vacuum columns, only tables. You can 'vacuum analyze' columns.");
foreach(le, va_spec)
{
@@ -725,8 +725,9 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
}
else if (!TransactionIdIsInProgress(htup->t_xmin))
{
/*
* Not Aborted, Not Committed, Not in Progress -
* Not Aborted, Not Committed, Not in Progress -
* so it's from crashed process. - vadim 11/26/96
*/
ncrash++;
@@ -741,11 +742,11 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
}
}
/*
* here we are concerned about tuples with xmin committed
* and xmax unknown or committed
/*
* here we are concerned about tuples with xmin committed and
* xmax unknown or committed
*/
if (htup->t_infomask & HEAP_XMIN_COMMITTED &&
if (htup->t_infomask & HEAP_XMIN_COMMITTED &&
!(htup->t_infomask & HEAP_XMAX_INVALID))
{
if (htup->t_infomask & HEAP_XMAX_COMMITTED)
@@ -759,6 +760,7 @@ vc_scanheap(VRelStats *vacrelstats, Relation onerel,
tupgone = true;
else if (!TransactionIdIsInProgress(htup->t_xmax))
{
/*
* Not Aborted, Not Committed, Not in Progress - so it
* from crashed process. - vadim 06/02/97
@@ -916,7 +918,7 @@ Tup %u: Vac %u, Crash %u, UnUsed %u, MinLen %u, MaxLen %u; Re-using: Free/Avail.
ru1.ru_stime.tv_sec - ru0.ru_stime.tv_sec,
ru1.ru_utime.tv_sec - ru0.ru_utime.tv_sec);
} /* vc_scanheap */
} /* vc_scanheap */
/*
@@ -1087,15 +1089,15 @@ vc_rpfheap(VRelStats *vacrelstats, Relation onerel,
* But we can't remove last page - this is our
* "show-stopper" !!! - vadim 02/25/98
*/
if (ToVpd != Fvplast &&
if (ToVpd != Fvplast &&
!vc_enough_space(ToVpd, vacrelstats->min_tlen))
{
Assert(Fnpages > ToVpI + 1);
memmove(Fvpl->vpl_pgdesc + ToVpI,
Fvpl->vpl_pgdesc + ToVpI + 1,
sizeof(VPageDescr *) * (Fnpages - ToVpI - 1));
sizeof(VPageDescr *) * (Fnpages - ToVpI - 1));
Fnpages--;
Assert (Fvplast == Fvpl->vpl_pgdesc[Fnpages - 1]);
Assert(Fvplast == Fvpl->vpl_pgdesc[Fnpages - 1]);
}
}
for (i = 0; i < Fnpages; i++)
@@ -1333,7 +1335,7 @@ Elapsed %u/%u sec.",
{
i = BlowawayRelationBuffers(onerel, blkno);
if (i < 0)
elog (FATAL, "VACUUM (vc_rpfheap): BlowawayRelationBuffers returned %d", i);
elog(FATAL, "VACUUM (vc_rpfheap): BlowawayRelationBuffers returned %d", i);
blkno = smgrtruncate(DEFAULT_SMGR, onerel, blkno);
Assert(blkno >= 0);
vacrelstats->npages = blkno; /* set new number of blocks */
@@ -1349,7 +1351,7 @@ Elapsed %u/%u sec.",
pfree(vpc);
} /* vc_rpfheap */
} /* vc_rpfheap */
/*
* vc_vacheap() -- free dead tuples
@@ -1367,7 +1369,7 @@ vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList Vvpl)
int i;
nblocks = Vvpl->vpl_npages;
nblocks -= Vvpl->vpl_nemend; /* nothing to do with them */
nblocks -= Vvpl->vpl_nemend;/* nothing to do with them */
for (i = 0, vpp = Vvpl->vpl_pgdesc; i < nblocks; i++, vpp++)
{
@@ -1394,17 +1396,17 @@ vc_vacheap(VRelStats *vacrelstats, Relation onerel, VPageList Vvpl)
* it) before truncation
*/
FlushBufferPool(!TransactionFlushEnabled());
i = BlowawayRelationBuffers(onerel, nblocks);
if (i < 0)
elog (FATAL, "VACUUM (vc_vacheap): BlowawayRelationBuffers returned %d", i);
elog(FATAL, "VACUUM (vc_vacheap): BlowawayRelationBuffers returned %d", i);
nblocks = smgrtruncate(DEFAULT_SMGR, onerel, nblocks);
Assert(nblocks >= 0);
vacrelstats->npages = nblocks; /* set new number of blocks */
}
} /* vc_vacheap */
} /* vc_vacheap */
/*
* vc_vacpage() -- free dead tuples on a page
@@ -1424,7 +1426,7 @@ vc_vacpage(Page page, VPageDescr vpd)
}
PageRepairFragmentation(page);
} /* vc_vacpage */
} /* vc_vacpage */
/*
* _vc_scanoneind() -- scan one index relation to update statistic.
@@ -1470,7 +1472,7 @@ vc_scanoneind(Relation indrel, int nhtups)
elog(NOTICE, "Ind %s: NUMBER OF INDEX' TUPLES (%u) IS NOT THE SAME AS HEAP' (%u)",
indrel->rd_rel->relname.data, nitups, nhtups);
} /* vc_scanoneind */
} /* vc_scanoneind */
/*
* vc_vaconeind() -- vacuum one index relation.
@@ -1553,7 +1555,7 @@ vc_vaconeind(VPageList vpl, Relation indrel, int nhtups)
elog(NOTICE, "Ind %s: NUMBER OF INDEX' TUPLES (%u) IS NOT THE SAME AS HEAP' (%u)",
indrel->rd_rel->relname.data, nitups, nhtups);
} /* vc_vaconeind */
} /* vc_vaconeind */
/*
* vc_tidreapped() -- is a particular tid reapped?
@@ -1597,7 +1599,7 @@ vc_tidreapped(ItemPointer itemptr, VPageList vpl)
return (vp);
} /* vc_tidreapped */
} /* vc_tidreapped */
/*
* vc_attrstats() -- compute column statistics used by the optimzer
@@ -2011,7 +2013,7 @@ vc_reappage(VPageList vpl, VPageDescr vpc)
/* insert this page into vpl list */
vc_vpinsert(vpl, newvpd);
} /* vc_reappage */
} /* vc_reappage */
static void
vc_vpinsert(VPageList vpl, VPageDescr vpnew)
@@ -2101,7 +2103,7 @@ vc_find_eq(char *bot, int nelem, int size, char *elm, int (*compar) (char *, cha
first_move = true;
}
} /* vc_find_eq */
} /* vc_find_eq */
static int
vc_cmp_blk(char *left, char *right)
@@ -2118,7 +2120,7 @@ vc_cmp_blk(char *left, char *right)
return (0);
return (1);
} /* vc_cmp_blk */
} /* vc_cmp_blk */
static int
vc_cmp_offno(char *left, char *right)
@@ -2130,7 +2132,7 @@ vc_cmp_offno(char *left, char *right)
return (0);
return (1);
} /* vc_cmp_offno */
} /* vc_cmp_offno */
static void
@@ -2207,7 +2209,7 @@ vc_getindices(Oid relid, int *nindices, Relation **Irel)
*Irel = (Relation *) NULL;
}
} /* vc_getindices */
} /* vc_getindices */
static void
@@ -2223,7 +2225,7 @@ vc_clsindices(int nindices, Relation *Irel)
}
pfree(Irel);
} /* vc_clsindices */
} /* vc_clsindices */
static void
@@ -2262,7 +2264,7 @@ vc_mkindesc(Relation onerel, int nindices, Relation *Irel, IndDesc **Idesc)
idcur->natts = natts;
}
} /* vc_mkindesc */
} /* vc_mkindesc */
static bool
@@ -2283,4 +2285,4 @@ vc_enough_space(VPageDescr vpd, Size len)
return (false);
} /* vc_enough_space */
} /* vc_enough_space */

View File

@@ -1,8 +1,8 @@
/*
* Routines for handling of 'SET var TO',
* 'SHOW var' and 'RESET var' statements.
* 'SHOW var' and 'RESET var' statements.
*
* $Id: variable.c,v 1.3 1998/02/03 16:06:49 thomas Exp $
* $Id: variable.c,v 1.4 1998/02/26 04:31:05 momjian Exp $
*
*/
@@ -61,7 +61,7 @@ get_token(char **tok, char **val, const char *str)
}
*tok = (char *) palloc(len + 1);
StrNCpy(*tok, start, len+1);
StrNCpy(*tok, start, len + 1);
/* skip white spaces */
while (isspace(*str))
@@ -107,7 +107,7 @@ get_token(char **tok, char **val, const char *str)
}
*val = (char *) palloc(len + 1);
StrNCpy(*val, start, len+1);
StrNCpy(*val, start, len + 1);
/* skip white spaces */
while (isspace(*str))
@@ -342,18 +342,21 @@ parse_date(const char *value)
DateStyle = USE_GERMAN_DATES;
dcnt++;
EuroDates = TRUE;
if ((ecnt > 0) && (! EuroDates)) ecnt++;
if ((ecnt > 0) && (!EuroDates))
ecnt++;
}
else if (!strncasecmp(tok, "EURO", 4))
{
EuroDates = TRUE;
if ((dcnt <= 0) || (DateStyle != USE_GERMAN_DATES)) ecnt++;
if ((dcnt <= 0) || (DateStyle != USE_GERMAN_DATES))
ecnt++;
}
else if ((!strcasecmp(tok, "US"))
|| (!strncasecmp(tok, "NONEURO", 7)))
{
EuroDates = FALSE;
if ((dcnt <= 0) || (DateStyle == USE_GERMAN_DATES)) ecnt++;
if ((dcnt <= 0) || (DateStyle == USE_GERMAN_DATES))
ecnt++;
}
else if (!strcasecmp(tok, "DEFAULT"))
{
@@ -445,7 +448,7 @@ parse_timezone(const char *value)
if ((defaultTZ = getenv("TZ")) != NULL)
strcpy(TZvalue, defaultTZ);
/* found nothing so mark with an invalid pointer */
/* found nothing so mark with an invalid pointer */
else
defaultTZ = (char *) -1;
@@ -459,7 +462,7 @@ parse_timezone(const char *value)
}
return TRUE;
} /* parse_timezone() */
} /* parse_timezone() */
bool
show_timezone()
@@ -468,10 +471,10 @@ show_timezone()
tz = getenv("TZ");
elog(NOTICE, "Time zone is %s", ((tz != NULL)? tz: "unknown"));
elog(NOTICE, "Time zone is %s", ((tz != NULL) ? tz : "unknown"));
return TRUE;
} /* show_timezone() */
} /* show_timezone() */
/* reset_timezone()
* Set TZ environment variable to original value.
@@ -501,7 +504,10 @@ reset_timezone()
tzset();
}
/* otherwise, time zone was set but no original explicit time zone available */
/*
* otherwise, time zone was set but no original explicit time zone
* available
*/
else
{
strcpy(tzbuf, "=");
@@ -511,7 +517,7 @@ reset_timezone()
}
return TRUE;
} /* reset_timezone() */
} /* reset_timezone() */
/*-----------------------------------------------------------------------*/
struct VariableParsers
@@ -523,13 +529,27 @@ struct VariableParsers
} VariableParsers[] =
{
{ "datestyle", parse_date, show_date, reset_date },
{ "timezone", parse_timezone, show_timezone, reset_timezone },
{ "cost_heap", parse_cost_heap, show_cost_heap, reset_cost_heap },
{ "cost_index", parse_cost_index, show_cost_index, reset_cost_index },
{ "geqo", parse_geqo, show_geqo, reset_geqo },
{ "r_plans", parse_r_plans, show_r_plans, reset_r_plans },
{ NULL, NULL, NULL, NULL }
{
"datestyle", parse_date, show_date, reset_date
},
{
"timezone", parse_timezone, show_timezone, reset_timezone
},
{
"cost_heap", parse_cost_heap, show_cost_heap, reset_cost_heap
},
{
"cost_index", parse_cost_index, show_cost_index, reset_cost_index
},
{
"geqo", parse_geqo, show_geqo, reset_geqo
},
{
"r_plans", parse_r_plans, show_r_plans, reset_r_plans
},
{
NULL, NULL, NULL, NULL
}
};
/*-----------------------------------------------------------------------*/

View File

@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.20 1998/02/10 04:00:32 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/view.c,v 1.21 1998/02/26 04:31:06 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -118,7 +118,7 @@ DefineVirtualRelation(char *relname, List *tlist)
* This routine is called when defining/removing a view.
*------------------------------------------------------------------
*/
char *
char *
MakeRetrieveViewRuleName(char *viewName)
{
char *buf;