2012/4/9 Andrew Dunstan <[email protected]>
>
>
> 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