OpenTTD

Tasklist

FS#6421 - Bogus open() syscalls when looking for openttd.cfg

Attached to Project: OpenTTD
Opened by Thomas Winwood (Ketsuban) - Thursday, 11 February 2016, 10:09 GMT
Last edited by Peter Nelson (peter1138) - Monday, 20 March 2017, 19:31 GMT
Type Bug
Category Core
Status Closed
Assigned To No-one
Operating System Linux
Severity Low
Priority Normal
Reported Version 1.5.3
Due in Version Undecided
Due Date Undecided
Percent Complete 100%
Votes 0
Private No

Details

I wanted OpenTTD on my PATH, so I symlinked the binary (in $HOME/.local/openttd) to $HOME/.local/bin and then ran it. At one point while debugging what I needed to do to make this work I used strace to track every instance in which OpenTTD used the open system call. These stood out to me.

open("/home/thomas//home/thomas/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/thomas/.openttd//home/thomas/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/share/games/openttd//home/thomas/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/thomas/.openttd/content_download//home/thomas/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/thomas/.openttd/openttd.cfg", O_RDONLY) = 3

From skimming the codebase I think this might be the result of a call to FioFindFullPath in fileio.cpp, but I could very well be wrong. Either way, I reckon bogus open syscalls are worthy of being filed as a low-severity bug.
This task depends upon

Closed by  Peter Nelson (peter1138)
Monday, 20 March 2017, 19:31 GMT
Reason for closing:  Fixed
Additional comments about closing:  In r27816
Comment by Alberth (Alberth) - Sunday, 28 February 2016, 08:34 GMT
Trying to just open a file at a number of places until you find the thing you are looking for is quite normal practice afaik.
What alternative would you suggest to find and read a file at an unknown location at the file system?
Comment by Peter Nelson (peter1138) - Monday, 13 March 2017, 22:25 GMT
We apparently already check for the cfg location earlier:

access("/home/petern/ottd/openttd.cfg", F_OK) = -1 ENOENT (No such file or directory)
access("/home/petern/.local/share/openttd/openttd.cfg", F_OK) = -1 ENOENT (No such file or directory)
access("/home/petern/.openttd/openttd.cfg", F_OK) = 0

Then later to actually open it, uses the chosen path but uses it in the search path:

open("/home/petern/ottd//home/petern/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/petern/.local/share/openttd//home/petern/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/petern/.openttd//home/petern/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/petern/ottd/bin//home/petern/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/local/share/games/openttd//home/petern/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/petern/.openttd/content_download//home/petern/.openttd/openttd.cfg", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/home/petern/.openttd/openttd.cfg", O_RDONLY) = 3

I'd say that is wrong in this case as we have already determined the path.
Comment by Peter Nelson (peter1138) - Monday, 13 March 2017, 22:46 GMT
This patch fixes it with hopefully no side effects. Ha! The three paths have already been determined on start up so no searching is necessary.

Loading...