*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.18 1997/08/18 02:14:37 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.19 1997/08/27 03:48:31 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include
#include
-#include
+#include
+#include
#include
-#include /* needed by in.h on Ultrix */
#include
#include
system.
---------------------------------------------------------------------------*/
- int rc;
- struct stat statbuf;
+ int fd;
FILE *file; /* The config file we have to read */
strlen(OLD_CONF_FILE)+2)*sizeof(char));
sprintf(old_conf_file, "%s/%s", DataDir, OLD_CONF_FILE);
- rc = stat(old_conf_file, &statbuf);
- if (rc == 0) {
+ if ((fd = open(old_conf_file,O_RDONLY,0)) != -1) {
/* Old config file exists. Tell this guy he needs to upgrade. */
+ close(fd);
sprintf(PQerrormsg,
"A file exists by the name used for host-based authentication "
"in prior releases of Postgres (%s). The name and format of "
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.4 1997/08/12 20:16:12 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/Attic/findbe.c,v 1.5 1997/08/27 03:48:38 momjian Exp $
*
*-------------------------------------------------------------------------
*/
#include
#include
-#include
#include
+#include
#include
#include "postgres.h"
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.11 1997/08/19 21:35:50 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.12 1997/08/27 03:48:39 momjian Exp $
*
* NOTES
* InitPostgres() is the function called from PostgresMain
#include
#include
#include
-#include
#include
#include
#include
static IPCKey PostgresIpcKey;
-
-#ifndef private
-#ifndef EBUG
-#define private static
-#else /* !defined(EBUG) */
-#define private
-#endif /* !defined(EBUG) */
-#endif /* !defined(private) */
-
/* ----------------------------------------------------------------
* InitPostgres support
* ----------------------------------------------------------------
sprintf(dbfname, "%s%cpg_database", DataDir, SEP_CHAR);
fileflags = O_RDONLY;
- if ((dbfd = open(dbfname, O_RDONLY, 0666)) < 0)
+ if ((dbfd = open(dbfname, O_RDONLY, 0)) < 0)
elog(FATAL, "Cannot open %s", dbfname);
pfree(dbfname);
DoChdirAndInitDatabaseNameAndPath(char *name) {
char *reason;
/* Failure reason returned by some function. NULL if no failure */
- struct stat statbuf;
+ int fd;
char errormsg[1000];
- if (stat(DataDir, &statbuf) < 0)
+ if ((fd = open(DataDir, O_RDONLY,0)) == -1)
sprintf(errormsg, "Database system does not exist. "
"PGDATA directory '%s' not found. Normally, you "
"create a database system by running initdb.",
else {
char myPath[MAXPGPATH]; /* DatabasePath points here! */
+ close(fd);
if (strlen(DataDir) + strlen(name) + 10 > sizeof(myPath))
sprintf(errormsg, "Internal error in postinit.c: database "
"pathname exceeds maximum allowable length.");
else {
sprintf(myPath, "%s/base/%s", DataDir, name);
- if (stat(myPath, &statbuf) < 0)
+ if ((fd = open(myPath, O_RDONLY,0)) == -1)
sprintf(errormsg,
"Database '%s' does not exist. "
"(We know this because the directory '%s' "
"of '%s/base/'.",
name, myPath, DataDir);
else {
+ close(fd);
ValidatePgVersion(DataDir, &reason);
if (reason != NULL)
sprintf(errormsg,
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.5 1997/07/28 00:57:08 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/utils/Attic/version.c,v 1.6 1997/08/27 03:48:50 momjian Exp $
*
* NOTES
* XXX eventually, should be able to handle version identifiers
int fd;
char version[4];
char full_path[MAXPGPATH+1];
- struct stat statbuf;
PathSetVersionFilePath(path, full_path);
- if (stat(full_path, &statbuf) < 0) {
+ if ((fd = open(full_path, O_RDONLY,0)) == -1) {
*reason_p = malloc(200);
- sprintf(*reason_p, "File '%s' does not exist.", full_path);
+ sprintf(*reason_p, "File '%s' does not exist or no read permission.", full_path);
} else {
- fd = open(full_path, O_RDONLY, 0);
- if (fd < 0) {
+ if (read(fd, version, 4) < 4 ||
+ !isascii(version[0]) || !isdigit(version[0]) ||
+ version[1] != '.' ||
+ !isascii(version[2]) || !isdigit(version[2]) ||
+ version[3] != '\n') {
+
*reason_p = malloc(200);
- sprintf(*reason_p, "Unable to open file '%s'. Errno = %s (%d).",
- full_path, strerror(errno), errno);
+ sprintf(*reason_p, "File '%s' does not have a valid format "
+ "for a PG_VERSION file.", full_path);
} else {
- if (read(fd, version, 4) < 4 ||
- !isascii(version[0]) || !isdigit(version[0]) ||
- version[1] != '.' ||
- !isascii(version[2]) || !isdigit(version[2]) ||
- version[3] != '\n') {
-
+ if (version[2] != '0' + PG_VERSION ||
+ version[0] != '0' + PG_RELEASE) {
*reason_p = malloc(200);
- sprintf(*reason_p, "File '%s' does not have a valid format "
- "for a PG_VERSION file.", full_path);
- } else {
- if (version[2] != '0' + PG_VERSION ||
- version[0] != '0' + PG_RELEASE) {
- *reason_p = malloc(200);
- sprintf(*reason_p,
- "Version number in file '%s' should be %d.%d, "
- "not %c.%c.",
- full_path,
- PG_RELEASE, PG_VERSION, version[0], version[2]);
- } else *reason_p = NULL;
- }
- close(fd);
+ sprintf(*reason_p,
+ "Version number in file '%s' should be %d.%d, "
+ "not %c.%c.",
+ full_path,
+ PG_RELEASE, PG_VERSION, version[0], version[2]);
+ } else *reason_p = NULL;
}
+ close(fd);
}
}