[ 
https://issues.apache.org/jira/browse/TS-3245?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15285220#comment-15285220
 ] 

ASF GitHub Bot commented on TS-3245:
------------------------------------

Github user jpeach commented on the pull request:

    https://github.com/apache/trafficserver/pull/571#issuecomment-219535666
  
    ``0`` is a GNU extension behaviour, from the [man 
page](http://man7.org/linux/man-pages/man3/getopt.3.html):
    ```
    ... and wants to make use of GNU extensions such as '+' and '-' at the start
    of optstring, or changes the value of POSIXLY_CORRECT between scans,
    must reinitialize getopt() by resetting optind to 0, rather than the 
traditional
    value of 1.
    ```
    
    This is probably where the confusion originates, since for glibc either 
``0`` or ``1`` should work, depending on which part of the man page the author 
read. On non-gllibc, ``1`` is the only value that would work. AFAIK we don't 
have any plugins that use GNU extensions, so I recommend we reset ``optind`` to 
``1`` in the plugin loader so that plugins always get the right behaviour by 
default.


> getopt doesn't work correctly when used in plugin chaining
> ----------------------------------------------------------
>
>                 Key: TS-3245
>                 URL: https://issues.apache.org/jira/browse/TS-3245
>             Project: Traffic Server
>          Issue Type: Improvement
>          Components: Plugins
>    Affects Versions: 5.1.1
>            Reporter: Sudheer Vinukonda
>            Priority: Minor
>              Labels: newbie
>             Fix For: sometime
>
>
> When multiple plugins that use getopt are chained, it doesn't work correctly 
> for the subsequent plugins after the first plugin. [[email protected]] and 
> [~zwoop] suggested that the getopt globals need to be reset (example, 
> {{optind = opterr = optopt = 0}}) before using it and would be better to do 
> it in the core during plugin loading to keep it simple/transparent from 
> plugin development. 
> Note that, if a plugin itself uses getopt multiple times on different argv's, 
> it would have to reset the globals between them. 



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to