Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [patch] Avoid race in zf_mkdir



On Fri, Oct 09, 2020 at 01:47:49PM -0700, Bart Schaefer wrote:
> On Fri, Oct 9, 2020 at 1:35 PM Roman Perepelitsa <
> roman.perepelitsa@xxxxxxxxx> wrote:
> 
> > On Fri, Oct 9, 2020 at 10:25 PM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
> > wrote:
> > >
> > > Er, sorry, this doesn't actually avoid the race, it just prevents the
> > error message from being shown by whichever shell loses the race.
> >
> > I think this is the expected behavior. It's prescribed by POSIX for mkdir.
> >
> [...]
> 
> >
> > The patch is incorrect for a different reason. If `zf_mkdir -p foo` is
> > racing with another process that's doing `mkdir foo && rmdir foo`, the
> > zf_mkdir call must never fail but with this patch it can fail.
> >
> 
> Hm ... in that case the code shouldn't call stat() unless the mkdir() gives
> EEXIST?  And then ignore ENOENT from stat()?
> 
> What if another process is doing "touch foo && rm foo"?  How is it possible
> to distinguish that from mkdir+rmdir ?
> 
> Or are we confusing the requirements for mkdir(2) from those for mkdir(1)
> ?  I don't have the spec handy.

https://pubs.opengroup.org/onlinepubs/9699919799/utilities/mkdir.html

I suppose we could stat before and after if after mkdir errno = EEXIST.




Messages sorted by: Reverse Date, Date, Thread, Author