Re: Check return value of pclose() correctly

Поиск
Список
Период
Сортировка
От Peter Eisentraut
Тема Re: Check return value of pclose() correctly
Дата
Msg-id 175ef638-32c7-1a84-590c-6df7497baeea@enterprisedb.com
обсуждение исходный текст
Ответ на Re: Check return value of pclose() correctly  (Tom Lane <tgl@sss.pgh.pa.us>)
Ответы Re: Check return value of pclose() correctly
Список pgsql-hackers
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.




В списке pgsql-hackers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Check return value of pclose() correctly
Следующее
От: Thomas Munro
Дата:
Сообщение: Re: Direct I/O