coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mktemp's access mode and inotify


From: David Thomas
Subject: mktemp's access mode and inotify
Date: Thu, 12 May 2011 11:05:12 -0700

So I've come across something I think is interesting, and may turn
into an associated bug report / feature request / patch, but I am
wondering first just generally what people's thoughts are.

It specifically has to do with how mktemp plays with inotify.  Since
mkstemp opens the file with the write bit set (or, well, technically
unset - but "able to read") when the file is closed inotify receives a
IN_CLOSE_WRITE event on the directory.  This seems redundant: any
process watching the directory will also be receiving a IN_CLOSE and
IN_CREATE if it is interested in the fact that the file was created or
closed, and we don't actually use that descriptor for writing.
Dropping write access from the open would allow:

filename=$(mktemp --tmpdir=$some_dir_being_watched)
(
   echo stuff
   echo to
   echo write
   echo to
   echo file
) > $filename

to play well, ensuring that a process listening for IN_CLOSE_WRITE
only sees a file once it is complete (absent error, which must be
handled correctly - but we're avoiding any chance of catching the file
incomplete-but-still-to-be-completed, as well as a spurious wakeup of
the listening process).

I'm not at all certain this won't break anything anywhere else, or
work on all environments, however - thoughts?

An alternative might be some magic to keep the file descriptor open -
but I'm not sure if/how that might work.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]