Commit 379268aa authored by Tom Lane's avatar Tom Lane

Proper fix for glibc getopt() botch. Surprising we did not see this

before.
parent 58f6b951
This diff is collapsed.
...@@ -985,6 +985,15 @@ if test x"$pgac_cv_var_int_optreset" = x"yes"; then ...@@ -985,6 +985,15 @@ if test x"$pgac_cv_var_int_optreset" = x"yes"; then
AC_DEFINE(HAVE_INT_OPTRESET, 1) AC_DEFINE(HAVE_INT_OPTRESET, 1)
fi fi
AC_CACHE_CHECK([for __getopt_initialized], pgac_cv_var_int___getopt_initialized,
[AC_TRY_LINK([#include <unistd.h>],
[extern int __getopt_initialized; __getopt_initialized = 1;],
[pgac_cv_var_int___getopt_initialized=yes],
[pgac_cv_var_int___getopt_initialized=no])])
if test x"$pgac_cv_var_int___getopt_initialized" = x"yes"; then
AC_DEFINE(HAVE_INT___GETOPT_INITIALIZED, 1)
fi
# This test makes sure that run tests work at all. Sometimes a shared # This test makes sure that run tests work at all. Sometimes a shared
# library is found by the linker, but the runtime linker can't find it. # library is found by the linker, but the runtime linker can't find it.
......
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.248 2001/10/19 18:19:41 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.249 2001/10/19 20:47:09 tgl Exp $
* *
* NOTES * NOTES
* *
...@@ -228,6 +228,9 @@ extern int optind, ...@@ -228,6 +228,9 @@ extern int optind,
#ifdef HAVE_INT_OPTRESET #ifdef HAVE_INT_OPTRESET
extern int optreset; extern int optreset;
#endif #endif
#ifdef HAVE_INT___GETOPT_INITIALIZED
extern int __getopt_initialized;
#endif
/* /*
* postmaster.c - function prototypes * postmaster.c - function prototypes
...@@ -355,7 +358,6 @@ PostmasterMain(int argc, char *argv[]) ...@@ -355,7 +358,6 @@ PostmasterMain(int argc, char *argv[])
} }
} }
/* /*
* for security, no dir or file created can be group or other * for security, no dir or file created can be group or other
* accessible * accessible
...@@ -422,12 +424,13 @@ PostmasterMain(int argc, char *argv[]) ...@@ -422,12 +424,13 @@ PostmasterMain(int argc, char *argv[])
} }
/* /*
* Non-option switch arguments don't exist. * Postmaster accepts no non-option switch arguments.
*/ */
if (optind < argc) if (optind < argc)
{ {
postmaster_error("invalid argument -- %s", argv[optind]); postmaster_error("invalid argument -- %s", argv[optind]);
fprintf(stderr, gettext("Try '%s --help' for more information.\n"), progname); fprintf(stderr, gettext("Try '%s --help' for more information.\n"),
progname);
ExitPostmaster(1); ExitPostmaster(1);
} }
...@@ -438,10 +441,15 @@ PostmasterMain(int argc, char *argv[]) ...@@ -438,10 +441,15 @@ PostmasterMain(int argc, char *argv[])
IgnoreSystemIndexes(false); IgnoreSystemIndexes(false);
optind = 1; /* start over (should be redundant here) */ /* reset getopt(3) to rescan arguments */
optind = 1;
#ifdef HAVE_INT_OPTRESET #ifdef HAVE_INT_OPTRESET
optreset = 1; optreset = 1; /* some systems need this */
#endif
#ifdef HAVE_INT___GETOPT_INITIALIZED
__getopt_initialized = 0; /* glibc needs this */
#endif #endif
while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF) while ((opt = getopt(argc, argv, "A:a:B:b:c:D:d:Fh:ik:lm:MN:no:p:Ss-:")) != EOF)
{ {
switch (opt) switch (opt)
...@@ -584,6 +592,20 @@ PostmasterMain(int argc, char *argv[]) ...@@ -584,6 +592,20 @@ PostmasterMain(int argc, char *argv[])
ExitPostmaster(1); ExitPostmaster(1);
} }
/*
* Now that we are done processing the postmaster arguments,
* reset getopt(3) library so that it will work correctly in
* subprocesses.
*/
optind = 1;
#ifdef HAVE_INT_OPTRESET
optreset = 1; /* some systems need this */
#endif
#ifdef HAVE_INT___GETOPT_INITIALIZED
__getopt_initialized = 0; /* glibc needs this */
#endif
/* For debugging: display postmaster environment */
if (DebugLvl > 2) if (DebugLvl > 2)
{ {
extern char **environ; extern char **environ;
...@@ -2179,11 +2201,6 @@ DoBackend(Port *port) ...@@ -2179,11 +2201,6 @@ 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
...@@ -2473,11 +2490,6 @@ SSDataBase(int xlop) ...@@ -2473,11 +2490,6 @@ SSDataBase(int xlop)
av[ac] = (char *) NULL; av[ac] = (char *) NULL;
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 @@
* or in pg_config.h afterwards. Of course, if you edit pg_config.h, then your * or in pg_config.h afterwards. Of course, if you edit pg_config.h, then your
* changes will be overwritten the next time you run configure. * changes will be overwritten the next time you run configure.
* *
* $Id: pg_config.h.in,v 1.9 2001/10/13 04:23:50 momjian Exp $ * $Id: pg_config.h.in,v 1.10 2001/10/19 20:47:09 tgl Exp $
*/ */
#ifndef PG_CONFIG_H #ifndef PG_CONFIG_H
...@@ -667,6 +667,9 @@ extern int fdatasync(int fildes); ...@@ -667,6 +667,9 @@ extern int fdatasync(int fildes);
/* Define if you have the optreset variable */ /* Define if you have the optreset variable */
#undef HAVE_INT_OPTRESET #undef HAVE_INT_OPTRESET
/* Define if you have the __getopt_initialized variable */
#undef HAVE_INT___GETOPT_INITIALIZED
/* Define if you have strtoll() */ /* Define if you have strtoll() */
#undef HAVE_STRTOLL #undef HAVE_STRTOLL
......
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