Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 861a679

Browse files
committed
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.
1 parent 6430e6e commit 861a679

File tree

3 files changed

+31
-20
lines changed

3 files changed

+31
-20
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.247 2001/10/19 17:03:08 tgl Exp $
40+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.248 2001/10/19 18:19:41 tgl Exp $
4141
*
4242
* NOTES
4343
*
@@ -275,6 +275,7 @@ checkDataDir(const char *checkdir)
275275
{
276276
char path[MAXPGPATH];
277277
FILE *fp;
278+
struct stat stat_buf;
278279

279280
if (checkdir == NULL)
280281
{
@@ -286,6 +287,22 @@ checkDataDir(const char *checkdir)
286287
progname);
287288
ExitPostmaster(2);
288289
}
290+
291+
/*
292+
* Check if the directory has group or world access. If so, reject.
293+
*/
294+
if (stat(checkdir, &stat_buf) == -1)
295+
{
296+
if (errno == ENOENT)
297+
elog(FATAL, "data directory %s was not found", checkdir);
298+
else
299+
elog(FATAL, "could not read permissions of directory %s: %m",
300+
checkdir);
301+
}
302+
303+
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
304+
elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)",
305+
checkdir);
289306

290307
/* Look for PG_VERSION before looking for pg_control */
291308
ValidatePgVersion(checkdir);
@@ -421,7 +438,7 @@ PostmasterMain(int argc, char *argv[])
421438

422439
IgnoreSystemIndexes(false);
423440

424-
optind = 1; /* start over */
441+
optind = 1; /* start over (should be redundant here) */
425442
#ifdef HAVE_INT_OPTRESET
426443
optreset = 1;
427444
#endif
@@ -2162,6 +2179,11 @@ DoBackend(Port *port)
21622179

21632180
av[ac] = (char *) NULL;
21642181

2182+
optind = 1; /* reset getopt(3) for subprocess */
2183+
#ifdef HAVE_INT_OPTRESET
2184+
optreset = 1;
2185+
#endif
2186+
21652187
/*
21662188
* Release postmaster's working memory context so that backend can
21672189
* recycle the space. Note this does not trash *MyProcPort, because
@@ -2451,7 +2473,10 @@ SSDataBase(int xlop)
24512473

24522474
av[ac] = (char *) NULL;
24532475

2454-
optind = 1;
2476+
optind = 1; /* reset getopt(3) for subprocess */
2477+
#ifdef HAVE_INT_OPTRESET
2478+
optreset = 1;
2479+
#endif
24552480

24562481
BootstrapMain(ac, av);
24572482
ExitPostmaster(0);

src/backend/tcop/postgres.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.236 2001/10/19 17:03:08 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.237 2001/10/19 18:19:41 tgl Exp $
1212
*
1313
* NOTES
1414
* this is the "main" module of the postgres backend and
@@ -1192,8 +1192,6 @@ PostgresMain(int argc, char *argv[],
11921192
secure = true;
11931193
ctx = PGC_POSTMASTER;
11941194

1195-
optind = 1; /* reset after postmaster's usage */
1196-
11971195
while ((flag = getopt(argc, argv, "A:B:c:CD:d:Eef:FiNOPo:p:S:st:v:W:x:-:")) != EOF)
11981196
switch (flag)
11991197
{
@@ -1651,7 +1649,7 @@ PostgresMain(int argc, char *argv[],
16511649
if (!IsUnderPostmaster)
16521650
{
16531651
puts("\nPOSTGRES backend interactive interface ");
1654-
puts("$Revision: 1.236 $ $Date: 2001/10/19 17:03:08 $\n");
1652+
puts("$Revision: 1.237 $ $Date: 2001/10/19 18:19:41 $\n");
16551653
}
16561654

16571655
/*

src/backend/utils/init/miscinit.c

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.79 2001/10/19 17:03:08 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.80 2001/10/19 18:19:41 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -120,7 +120,6 @@ void
120120
SetDataDir(const char *dir)
121121
{
122122
char *new;
123-
struct stat stat_buf;
124123

125124
AssertArg(dir);
126125

@@ -163,17 +162,6 @@ SetDataDir(const char *dir)
163162
if (!new)
164163
elog(FATAL, "out of memory");
165164
}
166-
167-
/*
168-
* Check if the directory has group or world access. If so, reject.
169-
*/
170-
if (stat(new, &stat_buf) == -1)
171-
elog(FATAL, "could not read permissions of directory %s: %s",
172-
new, strerror(errno));
173-
174-
if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
175-
elog(FATAL, "data directory %s has group or world access; permissions should be u=rwx (0700)",
176-
new);
177165

178166
if (DataDir)
179167
free(DataDir);

0 commit comments

Comments
 (0)