$ /usr/sbin/tor --ControlPortWriteToFile -f --ControlPort autoDec 04 16:16:22.230 [notice] Tor v0.2.3.8-alpha (git-da15c0cbd6638af3). This is experimental software. Do not rely on it for strong anonymity. (Running on Linux x86_64)Dec 04 16:16:22.232 [warn] Unable to open configuration file "--ControlPort".Dec 04 16:16:22.232 [err] Reading config failed--see warnings above.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Child items
0
Show closed items
No child items are currently assigned. Use child items to break down this issue into smaller parts.
Linked items
0
Link issues together to show that they're related.
Learn more.
When reading the configuration file name, I've added a check whether the file exists and if it does not and it starts with a '-' character the option is ignored. Basically I made a compromise between going through option_vars_ (O(N) algorithm) and simply discarding filenames starting with '-'.
I don't see how this code matches the description above. Where is the part that looks for a "-" character? (Also, that's not really a great idea. It is okay for a filename to start with a - character.)
It looks like you've removed support for logging "configuration file not present; using reasonable defaults.".
Finally, as written, this doesn't actually work. If I say "tor --ControlPortWriteToFile -f --ControlPort auto", then the key-value pairs should be ControlPortWriteToFile="-f" and ControlPort="auto", even if there is a file named ControlPort.
The right thing to do here is probably something like changing the way that config_get_commandlines() works so that instead of only returning a linked list of options in result, it also returns a list of the things that it currently skips. That way both torrc-option-on-the-commandline parsing (which uses config_get_commandlines), and commandline-only parsing (currently done in find_torrc_fname and elsewhere) would use the same rules for deciding what is an option and what is an argument.
Is this what you had in mind? Please don't waste too much time with this, just wanted to get some feedback before testing it more thoroughly. This version does exactly what you've said: "The right thing to do here is probably something like changing the way that config_get_commandlines() works so that instead of only returning a linked list of options in result, it also returns a list of the things that it currently skips. That way both torrc-option-on-the-commandline parsing (which uses config_get_commandlines), and commandline-only parsing (currently done in find_torrc_fname and elsewhere) would use the same rules for deciding what is an option and what is an argument."
I've combined ctoader's patches, added some fixups, and changes for #9578 (moved) and #9573 (moved) in branch "bug4647". It needs testing; writing some tests now.
ctoader liked an earlier version of this; now it has full integration tests. See "bug4647" in my public repo. I'll let anybody who wants to look at it look at it for while, then I'll merge it.
I told you I'd email back about #4647 (moved), I went through it again with the debugger and it looks good as it is. I wrote just a few notes on how I think things would be more robust.
The only drawback is that you cannot recover from a bad command such as "asdasd" which is treated as a command which also takes an argument so "asdad -f something.cfg" would pair the first 2 as key-value which would mess up the whole thing. Could be fixed, but most likely is not worth the effort, if config_parse_commandline() also validates each command, instead of having the commands validated in options_init_from_string(). This would also have to be done to options in conf files as well (in load_torrc_from_disk() maybe).
Also config_parse_commandline() can be called just once in tor_init() and have options_init_from_torrc() use the global_cmdline_options and cmdline_only_only set in tor_init(). In case SIGHUP is caught, options_init_from_torrc() doesn't need to re-parse the commandline, but it could if you check for argv == NULL.
I hope this helps, even if I didn't find any real issues!
I told you I'd email back about #4647 (moved), I went through it again with the debugger and it looks good as it is. I wrote just a few notes on how I think things would be more robust.
The only drawback is that you cannot recover from a bad command such as "asdasd" which is treated as a command which also takes an argument so "asdad -f something.cfg" would pair the first 2 as key-value which would mess up the whole thing. Could be fixed, but most likely is not worth the effort, if config_parse_commandline() also validates each command, instead of having the commands validated in options_init_from_string(). This would also have to be done to options in conf files as well (in load_torrc_from_disk() maybe).
Hm. I agree that error messages could be improved, but I don't think we're actually making matters worse with this patch. Previously, we'd get really confused by "tor asdad -f something.cfg", and happily read something.cfg, and then get confused by our inability to set "asdad -f", or something like that. I'll add another ticket for that when I merge this.
Also config_parse_commandline() can be called just once in tor_init() and have options_init_from_torrc() use the global_cmdline_options and cmdline_only_only set in tor_init(). In case SIGHUP is caught, options_init_from_torrc() doesn't need to re-parse the commandline, but it could if you check for argv == NULL.
I agree that this patch doesn't deliver on the actual text of the summary ("parse command line exactly once"), but it does fine in effect ("parse command line in exactly one way". I think that actually cacheing the result is probably needless.