BUG #3054: getopt_long () misbehaviour

From: "Tux" <h(dot)m(dot)brand(at)xs4all(dot)nl>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3054: getopt_long () misbehaviour
Date: 2007-02-22 13:36:00
Message-ID: 200702221336.l1MDa0rs097431@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3054
Logged by: Tux
Email address: h(dot)m(dot)brand(at)xs4all(dot)nl
PostgreSQL version: 8.2.3
Operating system: HP-UX 11.00
Description: getopt_long () misbehaviour
Details:

Might be some deep down misbehaving system library, but on HP-UX 11.00 (not
on 11.11, and/or 11.23) getopt_long () misbehaves in that it causes all
command line utilities to se the program name as the first argument, causing
a simple command like

# psql test

to be executed as

# psql psql test

The very first command already shows this misbehaviour, as

# initdb

does not create $PGDATA/*, but ./initdb as DB environment files. D'uh!

Patch below, also available on http://www.xs4all.nl/~procura/psql823.diff
All now runs fine:

--8<---
diff -pur postgresql-8.2.3/src/bin/initdb/initdb.c
postgresql-8.2.3-pro/src/bin/initdb/initdb.c
--- postgresql-8.2.3/src/bin/initdb/initdb.c 2006-10-04 20:58:08 +0200
+++ postgresql-8.2.3-pro/src/bin/initdb/initdb.c 2007-02-22 14:18:25
+0100
@@ -2440,6 +2440,7 @@ main(int argc, char *argv[])

/* process command-line options */

+ optind = 1;
while ((c = getopt_long(argc, argv, "dD:E:L:nU:WA:s", long_options,
&option_index)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/pg_dump/pg_dump.c
postgresql-8.2.3-pro/src/bin/pg_dump/pg_dump.c
--- postgresql-8.2.3/src/bin/pg_dump/pg_dump.c 2006-10-10 01:36:59 +0200
+++ postgresql-8.2.3-pro/src/bin/pg_dump/pg_dump.c 2007-02-22 14:18:47
+0100
@@ -296,6 +296,7 @@ main(int argc, char **argv)
}
}

