git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: About close() in commit_lock_file()

From
Duy Nguyen <pclouds@gmail.com>
Date
Aug 6, 2013, 08:36 UTC
Message-ID
<CACsJy8DquJj1qVawKfrbZY+2WLC54Gskizs1sxZ_j1yutBkbdA@mail.gmail.com>
In-Reply-To
<52009A90.7050701@viscovery.net>
On Tue, Aug 6, 2013 at 1:41 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
Show 16 quoted lines
> Am 8/5/2013 16:23, schrieb Duy Nguyen:
>> close() is added in commit_lock_file(), before rename(), by 4723ee9
>> (Close files opened by lock_file() before unlinking. - 2007-11-13),
>> which is needed by Windows. But doesn't that create a gap between
>> close() and rename() on other platforms where another process can
>> replace .lock file with something else before rename() is executed?
>
> First, files manipulated by commit_lock_file() are to be opened only using
> lock_file() by definition. Opening such a file in with open() or fopen()
> or renaming it via rename() without using the lockfile.[ch] API is
> possible regardless of whether commit_lock_file() has closed the file or
> not. Such manipulation is already undefined behavior (from Git's point of
> view), and there is nothing we can do about "misbehaving" processes.
>
> Second, lock_file() uses O_CREAT|O_EXCL, which fails when the file exists,
> regardless of whether it is open or not.

The second process could unlink(.lock file) first, then open it, even using lock_file(), but I think that falls into your "first" and is an invalid case from git point of view, so..

> Conclusion: There is no problem.
Agreed. False alarm.
-- 
Duy
Previous: Johannes Sixt
Message 4 of 4 in “About close() in commit_lock_file()”
  1. Duy NguyenAug 5, 2013
  2. Junio C HamanoAug 5, 2013
  3. Johannes SixtAug 6, 2013
  4. Duy NguyenAug 6, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.