* About close() in commit_lock_file()
@ 2013-08-05 14:23 Duy Nguyen
2013-08-05 16:56 ` Junio C Hamano
2013-08-06 6:41 ` Johannes Sixt
0 siblings, 2 replies; 4+ messages in thread
From: Duy Nguyen @ 2013-08-05 14:23 UTC (permalink / raw)
To: Git Mailing List
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?
Should we enclose close() in #ifdef __MINGW32__ (and maybe
__CYGWIN__)?
--
Duy
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: About close() in commit_lock_file()
2013-08-05 14:23 About close() in commit_lock_file() Duy Nguyen
@ 2013-08-05 16:56 ` Junio C Hamano
2013-08-06 6:41 ` Johannes Sixt
1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2013-08-05 16:56 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Git Mailing List
Duy Nguyen <pclouds@gmail.com> writes:
> 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?
Interesting.
> Should we enclose close() in #ifdef __MINGW32__ (and maybe
> __CYGWIN__)?
Or just have "close and retry" code after seeing rename() fails with
some known errno, without singling out a particular platform?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: About close() in commit_lock_file()
2013-08-05 14:23 About close() in commit_lock_file() Duy Nguyen
2013-08-05 16:56 ` Junio C Hamano
@ 2013-08-06 6:41 ` Johannes Sixt
2013-08-06 8:36 ` Duy Nguyen
1 sibling, 1 reply; 4+ messages in thread
From: Johannes Sixt @ 2013-08-06 6:41 UTC (permalink / raw)
To: Duy Nguyen; +Cc: Git Mailing List
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.
Conclusion: There is no problem.
-- Hannes
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: About close() in commit_lock_file()
2013-08-06 6:41 ` Johannes Sixt
@ 2013-08-06 8:36 ` Duy Nguyen
0 siblings, 0 replies; 4+ messages in thread
From: Duy Nguyen @ 2013-08-06 8:36 UTC (permalink / raw)
To: Johannes Sixt; +Cc: Git Mailing List
On Tue, Aug 6, 2013 at 1:41 PM, Johannes Sixt <j.sixt@viscovery.net> wrote:
> 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-08-06 8:37 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-05 14:23 About close() in commit_lock_file() Duy Nguyen
2013-08-05 16:56 ` Junio C Hamano
2013-08-06 6:41 ` Johannes Sixt
2013-08-06 8:36 ` Duy Nguyen
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).