+ optind = 1;
while ((c = getopt_long(argc, argv,
"abcCdDE:f:F:h:in:N:oOp:RsS:t:T:uU:vWxX:Z:",
long_options,
&optindex)) != -1)
{
diff -pur postgresql-8.2.3/src/bin/pg_dump/pg_dumpall.c
postgresql-8.2.3-pro/src/bin/pg_dump/pg_dumpall.c
--- postgresql-8.2.3/src/bin/pg_dump/pg_dumpall.c 2006-11-21 23:19:46
+0100
+++ postgresql-8.2.3-pro/src/bin/pg_dump/pg_dumpall.c 2007-02-22 14:18:52
+0100
@@ -161,6 +161,7 @@ main(int argc, char *argv[])

pgdumpopts = createPQExpBuffer();

+ optind = 1;
while ((c = getopt_long(argc, argv, "acdDgh:ioOp:sS:U:vWxX:",
long_options, &optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/pg_dump/pg_restore.c
postgresql-8.2.3-pro/src/bin/pg_dump/pg_restore.c
--- postgresql-8.2.3/src/bin/pg_dump/pg_restore.c 2006-10-15 01:07:22
+0200
+++ postgresql-8.2.3-pro/src/bin/pg_dump/pg_restore.c 2007-02-22 14:19:08
+0100
@@ -137,6 +137,7 @@ main(int argc, char **argv)
}
}

+ optind = 1;
while ((c = getopt_long(argc, argv,
"acCd:ef:F:h:iI:lL:n:Op:P:RsS:t:T:uU:vWxX:1",
cmdopts, NULL)) !=
-1)
{
diff -pur postgresql-8.2.3/src/bin/psql/startup.c
postgresql-8.2.3-pro/src/bin/psql/startup.c
--- postgresql-8.2.3/src/bin/psql/startup.c 2006-10-04 02:30:06 +0200
+++ postgresql-8.2.3-pro/src/bin/psql/startup.c 2007-02-22 14:19:17 +0100
@@ -451,6 +450,7 @@ parse_psql_options(int argc, char *argv[

memset(options, 0, sizeof *options);

+ optind = 1;
while ((c = getopt_long(argc, argv,
"aAc:d:eEf:F:h:HlL:no:p:P:qR:sStT:uU:v:VWxX?1",
long_options,
&optindex)) != -1)
{
diff -pur postgresql-8.2.3/src/bin/scripts/clusterdb.c
postgresql-8.2.3-pro/src/bin/scripts/clusterdb.c
--- postgresql-8.2.3/src/bin/scripts/clusterdb.c 2006-03-05 16:58:52
+0100
+++ postgresql-8.2.3-pro/src/bin/scripts/clusterdb.c 2007-02-22 14:19:28
+0100
@@ -60,6 +60,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "clusterdb", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "h:p:U:Weqd:at:", long_options,
&optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/scripts/createdb.c
postgresql-8.2.3-pro/src/bin/scripts/createdb.c
--- postgresql-8.2.3/src/bin/scripts/createdb.c 2006-06-01 02:15:36 +0200
+++ postgresql-8.2.3-pro/src/bin/scripts/createdb.c 2007-02-22 14:19:33
+0100
@@ -64,6 +64,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "createdb", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "h:p:U:WeqO:D:T:E:",
long_options, &optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/scripts/createlang.c
postgresql-8.2.3-pro/src/bin/scripts/createlang.c
--- postgresql-8.2.3/src/bin/scripts/createlang.c 2006-07-14 16:52:27
+0200
+++ postgresql-8.2.3-pro/src/bin/scripts/createlang.c 2007-02-22 14:19:39
+0100
@@ -56,6 +56,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "createlang", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "lh:p:U:Wd:e", long_options,
&optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/scripts/createuser.c
postgresql-8.2.3-pro/src/bin/scripts/createuser.c
--- postgresql-8.2.3/src/bin/scripts/createuser.c 2006-10-04 02:30:06
+0200
+++ postgresql-8.2.3-pro/src/bin/scripts/createuser.c 2007-02-22 14:19:43
+0100
@@ -86,6 +86,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "createuser", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "h:p:U:WeqdDsSaArRiIlLc:PEN",
long_options,
&optindex)) != -1)
{
diff -pur postgresql-8.2.3/src/bin/scripts/dropdb.c
postgresql-8.2.3-pro/src/bin/scripts/dropdb.c
--- postgresql-8.2.3/src/bin/scripts/dropdb.c 2006-09-22 20:50:41 +0200
+++ postgresql-8.2.3-pro/src/bin/scripts/dropdb.c 2007-02-22 14:19:45
+0100
@@ -55,6 +55,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "dropdb", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "h:p:U:Weqi", long_options,
&optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/scripts/droplang.c
postgresql-8.2.3-pro/src/bin/scripts/droplang.c
--- postgresql-8.2.3/src/bin/scripts/droplang.c 2006-05-31 13:02:42 +0200
+++ postgresql-8.2.3-pro/src/bin/scripts/droplang.c 2007-02-22 14:19:47
+0100
@@ -67,6 +67,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "droplang", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "lh:p:U:Wd:e", long_options,
&optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/scripts/dropuser.c
postgresql-8.2.3-pro/src/bin/scripts/dropuser.c
--- postgresql-8.2.3/src/bin/scripts/dropuser.c 2006-09-22 20:50:41 +0200
+++ postgresql-8.2.3-pro/src/bin/scripts/dropuser.c 2007-02-22 14:19:48
+0100
@@ -55,6 +55,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "dropuser", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "h:p:U:Weqi", long_options,
&optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/scripts/reindexdb.c
postgresql-8.2.3-pro/src/bin/scripts/reindexdb.c
--- postgresql-8.2.3/src/bin/scripts/reindexdb.c 2006-09-02 19:10:17
+0200
+++ postgresql-8.2.3-pro/src/bin/scripts/reindexdb.c 2007-02-22 14:19:52
+0100
@@ -70,6 +70,7 @@ main(int argc, char *argv[])
handle_help_version_opts(argc, argv, "reindexdb", help);

/* process command-line options */
+ optind = 1;
while ((c = getopt_long(argc, argv, "h:p:U:Weqd:ast:i:",
long_options, &optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/bin/scripts/vacuumdb.c
postgresql-8.2.3-pro/src/bin/scripts/vacuumdb.c
--- postgresql-8.2.3/src/bin/scripts/vacuumdb.c 2006-03-05 16:58:52 +0100
+++ postgresql-8.2.3-pro/src/bin/scripts/vacuumdb.c 2007-02-22 14:19:54
+0100
@@ -68,6 +68,7 @@ main(int argc, char *argv[])

handle_help_version_opts(argc, argv, "vacuumdb", help);

+ optind = 1;
while ((c = getopt_long(argc, argv, "h:p:U:Weqd:zat:fv",
long_options, &optindex)) != -1)
{
switch (c)
diff -pur postgresql-8.2.3/src/test/regress/pg_regress.c
postgresql-8.2.3-pro/src/test/regress/pg_regress.c
--- postgresql-8.2.3/src/test/regress/pg_regress.c 2006-10-04 02:30:14
+0200
+++ postgresql-8.2.3-pro/src/test/regress/pg_regress.c 2007-02-22 14:20:09
+0100
@@ -1351,6 +1351,7 @@ main(int argc, char *argv[])
hostname = "localhost";
#endif

+ optind = 1;
while ((c = getopt_long(argc, argv, "hV", long_options,
&option_index)) != -1)
{
switch (c)
-->8---

Enjoy, Have FUN! H.Merijn
perl5-porter

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Feng Chen 2007-02-22 16:41:59 Re: pg_dump and truncate
Previous Message brian blakey 2007-02-22 10:08:48 BUG #3052: Inconsistent results from PQexec... with rules