1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-20 05:03:10 +03:00

Standardize on MAXPGPATH as the size of a file pathname buffer,

eliminating some wildly inconsistent coding in various parts of the
system.  I set MAXPGPATH = 1024 in config.h.in.  If anyone is really
convinced that there ought to be a configure-time test to set the
value, go right ahead ... but I think it's a waste of time.
This commit is contained in:
Tom Lane
1999-10-25 03:08:03 +00:00
parent 8a17ed6335
commit 51f62d505e
22 changed files with 183 additions and 193 deletions

View File

@ -5,7 +5,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.6 1999/10/24 20:42:27 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/access/transam/xlog.c,v 1.7 1999/10/25 03:07:42 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -33,8 +33,8 @@ void StartupXLOG(void);
void ShutdownXLOG(void);
void CreateCheckPoint(bool shutdown);
char XLogDir[MAXPGPATH+1];
char ControlFilePath[MAXPGPATH+1];
char XLogDir[MAXPGPATH];
char ControlFilePath[MAXPGPATH];
uint32 XLOGbuffers = 0;
XLogRecPtr MyLastRecPtr = {0, 0};
bool StopIfError = false;
@ -147,8 +147,8 @@ typedef struct CheckPoint
#define XLogFileSize (XLogLastSeg * XLogSegSize)
#define XLogFileName(path, log, seg) \
sprintf(path, "%.*s%c%08X%08X", \
MAXPGPATH, XLogDir, SEP_CHAR, log, seg)
snprintf(path, MAXPGPATH, "%s%c%08X%08X", \
XLogDir, SEP_CHAR, log, seg)
#define PrevBufIdx(curridx) \
((curridx == 0) ? XLogCtl->XLogCacheBlck : (curridx - 1))
@ -718,7 +718,7 @@ XLogWrite(char *buffer)
static int
XLogFileInit(uint32 log, uint32 seg)
{
char path[MAXPGPATH+1];
char path[MAXPGPATH];
int fd;
XLogFileName(path, log, seg);
@ -760,7 +760,7 @@ tryAgain:
static int
XLogFileOpen(uint32 log, uint32 seg, bool econt)
{
char path[MAXPGPATH+1];
char path[MAXPGPATH];
int fd;
XLogFileName(path, log, seg);
@ -1067,7 +1067,7 @@ next_record_is_invalid:;
readId++;
}
{
char path[MAXPGPATH+1];
char path[MAXPGPATH];
XLogFileName(path, readId, readSeg);
unlink(path);

View File

@ -7,7 +7,7 @@
* Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.69 1999/10/06 21:58:02 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/bootstrap/bootstrap.c,v 1.70 1999/10/25 03:07:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -333,8 +333,10 @@ BootstrapMain(int argc, char *argv[])
*/
if (IsUnderPostmaster || xloginit)
{
sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR);
sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR);
snprintf(XLogDir, MAXPGPATH, "%s%cpg_xlog",
DataDir, SEP_CHAR);
snprintf(ControlFilePath, MAXPGPATH, "%s%cpg_control",
DataDir, SEP_CHAR);
}
if (IsUnderPostmaster && xloginit)

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.41 1999/09/24 00:24:17 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.42 1999/10/25 03:07:43 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -38,9 +38,9 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
{
Oid db_id;
int4 user_id;
char buf[512];
char buf[MAXPGPATH + 100];
char *lp,
loc[512];
loc[MAXPGPATH];
/*
* If this call returns, the database does not exist and we're allowed
@ -56,7 +56,7 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
{
if (*(dbpath + strlen(dbpath) - 1) == SEP_CHAR)
*(dbpath + strlen(dbpath) - 1) = '\0';
snprintf(loc, 512, "%s%c%s", dbpath, SEP_CHAR, dbname);
snprintf(loc, sizeof(loc), "%s%c%s", dbpath, SEP_CHAR, dbname);
}
else
strcpy(loc, dbname);
@ -71,11 +71,11 @@ createdb(char *dbname, char *dbpath, int encoding, CommandDest dest)
if (mkdir(lp, S_IRWXU) != 0)
elog(ERROR, "Unable to create database directory '%s'", lp);
snprintf(buf, 512, "%s %s%cbase%ctemplate1%c* %s",
snprintf(buf, sizeof(buf), "%s %s%cbase%ctemplate1%c* '%s'",
COPY_CMD, DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR, lp);
system(buf);
snprintf(buf, 512,
snprintf(buf, sizeof(buf),
"insert into pg_database (datname, datdba, encoding, datpath)"
" values ('%s', '%d', '%d', '%s');", dbname, user_id, encoding,
loc);
@ -89,8 +89,8 @@ destroydb(char *dbname, CommandDest dest)
int4 user_id;
Oid db_id;
char *path,
dbpath[MAXPGPATH + 1],
buf[MAXPGPATH + 50];
dbpath[MAXPGPATH],
buf[MAXPGPATH + 100];
Relation pgdbrel;
HeapScanDesc pgdbscan;
ScanKeyData key;
@ -233,7 +233,7 @@ check_permissions(char *command,
bool use_super;
char *userName;
text *dbtext;
char path[MAXPGPATH + 1];
char path[MAXPGPATH];
userName = GetPgUserName();
utup = SearchSysCacheTuple(USENAME,
@ -332,7 +332,7 @@ static void
stop_vacuum(char *dbpath, char *dbname)
{
#ifdef NOT_USED
char filename[MAXPGPATH + 1];
char filename[MAXPGPATH];
FILE *fp;
int pid;

View File

@ -28,7 +28,7 @@
*
* Copyright (c) 1994, Regents of the University of California
*
* $Id: pqcomm.c,v 1.85 1999/10/23 03:13:22 tgl Exp $
* $Id: pqcomm.c,v 1.86 1999/10/25 03:07:44 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -155,7 +155,8 @@ pq_close(void)
* Stream functions are used for vanilla TCP connection protocol.
*/
static char sock_path[MAXPGPATH + 1] = "";
static char sock_path[MAXPGPATH];
/* StreamDoUnlink()
* Shutdown routine for backend connection

View File

@ -10,7 +10,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.126 1999/10/08 05:36:58 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.127 1999/10/25 03:07:45 tgl Exp $
*
* NOTES
*
@ -179,7 +179,7 @@ static time_t tnow;
/*
* Default Values
*/
static char Execfile[MAXPATHLEN] = "";
static char Execfile[MAXPGPATH];
static int ServerSock_INET = INVALID_SOCK; /* stream socket server */
@ -195,7 +195,7 @@ static SSL_CTX *SSL_context = NULL; /* Global SSL context */
/*
* Set by the -o option
*/
static char ExtraOptions[MAXPATHLEN] = "";
static char ExtraOptions[MAXPGPATH];
/*
* These globals control the behavior of the postmaster in case some
@ -294,10 +294,10 @@ checkDataDir(const char *DataDir, bool *DataDirOK)
}
else
{
char path[MAXPATHLEN];
char path[MAXPGPATH];
FILE *fp;
sprintf(path, "%s%cbase%ctemplate1%cpg_class",
snprintf(path, sizeof(path), "%s%cbase%ctemplate1%cpg_class",
DataDir, SEP_CHAR, SEP_CHAR, SEP_CHAR);
#ifndef __CYGWIN32__
fp = AllocateFile(path, "r");
@ -446,7 +446,7 @@ PostmasterMain(int argc, char *argv[])
case 'b':
/* Set the backend executable file to use. */
if (!ValidateBinary(optarg))
strcpy(Execfile, optarg);
StrNCpy(Execfile, optarg, MAXPGPATH);
else
{
fprintf(stderr, "%s: invalid backend \"%s\"\n",
@ -1698,7 +1698,7 @@ DoBackend(Port *port)
{
char *av[ARGV_SIZE * 2];
int ac = 0;
char execbuf[MAXPATHLEN];
char execbuf[MAXPGPATH];
char debugbuf[ARGV_SIZE];
char protobuf[ARGV_SIZE];
char dbbuf[ARGV_SIZE];
@ -1749,7 +1749,7 @@ DoBackend(Port *port)
* ----------------
*/
StrNCpy(execbuf, Execfile, MAXPATHLEN);
StrNCpy(execbuf, Execfile, MAXPGPATH);
av[ac++] = execbuf;
/*
@ -2013,7 +2013,7 @@ SSDataBase(bool startup)
{
char *av[ARGV_SIZE * 2];
int ac = 0;
char execbuf[MAXPATHLEN];
char execbuf[MAXPGPATH];
char nbbuf[ARGV_SIZE];
char dbbuf[ARGV_SIZE];
@ -2024,7 +2024,7 @@ SSDataBase(bool startup)
StreamClose(ServerSock_UNIX);
#endif
StrNCpy(execbuf, Execfile, MAXPATHLEN);
StrNCpy(execbuf, Execfile, MAXPGPATH);
av[ac++] = execbuf;
av[ac++] = "-d";

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.56 1999/10/06 06:38:04 inoue Exp $
* $Header: /cvsroot/pgsql/src/backend/storage/smgr/md.c,v 1.57 1999/10/25 03:07:47 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -591,7 +591,7 @@ mdblindwrt(char *dbstr,
else
/* this is work arround only !!! */
{
char dbpath[MAXPGPATH + 1];
char dbpath[MAXPGPATH];
Oid id;
char *tmpPath;
@ -628,7 +628,7 @@ mdblindwrt(char *dbstr,
else
/* this is work arround only !!! */
{
char dbpath[MAXPGPATH + 1];
char dbpath[MAXPGPATH];
Oid id;
char *tmpPath;

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.135 1999/10/23 03:13:22 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.136 1999/10/25 03:07:48 tgl Exp $
*
* NOTES
* this is the "main" module of the postgres backend and
@ -92,7 +92,6 @@
* ----------------
*/
/*static bool EnableRewrite = true; , never changes why have it*/
CommandDest whereToSendOutput = Debug;
/* Define status buffer needed by PS_SET_STATUS */
@ -114,8 +113,6 @@ int dontExecute = 0;
static int ShowStats;
static bool IsEmptyQuery = false;
char relname[80]; /* current relation name */
/* note: these declarations had better match tcopprot.h */
DLLIMPORT sigjmp_buf Warn_restart;
@ -126,7 +123,7 @@ extern int NBuffers;
static bool EchoQuery = false; /* default don't echo */
time_t tim;
char pg_pathname[256];
char pg_pathname[MAXPGPATH];
FILE *StatFp;
/* ----------------
@ -1359,8 +1356,10 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
proc_exit(1);
}
BaseInit();
sprintf(XLogDir, "%s%cpg_xlog", DataDir, SEP_CHAR);
sprintf(ControlFilePath, "%s%cpg_control", DataDir, SEP_CHAR);
snprintf(XLogDir, MAXPGPATH, "%s%cpg_xlog",
DataDir, SEP_CHAR);
snprintf(ControlFilePath, MAXPGPATH, "%s%cpg_control",
DataDir, SEP_CHAR);
StartupXLOG();
}
@ -1372,6 +1371,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
SetCharSet();
#endif
/* On some systems our dynloader code needs the executable's pathname */
if (FindExec(pg_pathname, argv[0], "postgres") < 0)
elog(FATAL, "%s: could not locate executable, bailing out...",
argv[0]);
@ -1494,7 +1494,7 @@ PostgresMain(int argc, char *argv[], int real_argc, char *real_argv[])
if (!IsUnderPostmaster)
{
puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.135 $ $Date: 1999/10/23 03:13:22 $\n");
puts("$Revision: 1.136 $ $Date: 1999/10/25 03:07:48 $\n");
}
/*

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.22 1999/07/17 20:17:55 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/filename.c,v 1.23 1999/10/25 03:07:49 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -31,7 +31,7 @@ filename_in(char *file)
* (shexpand)
*/
str = (char *) palloc(MAXPATHLEN * sizeof(*str));
str = (char *) palloc(MAXPGPATH);
str[0] = '\0';
if (file[0] == '~')
{

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.49 1999/10/06 21:58:09 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/error/elog.c,v 1.50 1999/10/25 03:07:50 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -415,7 +415,6 @@ DebugFileOpen(void)
if (OutputFileName[0])
{
OutputFileName[MAXPGPATH - 1] = '\0';
if ((fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY,
0666)) < 0)
elog(FATAL, "DebugFileOpen: open of %s: %m",
@ -448,7 +447,8 @@ DebugFileOpen(void)
fd = fileno(stderr);
if (fcntl(fd, F_GETFD, 0) < 0)
{
sprintf(OutputFileName, "%s/pg.errors.%d", DataDir, (int) MyProcPid);
snprintf(OutputFileName, MAXPGPATH, "%s%cpg.errors.%d",
DataDir, SEP_CHAR, (int) MyProcPid);
fd = open(OutputFileName, O_CREAT | O_APPEND | O_WRONLY, 0666);
}
if (fd < 0)

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.51 1999/10/06 21:58:10 vadim Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.52 1999/10/25 03:07:51 tgl Exp $
*
* NOTES
* InitPostgres() is the function called from PostgresMain
@ -100,7 +100,7 @@ static void
InitMyDatabaseInfo(char *name)
{
char *path,
myPath[MAXPGPATH + 1];
myPath[MAXPGPATH];
SetDatabaseName(name);
GetRawDatabaseInfo(name, &MyDatabaseId, myPath);
@ -143,10 +143,9 @@ static void
VerifySystemDatabase()
{
char *reason;
/* Failure reason returned by some function. NULL if no failure */
int fd;
char errormsg[1000];
char errormsg[MAXPGPATH+100];
errormsg[0] = '\0';
@ -155,20 +154,21 @@ VerifySystemDatabase()
#else
if ((fd = open(DataDir, O_RDONLY | O_DIROPEN, 0)) == -1)
#endif
sprintf(errormsg, "Database system does not exist. "
"PGDATA directory '%s' not found.\n\tNormally, you "
"create a database system by running initdb.",
DataDir);
snprintf(errormsg, sizeof(errormsg),
"Database system does not exist. "
"PGDATA directory '%s' not found.\n\tNormally, you "
"create a database system by running initdb.",
DataDir);
else
{
close(fd);
ValidatePgVersion(DataDir, &reason);
if (reason != NULL)
sprintf(errormsg,
"InitPostgres could not validate that the database"
" system version is compatible with this level of"
" Postgres.\n\tYou may need to run initdb to create"
" a new database system.\n\t%s", reason);
snprintf(errormsg, sizeof(errormsg),
"InitPostgres could not validate that the database"
" system version is compatible with this level of"
" Postgres.\n\tYou may need to run initdb to create"
" a new database system.\n\t%s", reason);
}
if (errormsg[0] != '\0')
elog(FATAL, errormsg);
@ -185,7 +185,7 @@ VerifyMyDatabase()
/* Failure reason returned by some function. NULL if no failure */
char *reason;
int fd;
char errormsg[1000];
char errormsg[MAXPGPATH+100];
name = DatabaseName;
myPath = DatabasePath;
@ -195,26 +195,26 @@ VerifyMyDatabase()
#else
if ((fd = open(myPath, O_RDONLY | O_DIROPEN, 0)) == -1)
#endif
sprintf(errormsg,
"Database '%s' does not exist."
"\n\tWe know this because the directory '%s' does not exist."
"\n\tYou can create a database with the SQL command"
" CREATE DATABASE.\n\tTo see what databases exist,"
" look at the subdirectories of '%s/base/'.",
name, myPath, DataDir);
snprintf(errormsg, sizeof(errormsg),
"Database '%s' does not exist."
"\n\tWe know this because the directory '%s' does not exist."
"\n\tYou can create a database with the SQL command"
" CREATE DATABASE.\n\tTo see what databases exist,"
" look at the subdirectories of '%s/base/'.",
name, myPath, DataDir);
else
{
close(fd);
ValidatePgVersion(myPath, &reason);
if (reason != NULL)
sprintf(errormsg,
"InitPostgres could not validate that the database"
" version is compatible with this level of Postgres"
"\n\teven though the database system as a whole"
" appears to be at a compatible level."
"\n\tYou may need to recreate the database with SQL"
" commands DROP DATABASE and CREATE DATABASE."
"\n\t%s", reason);
snprintf(errormsg, sizeof(errormsg),
"InitPostgres could not validate that the database"
" version is compatible with this level of Postgres"
"\n\teven though the database system as a whole"
" appears to be at a compatible level."
"\n\tYou may need to recreate the database with SQL"
" commands DROP DATABASE and CREATE DATABASE."
"\n\t%s", reason);
else
{
@ -229,10 +229,10 @@ VerifyMyDatabase()
rc = chdir(myPath);
if (rc < 0)
sprintf(errormsg,
"InitPostgres unable to change "
"current directory to '%s', errno = %s (%d).",
myPath, strerror(errno), errno);
snprintf(errormsg, sizeof(errormsg),
"InitPostgres unable to change "
"current directory to '%s', errno = %s (%d).",
myPath, strerror(errno), errno);
else
errormsg[0] = '\0';
}

View File

@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.30 1999/09/24 00:25:04 tgl Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/misc/Attic/database.c,v 1.31 1999/10/25 03:07:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@ -30,7 +30,7 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
{
Oid dbowner,
dbid;
char dbpath[MAXPGPATH + 1];
char dbpath[MAXPGPATH];
text *dbtext;
Relation dbrel;
@ -86,8 +86,7 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
owner = palloc(sizeof(Oid));
*owner = dbowner;
path = palloc(strlen(dbpath) + 1);
strcpy(path, dbpath);
path = pstrdup(dbpath); /* doesn't do the right thing! */
return FALSE;
} /* GetDatabaseInfo() */
@ -97,46 +96,53 @@ GetDatabaseInfo(char *name, int4 *owner, char *path)
char *
ExpandDatabasePath(char *dbpath)
{
char *path;
char buf[MAXPGPATH];
char *cp;
char buf[MAXPGPATH + 1];
char *envvar;
int len;
if (strlen(dbpath) >= MAXPGPATH)
return NULL; /* ain't gonna fit nohow */
/* leading path delimiter? then already absolute path */
if (*dbpath == SEP_CHAR)
{
#ifdef ALLOW_ABSOLUTE_DBPATHS
cp = strrchr(dbpath, SEP_CHAR);
strncpy(buf, dbpath, (cp - dbpath));
sprintf(&buf[cp - dbpath], "%cbase%c%s", SEP_CHAR, SEP_CHAR, (cp + 1));
len = cp - dbpath;
strncpy(buf, dbpath, len);
snprintf(&buf[len], MAXPGPATH-len, "%cbase%c%s",
SEP_CHAR, SEP_CHAR, (cp + 1));
#else
return NULL;
#endif
}
/* path delimiter somewhere? then has leading environment variable */
else if (strchr(dbpath, SEP_CHAR) != NULL)
else if ((cp = strchr(dbpath, SEP_CHAR)) != NULL)
{
cp = strchr(dbpath, SEP_CHAR);
strncpy(buf, dbpath, (cp - dbpath));
buf[cp - dbpath] = '\0';
path = getenv(buf);
len = cp - dbpath;
strncpy(buf, dbpath, len);
buf[len] = '\0';
envvar = getenv(buf);
/*
* problem getting environment variable? let calling routine
* handle it
*/
if (path == NULL)
return path;
if (envvar == NULL)
return envvar;
sprintf(buf, "%s%cbase%c%s", path, SEP_CHAR, SEP_CHAR, (cp + 1));
snprintf(buf, sizeof(buf), "%s%cbase%c%s",
envvar, SEP_CHAR, SEP_CHAR, (cp + 1));
}
/* no path delimiter? then add the default path prefixes */
else
sprintf(buf, "%s%cbase%c%s", DataDir, SEP_CHAR, SEP_CHAR, dbpath);
{
/* no path delimiter? then add the default path prefix */
snprintf(buf, sizeof(buf), "%s%cbase%c%s",
DataDir, SEP_CHAR, SEP_CHAR, dbpath);
}
path = palloc(strlen(buf) + 1);
strcpy(path, buf);
return path;
return pstrdup(buf);
} /* ExpandDatabasePath() */