Skip to content

Resolve "Kea might not use getopt correctly on alpine"

Closes #2788 (closed).

  • 11ad14d3 make all commandLineArgs tests more strict

  • 3571991e exhaust options before throwing error

    Prior to this change, if parseArgs() was called twice during the same program lifetime and it stumbled on an unsupported option and throwed an exception on the first call, the previous set of arguments lived on to be parsed by the second call. This is a situation that likely arises only in unit tests, but let us fix it properly to at least silence the unit test failure on alpine, which was happening because of different implementation of getopt from musl, and which motivated looking into how getopt behaves. To make the bug evident even in a non-alpine environment, add an EXPECT_THROW_MSG in DStubControllerTest.commandLineArgs when parsing argv3, and see that it outputs "unsupported option: [s]" instead of "extraneous command line information".

  • 22eb9978 reset optarg

    optarg is not reset in musl's getopt and it leaks values to other flags. Reset it for all systems because it cannot hurt. If you remove the optarg reset, you should see the bug in action on alpine systems in DstubControllerTest.commandLineArgs when parsing argv2:

    [ RUN      ] DStubControllerTest.commandLineArgs
    d_controller_unittests.cc:102: Failure
    Expected equality of these values:
      std::string(ex.what())
        Which is: "unsupported option: -b cfgName"
      "unsupported option: -b"
    [  FAILED  ] DStubControllerTest.commandLineArgs (14 ms)
Edited by Andrei Pavel

Merge request reports