Re: why was the VAR 'optind' never changed in initdb?

From: Clover White <mywhiteclover(at)gmail(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: why was the VAR 'optind' never changed in initdb?
Date: 2012-04-09 16:36:07
Message-ID: CAEwsEE7rEN13FK9jTfcksL5bRX4yenoeSxZpn8XQsU6PkvGUsw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

2012/4/9 Andrew Dunstan <andrew(at)dunslane(dot)net>

>
>
> On 04/09/2012 07:38 AM, Clover White wrote:
>
>> Hi,
>> I'm debugging initdb using gdb.
>> I found that I could not step in the function getopt_long in line 2572
>> in initdb.c.
>> I also found that the value of VAR optind never be changed. VAR optind
>> is always equal to 1 but how could optind be larger than the value of
>> argc(the value of argc is 6) in line 2648 and 2654.
>>
>> I was so confused. Could someone give me some help? Thank you~
>>
>>
>>
> Why do you expect it to be? Perhaps if you tell us what problem you're
> actually trying to solve we can help you better.
>
> cheers
>
> andrew
>

Hi, this is my story, it may be a little long :)
I mistook the parameter -W of initdb at the first time and used it like
this:
initdb -U pgsql -W 12345 -D /home/pgsql/pg_data
And I found the database was not created in the right directory, but I
could not find a log file to find out why.
So, I debug initdb and found out I have mistook the parameter -W, I
should use it like this:
initdb -U pgsql -W -D /home/pgsql/pg_data

however, when I debug initdb.c, VAR optind was supported to increased
after getopt_long pasered every parameter,
but it was alway equal to 1.

And there is a segment of initdb.c.
if (optind < argc)
{
do something statement
}

I print the value of optind and argc:

(gdb) p optind
$11 = 1
(gdb) p argc
$12 = 6

optind is obvious less than argc, but the statement above do not excute
at all.

QUESTION:
1.why does the statement above not excute?
2.why is optind always equal to 1?

--
Clover White

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Merlin Moncure 2012-04-09 16:37:38 Re: [JDBC] Regarding GSoc Application
Previous Message Robert Haas 2012-04-09 16:28:20 Re: Deprecating non-select rules (was Re: Last gasp)