Tom Lane píše v so 28. 03. 2009 v 14:36 -0400:

> Apparently the system version of getopt_long is broken on Solaris 11.
> My patience for this grows short.

It is not problem with getopt_long itself, but with symbol overriding.
getopt_long uses optind and so on from libc, but e.g. initdb takes
optind which is defined in port/getopt.c. It causes problem in following
code:

02607     /* Non-option argument specifies data directory */
02608     if (optind < argc)

which compares different variable.

I think it is general problem. HAVE_GETOPT_LONG cannot be defined when
HAVE_GETOPT_H is not defined.

I'm sorry for my previous patch. I had to make some mistake in
autoconf/make magic.

I attached a fix. Only problem what I see there is getopt_long.h which
contains 

#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif

but getopt.h is required for getopt_long(). Fortunately, content is
similar with getopt_long.h and there is no problem with it on Solaris.

                Zdenek



*** pgsql.orig.2ecfaec29a72/src/port/getopt.c	2009-03-30 22:06:31.183510859 +0200
--- pgsql.orig/src/port/getopt.c	2009-03-30 21:34:04.697048053 +0200
***************
*** 36,47 ****
  static char sccsid[] = "@(#)getopt.c	8.3 (Berkeley) 4/27/95";
  #endif   /* LIBC_SCCS and not lint */
  
! 
! int			opterr = 1,			/* if error message should be printed */
! 			optind = 1,			/* index into parent argv vector */
! 			optopt,				/* character checked for validity */
! 			optreset;			/* reset getopt */
  char	   *optarg;				/* argument associated with option */
  
  #define BADCH	(int)'?'
  #define BADARG	(int)':'
--- 36,52 ----
  static char sccsid[] = "@(#)getopt.c	8.3 (Berkeley) 4/27/95";
  #endif   /* LIBC_SCCS and not lint */
  
! /* In situation when we use getopt_long from libc, we needs to use libc variable,
!  * else it causes symbol overriding and optind contains nonsens. 
!  */ 
! #ifndef HAVE_GETOPT_LONG
! int			opterr = 1;			/* if error message should be printed */
! int			optind = 1;			/* index into parent argv vector */
! int			optopt;				/* character checked for validity */
  char	   *optarg;				/* argument associated with option */
+ #endif
+ static int	optreset;			/* reset getopt */
+ 
  
  #define BADCH	(int)'?'
  #define BADARG	(int)':'
-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to