Re: dup(0) fails on Ubuntu 20.04 and macOS 10.15 with 13.0

From: Mario Emmenlauer <mario(at)emmenlauer(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: dup(0) fails on Ubuntu 20.04 and macOS 10.15 with 13.0
Date: 2021-09-01 15:49:57
Message-ID: ba09e27f-6419-ccaf-0e29-aae32f2f3c2a@emmenlauer.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

On 01.09.21 15:54, Tom Lane wrote:
> Mario Emmenlauer <mario(at)emmenlauer(dot)de> writes:
>> On 05.10.20 14:35, Tom Lane wrote:
>>> Mario Emmenlauer <mario(at)emmenlauer(dot)de> writes:
>>>> I get reproducibly the error:
>>>> 2020-10-05 11:48:19.720 CEST [84731] WARNING: dup(0) failed after 0 successes: Bad file descriptor
>
>>> Hmph. That code loop assumes that stdin exists to be duplicated,
>>> but maybe if it had been closed, you'd get this error.
>
>> Replying to a very old thread here: I could indeed trace the problem of
>> the failing `dup(0)` back to how we start the server! We start the
>> server from an executable that closes stdin very early on, and this
>> seems to lead to the problem.
>
> Hm. I'm tempted to propose that we simply change that from dup(0) to
> dup(2). Formally, that's just moving the problem around. In practice
> though, there are good reasons not to close the server's stderr, ie you
> will lose error messages that might be important. OTOH there does not
> seem to be any obvious reason why the server should need valid stdin,
> so if we can get rid of an implementation artifact that makes it require
> that, that seems like an improvement.

The idea to switch to dup(2) sounds very good to me. Also, while at it,
maybe the error message could be improved? The kids nowadays don't learn
so much about system I/O any more, and if someone does not know `dup()`,
then the error message is not very telling. It took me a while to under-
stand what the code was supposed to do. So it may be helpful to add to
the error message something like "possible the stderr stream is closed,
this is not supported". What do you think?

All the best,

Mario Emmenlauer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2021-09-01 15:56:57 Re: dup(0) fails on Ubuntu 20.04 and macOS 10.15 with 13.0
Previous Message Tom Lane 2021-09-01 15:46:41 Re: PostgreSQL 12 - ERROR: invalid attribute number 2 for ad_user_pkey - Urgent

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2021-09-01 15:56:57 Re: dup(0) fails on Ubuntu 20.04 and macOS 10.15 with 13.0
Previous Message Jacob Champion 2021-09-01 15:42:35 Re: [PATCH] Support pg_ident mapping for LDAP