From: Peter Eisentraut <peter.eisentraut@enterprisedb.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: Check return value of pclose() correctly
Date: Tue, 1 Nov 2022 16:41:15 -0400
Message-ID: <175ef638-32c7-1a84-590c-6df7497baeea@enterprisedb.com> (raw)
In-Reply-To: <1091330.1667281922@sss.pgh.pa.us>
References: <8cd9fb02-bc26-65f1-a809-b1cb360eef73@enterprisedb.com>
<Y2CwITuzlNpF/dWj@paquier.xyz>
<1091330.1667281922@sss.pgh.pa.us>
On 01.11.22 06:52, Tom Lane wrote:
> I think there are two issues here. POSIX says
>
> Upon successful return, pclose() shall return the termination status
> of the command language interpreter. Otherwise, pclose() shall return
> -1 and set errno to indicate the error.
>
> That is, first you need to make sure that pclose returned a valid
> child process status, and then you need to decode that status.
> It's not obvious to me that -1 is disjoint from the set of possible
> child statuses. Do we need to add some logic that clears and then
> checks errno?
This return convention is also used by system() and is widely used. So
I don't think we need to be concerned about this.
In practice, int is 4 bytes and WEXITSTATUS() and WTERMSIG() are one
byte each, so they are probably in the lower bytes, and wouldn't
accidentally make up a -1.
> Also, we have a number of places --- at least FreeDesc() and
> ClosePipeStream() --- that consider pclose()'s return value to be
> perfectly equivalent to that of close() etc, because they'll
> return either one without telling the caller which is which.
> It seems like we have to fix that if we want to issue sane
> error reports.
I think this works. FreeDesc() returns the pclose() exit status to
ClosePipeStream(), which returns it directly. No interpretation is done
within these functions.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: peter.eisentraut@enterprisedb.com, tgl@sss.pgh.pa.us, michael@paquier.xyz
Subject: Re: Check return value of pclose() correctly
In-Reply-To: <175ef638-32c7-1a84-590c-6df7497baeea@enterprisedb.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox