[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
find -fprint can open file twice for writing
From: |
Federico Mena Quintero |
Subject: |
find -fprint can open file twice for writing |
Date: |
Fri, 14 Nov 2008 13:07:05 -0600 |
Hi,
There's something that is not really a bug in find(1), but it can lead
to surprising/incorrect output.
I found a script that runs something like
find dirname -type f \
\( -name '*.foo' -fprint output1 \
-o -name '*.bar' -fprint output1 \
\) -o name '*.baz' -fprint output2
The problem is the two occurrences "-fprint output1". The find program
ends up opening output1 *twice*, and it writes to each separate file
descriptor when pred_fprint() runs. The result is that output1 ends up
with corrupted data as writes to both file descriptors race each other.
It turns out that fixing the culprit script is easy; I just moved the
fprint outside the parentheses.
However, I wonder if find(1) should detect this situation and either
print an error, or do the right thing and only open the file once.
Federico
- find -fprint can open file twice for writing,
Federico Mena Quintero <=