From: prj@po.cwru.edu (Paul Jarc)
Date: Fri, 09 Aug 2002 14:25:20 -0400
Derek Robert Price <derek@ximbiot.com> wrote:
I assume they have different file table entries in the kernel
because stderr can be set to nonblock without doing the same to
stdout. I need to know when the two file descriptors point to the
same file table entry (i.e. $ cvs <whatever> 2>&1).
Ah. So frob the flags on one of them and see if the other one changes
too; then restore the original flags. This still isn't perfect, for
the same reason that the problem exists: another process with a copy
of the same descriptor could be messing around with flags at the same
time. But that seems unlikely in the cases where the problem appears.
Since (as you mention) this optimization isn't safe, then I wouldn't
do it. For this particular application, it's just an optimization to
check for the same file table entries; it's OK to omit the
optimization if it isn't safe.
In contrast, the st_dev+st_ino optimization is safe, since it doesn't
make any assumptions about what other processes are doing.