linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chris Sykes <chris@sigsegv.plus.com>
To: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cc: linux-kernel@vger.kernel.org
Subject: Re: rename("a","b") succeeds multiple times race
Date: Thu, 24 Apr 2003 15:30:58 +0100	[thread overview]
Message-ID: <20030424143058.GC23247@spackhandychoptubes.co.uk> (raw)
In-Reply-To: <16039.53523.533498.354359@chiark.greenend.org.uk>

[-- Attachment #1: Type: text/plain, Size: 1889 bytes --]

On Thu, Apr 24, 2003 at 12:57:07PM +0100, Ian Jackson wrote:
> I'm running 2.2.25 on a dual PIII; I have a program that processes
> mail messages which are left in a queue directory as uniquely named
> files.  The queue runners each `claim' a message by renaming it away
> from the initial filename, so that only one queue runner works on each
> message.
> 
> However, this does not work because Linux erroneously allows several
> processes to simultaneously and `successfully' rename the same file.
> The filesystem in question is ext2.
> 
> I ran the system under strace, and saw (for example) the following, in
> five straces of five different processes:
> 
>  02:11:47.293131 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
>  02:11:47.354497 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
>  02:11:47.412207 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
>  02:11:47.414376 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0
>  02:11:47.414559 rename("q1988na-000xqY", "proc.1988na-000xqY") = 0

In rename(2):
[1] "If  newpath  already exists it will be atomically replaced
    (subject to a few conditions - see ERRORS below), so  that
    there  is  no point at which another process attempting to
    access newpath will find it missing."

 ...

[2] "However, when overwriting there will probably be a  window
    in  which both oldpath and newpath refer to the file being
    renamed."

Perhaps your program should link(2) the newpath to the oldpath, then
on success unlink(2) the oldpath.  link(2) will fail should newpath
already exist.  Of course this assumes that oldpath & newpath are on
the same filesystem.

-- 

(o-  Chris Sykes  -- GPG Key: http://www.sigsegv.plus.com/key.txt
//\       "Don't worry. Everything is getting nicely out of control ..."
V_/_                          Douglas Adams - The Salmon of Doubt


[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2003-04-24 14:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-24 11:57 rename("a","b") succeeds multiple times race Ian Jackson
2003-04-24 14:30 ` Chris Sykes [this message]
2003-04-24 16:46   ` Ian Jackson
2003-04-24 21:34   ` Jamie Lokier
2003-04-24 21:54     ` viro

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=20030424143058.GC23247@spackhandychoptubes.co.uk \
    --to=chris@sigsegv.plus.com \
    --cc=ijackson@chiark.greenend.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).