Re: why was the VAR 'optind' never changed in initdb? - Mailing list pgsql-hackers

From Clover White
Subject Re: why was the VAR 'optind' never changed in initdb?
Date
Msg-id CAEwsEE7rEN13FK9jTfcksL5bRX4yenoeSxZpn8XQsU6PkvGUsw@mail.gmail.com
Whole thread Raw
In response to Re: why was the VAR 'optind' never changed in initdb?  (Andrew Dunstan <andrew@dunslane.net>)
Responses Re: why was the VAR 'optind' never changed in initdb?
List pgsql-hackers
<div class="gmail_quote">2012/4/9 Andrew Dunstan <span dir="ltr"><<a
href="mailto:andrew@dunslane.net">andrew@dunslane.net</a>></span><br/><blockquote class="gmail_quote"
style="margin:00 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br /><br /> On 04/09/2012 07:38
AM,Clover White wrote:<br /><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc
solid;padding-left:1ex">Hi,<br />  I'm debugging initdb using gdb.<br />  I found that I could not step in the function
getopt_longin line 2572 in initdb.c.<br />  I also found that the value of VAR optind never be changed. VAR optind is
alwaysequal to 1 but how could optind be larger than the value of argc(the value of argc is 6) in line 2648 and
2654.<br/><br /> I was so confused. Could someone give me some help? Thank you~<br /><br /><br /></blockquote><br
/></div>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.<br/><br /> cheers<br /><font color="#888888"><br /> andrew<br /></font></blockquote></div><br />Hi, this is my
story,it may be a little long :)<br />  I mistook the parameter -W of initdb at the first time and used it like
this:<br/>    initdb -U pgsql -W 12345 -D /home/pgsql/pg_data<br />   And I found the database was not created in the
rightdirectory, but I could not find a log file to find out why.<br />  So, I debug initdb and found out I have mistook
theparameter -W, I should use it like this:<br />    initdb -U pgsql -W -D /home/pgsql/pg_data<br />     <br /> 
however,when I debug initdb.c, VAR optind was supported to increased after getopt_long pasered every parameter,<br /> 
butit was alway equal to 1.<br />  <br />  And there is a segment of initdb.c.<br />    if (optind < argc)<br />    
 {<br />          do something statement<br />      }  <br />  <br />  I print the value of optind and argc:<div
class="im"><br/>    (gdb) p optind<br />    $11 = 1<br />    (gdb) p argc<br />    $12 = 6<br />  <br /></div>  optind
isobvious less than argc, but the statement above do not excute at all.<br />   <br />  QUESTION:<br />    1.why does
thestatement above not excute?<br />    2.why is optind always equal to 1? <br clear="all" /><br />-- <br />Clover
White<br/><br /> 

pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: Deprecating non-select rules (was Re: Last gasp)
Next
From: Merlin Moncure
Date:
Subject: Re: [JDBC] Regarding GSoc Application