Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MTR_OPTIONS processed incorrectly #286

Closed
z-eos opened this issue Dec 31, 2018 · 3 comments
Closed

MTR_OPTIONS processed incorrectly #286

z-eos opened this issue Dec 31, 2018 · 3 comments

Comments

@z-eos
Copy link

z-eos commented Dec 31, 2018

in rc script, MTR_OPTIONS variable declared this way:
export MTR_OPTIONS='-4 -b -t -o "LSD NBAW V GMX" -z'

in shell, env(1) shows this:
MTR_OPTIONS=-4 -b -t -o "LSD NBAW V GMX" -z

but on attempt to mtr any address we get:
mtr: Unknown field identifier: "

so, it looks like mtr parses the option wrong way

@rewolff
Copy link
Collaborator

rewolff commented Jan 1, 2019

From the error message it looks as if mtr is seeing one of the double quotes.

You are supposed to pass the string "LSD NBAW V GMX" as a single string to MTR. But your shell would normally cut that string into pieces and pass them as separate arguments to MTR at the spaces. So that is why you put the quotes around.
So mtr should see: argv[4] = "-o";
that is: The argv[4] pointer points to an address with a - sign in it. The next one is a lower case o, and after that there is a 0 terminating the string.
Similarly argv[5] should be: "LSD NBAW V GMX", the pointer pointing directly at the 'L' and the X being followed by the terminating 0.

So specifying the string with spaces in it as an argument requires you to escape them from the shell.

However, when using this in mtr-options, things get a bit tricky: mtr has to do the parsing itself. At the moment it does not do the stuff with the quotes, so it blindly passes the string "LSD as the argument to the -o option.

Either we have to improve the split into separate chunks function ("parse_mtr_options" in the source) to handle the quotes. Or we have to do a workaround: You specify _ in the environment variable and that gets turned into a space in the code.

OK. Implemented the workaround.
Check the latest git. (in 5 minutes).

rewolff added a commit that referenced this issue Jan 1, 2019
@z-eos
Copy link
Author

z-eos commented Jan 1, 2019

confirm
it works

@rewolff rewolff closed this as completed Jan 1, 2019
@z-eos
Copy link
Author

z-eos commented Jan 2, 2019

patch provided by Sergey Poznyakoff (gray at gnu dot org dot ua) is attached

  • ui/mtr.c (parse_mtr_options): Correctly parse quoted arguments
    mtr.c.patch.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants