From: | Paul Guo <pguo(at)pivotal(dot)io> |
---|---|
To: | Michael Paquier <michael(at)paquier(dot)xyz> |
Cc: | Ning Yu <nyu(at)pivotal(dot)io>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Possible race condition in pg_mkdir_p()? |
Date: | 2019-07-18 10:30:13 |
Message-ID: | CAEET0ZHVofSLgh_KvQDbRTYr=Ck3mWA11kOGsmHFA-w76qomiw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Thu, Jul 18, 2019 at 4:57 PM Michael Paquier <michael(at)paquier(dot)xyz> wrote:
> On Thu, Jul 18, 2019 at 04:17:22PM +0800, Ning Yu wrote:
> > This is still wrong with current code logic, because when the statusdir
> is
> > a file the errno is also EEXIST, but it can pass the check here. Even if
> > we fix pg_mkdir_p() by following the `mkdir -p` way the errno check here
> is
> > still wrong.
>
> Would you like to send a patch?
>
Michael, we'll send out the patch later. Checked code, it seems that there
is another related mkdir() issue.
MakePGDirectory() is actually a syscall mkdir(), and manpage says the errno
meaning of EEXIST,
EEXIST pathname already exists (not necessarily as a directory).
This includes the case where pathname is a symbolic link, dangling or not.
However it looks like some callers do not use that correctly, e.g.
if (MakePGDirectory(directory) < 0)
{
if (errno == EEXIST)
return;
OR
if (MakePGDirectory(parentdir) < 0 && errno != EEXIST)
i.e. we should better use stat(path) && S_ISDIR(buf) && errno == EEXIST to
replace errno == EEXIST.
One possible fix is to add an argument like ignore_created (in case some
callers want to fail if the path has been created) in MakePGDirectory() and
then add that code logic into it.
From | Date | Subject | |
---|---|---|---|
Next Message | Etsuro Fujita | 2019-07-18 11:00:45 | Re: partition routing layering in nodeModifyTable.c |
Previous Message | Thomas Munro | 2019-07-18 09:40:32 | Re: SegFault on 9.6.14 |