#52 Basic command line parameters are sometimes ignored

v1.0_(example)
closed
nobody
None
5
2013-11-15
2013-09-18
Jan Breuer
No

This works

ptpd2 --interface eth0 --verbose -m --ptpengine:delay_mechanism=E2E

this ignores -m switch

ptpd2 --interface eth0 --verbose --ptpengine:delay_mechanism=E2E -m

Discussion

  • Wojciech Owczarek

    Jan, I think even the help text mentions that short options should be used first, and long options [key:option] after them.

    I think this condition may be the caused by the way I "remove" the key:value from argv - by setting it to "--"... this may not be the best solution.

    We would need to dump the argv before it gets to getopt() and see how it looks like at that stage in the second scenario you listed.

     
  • Jan Breuer

    Jan Breuer - 2013-09-23

    There is a problem with "--"

    From man page of getopt_long(3)

    The special argument "--" forces an end of option-scanning regardless of the scanning mode.

    Solution seems to be easy, dont replace arguments with "--" but with an emty string "". Is there any problem with this? It works for me.

    diff --git a/src/dep/daemonconfig.c b/src/dep/daemonconfig.c
    index 9b79fac..1aed4a1 100644
    --- a/src/dep/daemonconfig.c
    +++ b/src/dep/daemonconfig.c
    @@ -1852,7 +1852,7 @@ loadCommandLineKeys(dictionary* dict, int argc,char** argv)
            if (sscanf(argv[i],"--%[-_a-zA-Z0-9:]=%s",key,val)==2 ||
                sscanf(argv[i],"-%[-_a-zA-Z0-9:]=%s",key,val)==2) {
            /* wipe the used argv entry so that getopt doesn't get confused */
    -               argv[i]="--";
    +               argv[i]="";
                } else
            /*
             * there are no optional arguments for key:sec options - if there's no =,
    @@ -1860,13 +1860,13 @@ loadCommandLineKeys(dictionary* dict, int argc,char** argv)
             */
            if (sscanf(argv[i],"--%[-_a-zA-Z0-9:]",key)==1 ||
                sscanf(argv[i],"-%[-_a-zA-Z0-9:]",key)==1 ) {
    -               argv[i]="--";
    +               argv[i]="";
                    memset(val, 0, PATH_MAX);
                    if (i+1 < argc) {
                        if( (argv[i+1][0]!='-') &&
                            ( (strlen(argv[i+i]) > 1) && argv[i+1][1] !='-' )) {
                            strncpy(val,argv[i+1],PATH_MAX);
    -                       argv[i+1]="--";
    +                       argv[i+1]="";
                        }
    
                    }
    diff --git a/src/dep/startup.c b/src/dep/startup.c
    index 6bf3152..20ad97a 100644
    --- a/src/dep/startup.c
    +++ b/src/dep/startup.c
    @@ -482,7 +482,7 @@ void dump_command_line_parameters(int argc, char **argv)
    
            *st = '\0';
            for(i=0; i < argc; i++){
    -               if(strcmp(argv[i],"--") == 0)
    +               if(strcmp(argv[i],"") == 0)
                        continue;
                    len += snprintf(sbuf + len,
                                                 sizeof(sbuf) - len,
    
     
    Last edit: Jan Breuer 2013-09-23
  • Wojciech Owczarek

    Jan - yes, seems to work, I've just committed this. Again I had a reason for this but it escapes my memory what it was ;) - this works and that's what matters.

     
  • Wojciech Owczarek

    • status: open --> pending
     
  • Wojciech Owczarek

    • status: pending --> closed
     
  • Wojciech Owczarek

    Jan - I think this one can be closed?

     

Log in to post a comment.