bug-coreutils
[Top][All Lists]
Advanced

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

bug#12366: [gnu-prog-discuss] Writing unwritable files


From: Paul Eggert
Subject: bug#12366: [gnu-prog-discuss] Writing unwritable files
Date: Thu, 06 Sep 2012 11:23:21 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0

On 09/06/2012 10:35 AM, Bernhard Voelker wrote:
> Why can't 'sed -i' be made atomic for the user?
> Today, it creates a temporary file for the output.
> At the end, it calls rename(). What if it instead
> rewinds the input and that temporary file and copies
> it's content to the input file?

That's kind of what 'sort -o' does, and it also
has race conditions.  For example, in that last phase
while it's copying the content to the input file, some other
process might be reading the input file.

There is no good general and portable atomic solution to
this sort of problem, not in POSIX anyway.  Practical
implementations of utilities like 'sed' and 'sort'
and 'shuf' all involve races of some sort or another.





reply via email to

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