aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/init
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/init')
-rw-r--r--src/backend/utils/init/findbe.c27
-rw-r--r--src/backend/utils/init/miscinit.c142
-rw-r--r--src/backend/utils/init/postinit.c59
3 files changed, 152 insertions, 76 deletions
diff --git a/src/backend/utils/init/findbe.c b/src/backend/utils/init/findbe.c
index fabdd719110..a725160ee6b 100644
--- a/src/backend/utils/init/findbe.c
+++ b/src/backend/utils/init/findbe.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.34 2003/05/27 17:49:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.35 2003/07/25 20:17:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -62,13 +62,13 @@ ValidateBinary(char *path)
*/
if (stat(path, &buf) < 0)
{
- elog(DEBUG3, "ValidateBinary: can't stat \"%s\"", path);
+ elog(DEBUG3, "could not stat \"%s\": %m", path);
return -1;
}
if ((buf.st_mode & S_IFMT) != S_IFREG)
{
- elog(DEBUG3, "ValidateBinary: \"%s\" is not a regular file", path);
+ elog(DEBUG3, "\"%s\" is not a regular file", path);
return -1;
}
@@ -95,7 +95,7 @@ ValidateBinary(char *path)
is_r = buf.st_mode & S_IRUSR;
is_x = buf.st_mode & S_IXUSR;
if (!(is_r && is_x))
- elog(DEBUG3, "ValidateBinary: \"%s\" is not user read/execute", path);
+ elog(DEBUG3, "\"%s\" is not user read/execute", path);
return is_x ? (is_r ? 0 : -2) : -1;
}
pwp = getpwuid(euid);
@@ -121,16 +121,14 @@ ValidateBinary(char *path)
is_r = buf.st_mode & S_IRGRP;
is_x = buf.st_mode & S_IXGRP;
if (!(is_r && is_x))
- elog(DEBUG3, "ValidateBinary: \"%s\" is not group read/execute",
- path);
+ elog(DEBUG3, "\"%s\" is not group read/execute", path);
return is_x ? (is_r ? 0 : -2) : -1;
}
}
is_r = buf.st_mode & S_IROTH;
is_x = buf.st_mode & S_IXOTH;
if (!(is_r && is_x))
- elog(DEBUG3, "ValidateBinary: \"%s\" is not other read/execute",
- path);
+ elog(DEBUG3, "\"%s\" is not other read/execute", path);
return is_x ? (is_r ? 0 : -2) : -1;
#endif
}
@@ -179,10 +177,10 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
if (ValidateBinary(buf) == 0)
{
strncpy(full_path, buf, MAXPGPATH);
- elog(DEBUG2, "FindExec: found \"%s\" using argv[0]", full_path);
+ elog(DEBUG2, "found \"%s\" using argv[0]", full_path);
return 0;
}
- elog(LOG, "FindExec: invalid binary \"%s\"", buf);
+ elog(DEBUG2, "invalid binary \"%s\"", buf);
return -1;
}
@@ -192,7 +190,7 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
*/
if ((p = getenv("PATH")) && *p)
{
- elog(DEBUG2, "FindExec: searching PATH ...");
+ elog(DEBUG2, "searching PATH for executable");
path = strdup(p); /* make a modifiable copy */
for (startp = path, endp = strchr(path, ':');
startp && *startp;
@@ -213,14 +211,13 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
{
case 0: /* found ok */
strncpy(full_path, buf, MAXPGPATH);
- elog(DEBUG2, "FindExec: found \"%s\" using PATH",
- full_path);
+ elog(DEBUG2, "found \"%s\" using PATH", full_path);
free(path);
return 0;
case -1: /* wasn't even a candidate, keep looking */
break;
case -2: /* found but disqualified */
- elog(LOG, "FindExec: could not read binary \"%s\"", buf);
+ elog(DEBUG2, "could not read binary \"%s\"", buf);
free(path);
return -1;
}
@@ -230,6 +227,6 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
free(path);
}
- elog(LOG, "FindExec: could not find a %s to execute", binary_name);
+ elog(DEBUG2, "could not find a \"%s\" to execute", binary_name);
return -1;
}
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index 4d65f619be4..40cd86c1785 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.104 2003/06/27 19:08:37 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.105 2003/07/25 20:17:52 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -128,7 +128,9 @@ SetDataDir(const char *dir)
{
buf = malloc(buflen);
if (!buf)
- elog(FATAL, "out of memory");
+ ereport(FATAL,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
if (getcwd(buf, buflen))
break;
@@ -141,13 +143,15 @@ SetDataDir(const char *dir)
else
{
free(buf);
- elog(FATAL, "cannot get current working directory: %m");
+ elog(FATAL, "could not get current working directory: %m");
}
}
new = malloc(strlen(buf) + 1 + strlen(dir) + 1);
if (!new)
- elog(FATAL, "out of memory");
+ ereport(FATAL,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
sprintf(new, "%s/%s", buf, dir);
free(buf);
}
@@ -155,7 +159,9 @@ SetDataDir(const char *dir)
{
new = strdup(dir);
if (!new)
- elog(FATAL, "out of memory");
+ ereport(FATAL,
+ (errcode(ERRCODE_OUT_OF_MEMORY),
+ errmsg("out of memory")));
}
/*
@@ -235,7 +241,7 @@ SetCharSet(void)
while (!feof(file) && buf[0])
{
next_token(file, buf, sizeof(buf));
- elog(LOG, "SetCharSet: unknown tag %s in file %s",
+ elog(LOG, "unexpected token %s in file %s",
buf, filename);
}
}
@@ -390,7 +396,7 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
else if (strcasecmp(buf, "RecodeTable") == 0)
key = KEY_TABLE;
else
- elog(LOG, "GetCharSetByHost: unknown tag %s in file %s",
+ elog(LOG, "unknown tag %s in file %s",
buf, CHARSET_FILE);
switch (key)
@@ -446,7 +452,7 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
while (!feof(file) && buf[0])
{
next_token(file, buf, sizeof(buf));
- elog(LOG, "GetCharSetByHost: unknown tag %s in file %s",
+ elog(LOG, "unknown tag %s in file %s",
buf, CHARSET_FILE);
}
}
@@ -544,7 +550,9 @@ InitializeSessionUserId(const char *username)
PointerGetDatum(username),
0, 0, 0);
if (!HeapTupleIsValid(userTup))
- elog(FATAL, "user \"%s\" does not exist", username);
+ ereport(FATAL,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("user \"%s\" does not exist", username)));
usesysid = ((Form_pg_shadow) GETSTRUCT(userTup))->usesysid;
@@ -610,7 +618,9 @@ SetSessionAuthorization(AclId userid, bool is_superuser)
if (userid != AuthenticatedUserId &&
!AuthenticatedUserIsSuperuser)
- elog(ERROR, "SET SESSION AUTHORIZATION: permission denied");
+ ereport(ERROR,
+ (errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
+ errmsg("permission denied")));
SetSessionUserId(userid);
SetUserId(userid);
@@ -634,7 +644,9 @@ GetUserNameFromId(AclId userid)
ObjectIdGetDatum(userid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
- elog(ERROR, "invalid user id %d", userid);
+ ereport(ERROR,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("invalid user id: %d", userid)));
result = pstrdup(NameStr(((Form_pg_shadow) GETSTRUCT(tuple))->usename));
@@ -716,7 +728,10 @@ CreateLockFile(const char *filename, bool amPostmaster,
* Couldn't create the pid file. Probably it already exists.
*/
if ((errno != EEXIST && errno != EACCES) || ntries > 100)
- elog(FATAL, "Can't create lock file %s: %m", filename);
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not create lock file \"%s\": %m",
+ filename)));
/*
* Read the file to get the old owner's PID. Note race condition
@@ -727,10 +742,16 @@ CreateLockFile(const char *filename, bool amPostmaster,
{
if (errno == ENOENT)
continue; /* race condition; try again */
- elog(FATAL, "Can't read lock file %s: %m", filename);
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not open lock file \"%s\": %m",
+ filename)));
}
if ((len = read(fd, buffer, sizeof(buffer) - 1)) <= 0)
- elog(FATAL, "Can't read lock file %s: %m", filename);
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not read lock file \"%s\": %m",
+ filename)));
close(fd);
buffer[len] = '\0';
@@ -740,7 +761,7 @@ CreateLockFile(const char *filename, bool amPostmaster,
other_pid = (pid_t) (encoded_pid < 0 ? -encoded_pid : encoded_pid);
if (other_pid <= 0)
- elog(FATAL, "Bogus data in lock file %s", filename);
+ elog(FATAL, "bogus data in lock file \"%s\"", filename);
/*
* Check to see if the other process still exists
@@ -814,10 +835,13 @@ CreateLockFile(const char *filename, bool amPostmaster,
* against other would-be creators.
*/
if (unlink(filename) < 0)
- elog(FATAL, "Can't remove old lock file %s: %m"
- "\n\tThe file seems accidentally left, but I couldn't remove it."
- "\n\tPlease remove the file by hand and try again.",
- filename);
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not remove old lock file \"%s\": %m",
+ filename),
+ errhint("The file seems accidentally left over, but "
+ "I couldn't remove it. Please remove the file "
+ "by hand and try again.")));
}
/*
@@ -835,7 +859,9 @@ CreateLockFile(const char *filename, bool amPostmaster,
unlink(filename);
/* if write didn't set errno, assume problem is no disk space */
errno = save_errno ? save_errno : ENOSPC;
- elog(FATAL, "Can't write lock file %s: %m", filename);
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not write lock file \"%s\": %m", filename)));
}
close(fd);
@@ -941,13 +967,19 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
fd = open(directoryLockFile, O_RDWR | PG_BINARY, 0);
if (fd < 0)
{
- elog(LOG, "Failed to rewrite %s: %m", directoryLockFile);
+ ereport(LOG,
+ (errcode_for_file_access(),
+ errmsg("could not rewrite \"%s\": %m",
+ directoryLockFile)));
return;
}
len = read(fd, buffer, sizeof(buffer) - 100);
if (len <= 0)
{
- elog(LOG, "Failed to read %s: %m", directoryLockFile);
+ ereport(LOG,
+ (errcode_for_file_access(),
+ errmsg("could not read \"%s\": %m",
+ directoryLockFile)));
close(fd);
return;
}
@@ -960,7 +992,7 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
if (ptr == NULL ||
(ptr = strchr(ptr + 1, '\n')) == NULL)
{
- elog(LOG, "Bogus data in %s", directoryLockFile);
+ elog(LOG, "bogus data in \"%s\"", directoryLockFile);
close(fd);
return;
}
@@ -984,7 +1016,10 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
/* if write didn't set errno, assume problem is no disk space */
if (errno == 0)
errno = ENOSPC;
- elog(LOG, "Failed to write %s: %m", directoryLockFile);
+ ereport(LOG,
+ (errcode_for_file_access(),
+ errmsg("could not write \"%s\": %m",
+ directoryLockFile)));
close(fd);
return;
}
@@ -1001,7 +1036,7 @@ RecordSharedMemoryInLockFile(unsigned long id1, unsigned long id2)
* Determine whether the PG_VERSION file in directory `path' indicates
* a data version compatible with the version of this program.
*
- * If compatible, return. Otherwise, elog(FATAL).
+ * If compatible, return. Otherwise, ereport(FATAL).
*/
void
ValidatePgVersion(const char *path)
@@ -1026,21 +1061,36 @@ ValidatePgVersion(const char *path)
if (!file)
{
if (errno == ENOENT)
- elog(FATAL, "File %s is missing. This is not a valid data directory.", full_path);
+ ereport(FATAL,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("\"%s\" is not a valid data directory",
+ path),
+ errdetail("File \"%s\" is missing.", full_path)));
else
- elog(FATAL, "cannot open %s: %m", full_path);
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not open \"%s\": %m", full_path)));
}
ret = fscanf(file, "%ld.%ld", &file_major, &file_minor);
if (ret != 2)
- elog(FATAL, "File %s does not contain valid data. You need to initdb.", full_path);
+ ereport(FATAL,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("\"%s\" is not a valid data directory",
+ path),
+ errdetail("File \"%s\" does not contain valid data.",
+ full_path),
+ errhint("You may need to initdb.")));
FreeFile(file);
if (my_major != file_major || my_minor != file_minor)
- elog(FATAL, "The data directory was initialized by PostgreSQL version %ld.%ld, "
- "which is not compatible with this version %s.",
- file_major, file_minor, version_string);
+ ereport(FATAL,
+ (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
+ errmsg("database files are incompatible with server"),
+ errdetail("The data directory was initialized by PostgreSQL version %ld.%ld, "
+ "which is not compatible with this version %s.",
+ file_major, file_minor, version_string)));
}
/*-------------------------------------------------------------------------
@@ -1077,7 +1127,10 @@ process_preload_libraries(char *preload_libraries_string)
/* syntax error in list */
pfree(rawstring);
freeList(elemlist);
- elog(LOG, "invalid list syntax for preload_libraries configuration option");
+ ereport(LOG,
+ (errcode(ERRCODE_SYNTAX_ERROR),
+ errmsg("invalid list syntax for preload_libraries configuration option")));
+ return;
}
foreach(l, elemlist)
@@ -1098,12 +1151,11 @@ process_preload_libraries(char *preload_libraries_string)
size_t funcname_len = strlen(tok) - filename_len - 1;
filename = (char *) palloc(filename_len + 1);
- memset(filename, '\0', filename_len + 1);
- snprintf(filename, filename_len + 1, "%s", tok);
+ memcpy(filename, tok, filename_len);
+ filename[filename_len] = '\0';
funcname = (char *) palloc(funcname_len + 1);
- memset(funcname, '\0', funcname_len + 1);
- snprintf(funcname, funcname_len + 1, "%s", sep + 1);
+ strcpy(funcname, sep + 1);
}
else
{
@@ -1114,16 +1166,22 @@ process_preload_libraries(char *preload_libraries_string)
funcname = NULL;
}
- initfunc = (func_ptr) load_external_function(filename, funcname, false, NULL);
+ initfunc = (func_ptr) load_external_function(filename, funcname,
+ false, NULL);
if (initfunc)
(*initfunc)();
- elog(LOG, "preloaded library %s with initialization function %s", filename, funcname);
-
- if (filename != NULL)
- pfree(filename);
+ if (funcname)
+ ereport(LOG,
+ (errmsg("preloaded library \"%s\" with initialization function \"%s\"",
+ filename, funcname)));
+ else
+ ereport(LOG,
+ (errmsg("preloaded library \"%s\"",
+ filename)));
- if (funcname != NULL)
+ pfree(filename);
+ if (funcname)
pfree(funcname);
}
diff --git a/src/backend/utils/init/postinit.c b/src/backend/utils/init/postinit.c
index 3cd3f579294..9dc96f0653b 100644
--- a/src/backend/utils/init/postinit.c
+++ b/src/backend/utils/init/postinit.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.123 2003/07/14 20:00:22 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.124 2003/07/25 20:17:52 tgl Exp $
*
*
*-------------------------------------------------------------------------
@@ -111,8 +111,10 @@ ReverifyMyDatabase(const char *name)
*/
DropBuffers(MyDatabaseId);
/* Now I can commit hara-kiri with a clear conscience... */
- elog(FATAL, "Database \"%s\", OID %u, has disappeared from pg_database",
- name, MyDatabaseId);
+ ereport(FATAL,
+ (errcode(ERRCODE_UNDEFINED_DATABASE),
+ errmsg("database \"%s\", OID %u, has disappeared from pg_database",
+ name, MyDatabaseId)));
}
/*
@@ -120,8 +122,10 @@ ReverifyMyDatabase(const char *name)
*/
dbform = (Form_pg_database) GETSTRUCT(tup);
if (!dbform->datallowconn)
- elog(FATAL, "Database \"%s\" is not currently accepting connections",
- name);
+ ereport(FATAL,
+ (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
+ errmsg("database \"%s\" is not currently accepting connections",
+ name)));
/*
* OK, we're golden. Only other to-do item is to save the encoding
@@ -252,23 +256,38 @@ InitPostgres(const char *dbname, const char *username)
GetRawDatabaseInfo(dbname, &MyDatabaseId, datpath);
if (!OidIsValid(MyDatabaseId))
- elog(FATAL,
- "Database \"%s\" does not exist in the system catalog.",
- dbname);
+ ereport(FATAL,
+ (errcode(ERRCODE_UNDEFINED_DATABASE),
+ errmsg("database \"%s\" does not exist",
+ dbname)));
fullpath = GetDatabasePath(MyDatabaseId);
/* Verify the database path */
if (access(fullpath, F_OK) == -1)
- elog(FATAL, "Database \"%s\" does not exist.\n\t"
- "The database subdirectory '%s' is missing.",
- dbname, fullpath);
+ {
+ if (errno == ENOENT)
+ ereport(FATAL,
+ (errcode(ERRCODE_UNDEFINED_DATABASE),
+ errmsg("database \"%s\" does not exist",
+ dbname),
+ errdetail("The database subdirectory \"%s\" is missing.",
+ fullpath)));
+ else
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not access directory \"%s\": %m",
+ fullpath)));
+ }
ValidatePgVersion(fullpath);
if (chdir(fullpath) == -1)
- elog(FATAL, "Unable to change directory to '%s': %m", fullpath);
+ ereport(FATAL,
+ (errcode_for_file_access(),
+ errmsg("could not change directory to \"%s\": %m",
+ fullpath)));
SetDatabasePath(fullpath);
}
@@ -297,7 +316,7 @@ InitPostgres(const char *dbname, const char *username)
InitBackendSharedInvalidationState();
if (MyBackendId > MaxBackends || MyBackendId <= 0)
- elog(FATAL, "InitPostgres: bad backend id %d", MyBackendId);
+ elog(FATAL, "bad backend id: %d", MyBackendId);
/*
* Initialize the transaction system override state.
@@ -347,11 +366,11 @@ InitPostgres(const char *dbname, const char *username)
{
InitializeSessionUserIdStandalone();
if (!ThereIsAtLeastOneUser())
- {
- elog(WARNING, "There are currently no users defined in this database system.");
- elog(WARNING, "You should immediately run 'CREATE USER \"%s\" WITH SYSID %d CREATEUSER;'.",
- username, BOOTSTRAP_USESYSID);
- }
+ ereport(WARNING,
+ (errcode(ERRCODE_UNDEFINED_OBJECT),
+ errmsg("no users are defined in this database system"),
+ errhint("You should immediately run 'CREATE USER \"%s\" WITH SYSID %d CREATEUSER;'.",
+ username, BOOTSTRAP_USESYSID)));
}
else
{
@@ -384,7 +403,9 @@ InitPostgres(const char *dbname, const char *username)
if (ReservedBackends > 0 &&
CountEmptyBackendSlots() < ReservedBackends &&
!superuser())
- elog(FATAL, "Non-superuser connection limit exceeded");
+ ereport(FATAL,
+ (errcode(ERRCODE_TOO_MANY_CONNECTIONS),
+ errmsg("connection limit exceeded for non-superusers")));
/*
* Initialize various default states that can't be set up until we've