Thanks,
Nordlöw
Going by what's stated in the new POSIX standard the purpose of
these new functions is neither performance nor convenience but
the avoidance of race conditions. If you use fstat() on a file
in a different directory than the current working directory and
then open() it (relying on the results of fstat()), another pro-
cess could have changed in between where the path leads to, so
instead of opening the file you called fstat() on you might be
tricked into opening a completely different one. I.e. let's say
you call fstat() on
/foo/bar/a.txt
and now another process gets in between and does
mv /foo/bar /foo/baz
mkdir /foo/bar
cp something_bad.txt /foo/bar/a.txt
then you would not open the file you had tested with fstat()
but the file just created by the other process. And that (at
least as far as I understand it at the momente) is what can
be avoided by using these new functions since you don't spe-
cify the path to the file by name but with respect to the file
descriptor for the directory (which isn't changed on renaming).
Regards, Jens
--
\ Jens Thoms Toerring ___ j...@toerring.de
\__________________________ http://toerring.de
> Going by what's stated in the new POSIX standard the purpose of
> these new functions is neither performance nor convenience but
> the avoidance of race conditions. If you use fstat() on a file
> in a different directory than the current working directory and
> then open() it (relying on the results of fstat()), another pro-
> cess could have changed in between where the path leads to, so
> instead of opening the file you called fstat() on you might be
> tricked into opening a completely different one. I.e. let's say
[snip]
To put it more simply, functions like 'fstatat', 'openat', and the
ability to open a directory and get a file descriptor for it provide a
way to have a sequence of operations that all definitely refer to the
same directory.
They also provide a way for a process to have more than one equivalent
of a current working directory and they provide a way to pass a
working directory to a function. This can be especially useful in
multi-threaded processes.
DS
Superb answers!
I am grateful!
/Nordlöw