Commit 861a679f authored by Tom Lane's avatar Tom Lane

Set optreset on platforms that have it before launching postmaster

subprocesses; perhaps this will fix portability problem just noted by
Lockhart.  Also, move test for bad permissions of DataDir to a more
logical place.
parent 6430e6e2
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.247 2001/10/19 17:03:08 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.248 2001/10/19 18:19:41 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -275,6 +275,7 @@ checkDataDir(const char *checkdir) ...@@ -275,6 +275,7 @@ checkDataDir(const char *checkdir)
{ {
char path[MAXPGPATH]; char path[MAXPGPATH];
FILE *fp; FILE *fp;
struct stat stat_buf;
if (checkdir == NULL) if (checkdir == NULL)
{ {
...@@ -287,6 +288,22 @@ checkDataDir(const char *checkdir) ...@@ -287,6 +288,22 @@ checkDataDir(const char *checkdir)
ExitPostmaster(2); ExitPostmaster(2);
} }
/*
* Check if the directory has group or world access. If so, reject.
*/
if (stat(checkdir, &stat_buf) == -1)
{
if (errno == ENOENT)
elog(FATAL, "data directory %s was not found", checkdir);
else
elog(FATAL, "could not read permissions of directory %s: %m",
checkdir);
}
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)",
checkdir);
/* Look for PG_VERSION before looking for pg_control */ /* Look for PG_VERSION before looking for pg_control */
ValidatePgVersion(checkdir); ValidatePgVersion(checkdir);
...@@ -421,7 +438,7 @@ PostmasterMain(int argc, char *argv[]) ...@@ -421,7 +438,7 @@ PostmasterMain(int argc, char *argv[])
IgnoreSystemIndexes(false); IgnoreSystemIndexes(false);
optind = 1; /* start over */ optind = 1; /* start over (should be redundant here) */
#ifdef HAVE_INT_OPTRESET #ifdef HAVE_INT_OPTRESET
optreset = 1; optreset = 1;
#endif #endif
...@@ -2162,6 +2179,11 @@ DoBackend(Port *port) ...@@ -2162,6 +2179,11 @@ DoBackend(Port *port)
av[ac] = (char *) NULL; av[ac] = (char *) NULL;
optind = 1; /* reset getopt(3) for subprocess */
#ifdef HAVE_INT_OPTRESET
optreset = 1;
#endif
/* /*
* Release postmaster's working memory context so that backend can * Release postmaster's working memory context so that backend can
* recycle the space. Note this does not trash *MyProcPort, because * recycle the space. Note this does not trash *MyProcPort, because
...@@ -2451,7 +2473,10 @@ SSDataBase(int xlop) ...@@ -2451,7 +2473,10 @@ SSDataBase(int xlop)
av[ac] = (char *) NULL; av[ac] = (char *) NULL;
optind = 1; optind = 1; /* reset getopt(3) for subprocess */
#ifdef HAVE_INT_OPTRESET
optreset = 1;
#endif
BootstrapMain(ac, av); BootstrapMain(ac, av);
ExitPostmaster(0); ExitPostmaster(0);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.236 2001/10/19 17:03:08 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.237 2001/10/19 18:19:41 tgl Exp $
* *
* NOTES * NOTES
* this is the "main" module of the postgres backend and * this is the "main" module of the postgres backend and
...@@ -1192,8 +1192,6 @@ PostgresMain(int argc, char *argv[], ...@@ -1192,8 +1192,6 @@ PostgresMain(int argc, char *argv[],
secure = true; secure = true;
ctx = PGC_POSTMASTER; ctx = PGC_POSTMASTER;
optind = 1; /* reset after postmaster's usage */
while ((flag = getopt(argc, argv, "A:B:c:CD:d:Eef:FiNOPo:p:S:st:v:W:x:-:")) != EOF) while ((flag = getopt(argc, argv, "A:B:c:CD:d:Eef:FiNOPo:p:S:st:v:W:x:-:")) != EOF)
switch (flag) switch (flag)
{ {
...@@ -1651,7 +1649,7 @@ PostgresMain(int argc, char *argv[], ...@@ -1651,7 +1649,7 @@ PostgresMain(int argc, char *argv[],
if (!IsUnderPostmaster) if (!IsUnderPostmaster)
{ {
puts("\nPOSTGRES backend interactive interface "); puts("\nPOSTGRES backend interactive interface ");
puts("$Revision: 1.236 $ $Date: 2001/10/19 17:03:08 $\n"); puts("$Revision: 1.237 $ $Date: 2001/10/19 18:19:41 $\n");
} }
/* /*
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.79 2001/10/19 17:03:08 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.80 2001/10/19 18:19:41 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -120,7 +120,6 @@ void ...@@ -120,7 +120,6 @@ void
SetDataDir(const char *dir) SetDataDir(const char *dir)
{ {
char *new; char *new;
struct stat stat_buf;
AssertArg(dir); AssertArg(dir);
...@@ -164,17 +163,6 @@ SetDataDir(const char *dir) ...@@ -164,17 +163,6 @@ SetDataDir(const char *dir)
elog(FATAL, "out of memory"); elog(FATAL, "out of memory");
} }
/*
* Check if the directory has group or world access. If so, reject.
*/
if (stat(new, &stat_buf) == -1)
elog(FATAL, "could not read permissions of directory %s: %s",
new, strerror(errno));
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)",
new);
if (DataDir) if (DataDir)
free(DataDir); free(DataDir);
DataDir = new; DataDir = new;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment