From: "Pádraig Brady" <P@draigBrady.com>
To: Denys Vlasenko <vda.linux@googlemail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>,
Christian Engelmayer <christian.engelmayer@frequentis.com>,
Coreutils <coreutils@gnu.org>
Subject: Re: rename("a", "b") would not always remove "a" on success. ?!!
Date: Fri, 28 Oct 2011 16:32:00 +0100 [thread overview]
Message-ID: <4EAACAF0.4030401@draigBrady.com> (raw)
In-Reply-To: <CAK1hOcN1ocnFh+HJWMONbUmoGtnxGvfrkxjRVs8zNmurz1xdrA@mail.gmail.com>
On 10/28/2011 04:25 PM, Denys Vlasenko wrote:
> Hi,
>
> One of my users stumbled over a problem when power failure
> hit his system at rename() and the filesystem he uses
> (I don't know which) ended up having both old and new
> file names in the directory. Basically, he ended up with
> one file with two hardlinks pointing to it.
>
> IOW: the scenario does not require unlucky power offs
> to reproduce, just "ln a b" would do.
>
> In his case these two particular hardlinks were pointing
> to rotated log files.
>
> When system restarted, it eventually tried to rotate files
> again, via rename("a", "b").
> rename succeeded, but since they are hardlinks, rename
> did NOT remove "a".
> Which made the logger process very confused.
>
>
> The user dug into it and discovered that SUS actually
> specifies this insane behavior:
>
> http://pubs.opengroup.org/onlinepubs/9699919799/functions/rename.html
>
> 'If the old argument and the new argument resolve to either .... or different
> directory entries for the same existing file, rename() shall return
> successfully and perform no other action.'
>
> It's incredible they had audacity to put such nonsense into standard.
>
> The page says in "RATIONALE" section:
>
> 'The specification that if old and new refer to the same file is
> intended to guarantee that:
>
> rename("x", "x");
>
> does not remove the file.'
>
> Why didn't they just explicitly say that they actually want THIS
> particular case to work correctly, not OTHER cases to be fucked up?!
>
>
> Anyway. My question is, does it really need to be implemented in Linux?
> It looks bogus to me, and it basically requires any program
> to contain a work-around for this case. For example, mv from util-linux
> apparently already has a workaround:
>
> $ touch a; ln a b
> $ strace mv a b
> ...
> stat64("b", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
> lstat64("a", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
> lstat64("b", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
> geteuid32() = 0
> unlink("a") = 0
> close(0) = 0
> close(1) = 0
> close(2) = 0
> exit_group(0) = ?
mv is from coreutils BTW.
Here is the related comment from the source:
"Set *UNLINK_SRC if we've determined that the caller wants to do
`rename (a, b)' where `a' and `b' are distinct hard links to the same
file. In that case, the caller should try to unlink `a' and then return
successfully. Ideally, we wouldn't have to do that, and we'd be
able to rely on rename to remove the source file. However, POSIX
mistakenly requires that such a rename call do *nothing* and return
successfully."
Perhaps it could be brought up as an issue with the standards guys?
cheers,
Pádraig.
next prev parent reply other threads:[~2011-10-28 15:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-10-28 15:25 rename("a", "b") would not always remove "a" on success. ?!! Denys Vlasenko
2011-10-28 15:32 ` Pádraig Brady [this message]
2011-10-28 15:42 ` Eric Blake
2011-10-28 15:58 ` Eric Blake
2011-10-29 1:00 ` Denys Vlasenko
2011-10-29 1:19 ` richard -rw- weinberger
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EAACAF0.4030401@draigBrady.com \
--to=p@draigbrady.com \
--cc=christian.engelmayer@frequentis.com \
--cc=coreutils@gnu.org \
--cc=linux-kernel@vger.kernel.org \
--cc=vda.linux@googlemail.com \
--cc=viro@zeniv.linux.org.uk \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.