QNX (Neutrino 6.5.0) uses an open source implementation of ksh as its shell. A lot of the provided scripts, including the system startup scripts, use constructs such as
if ! test /dev/slog -ef /dev/slog; then
# do something
fi
to check whether a resource manager exists or not in the filesystem. I've searched and could only find very dray explanations that -ef
checks to see whether the two parameters are in fact the same file. Since the filename specified is the same it seems to just reduce to checking that the file exists.
I have checked the behaviour of test -a
and test -e
(both seem to check for file existance of any type of file according to the various docs I've read) and they seem to also work.
Is there any difference in the checks performed between -ef
and -a
/-e
? Is using -ef
some kind of attempt to protect against a race condition in the existence of the file?
test
since it is part of the initial system startup script. In the normal case of /dev/slog a process can write to the device to log to a file/console/memory, and while it may end up with a different filename, the device exposed in /dev should be the same as before the write to /dev/slog. – Infatuationtest
) is completed, the file/device is removed/replaced by the driver -- thus causing the second stat() to get different information, in turn causing thetest
to fail. It's been a while since I've used QNX, but the slogger man page suggests there are side effects from interacting with /dev/slog (e.g., unlinking it purges the log). – Storetest -a
andtest -e
are relatively new. At one point, they don't seem to have been part of the Posix shell that was in use by QNX (see qnx.com/developers/docs/qnx_4.25_docs/qnx4/utils/s/sh.html . So I now suspect that this is just a legacy pattern. – Store