From: Andres Freund <andres@anarazel.de>
To: Magnus Hagander <magnus@hagander.net>
To: Alvaro Herrera <alvherre@alvh.no-ip.org>
To: Michael Paquier <michael@paquier.xyz>
Cc: Dave Page <dpage@pgadmin.org>
Cc: Andrew Dunstan <andrew@dunslane.net>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: Thomas Munro <thomas.munro@gmail.com>
Cc: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Subject: Re: CI/windows docker vs "am a service" autodetection on windows
Date: Fri, 5 Mar 2021 10:57:52 -0800
Message-ID: <20210305185752.3up5eq2eanb7ofmb@alap3.anarazel.de> (raw)
In-Reply-To: <20210304204859.65z6ynqicmlobi7r@alap3.anarazel.de>
References: <20210304190817.at3r2kedvm5e3rq7@alap3.anarazel.de>
<58c9854f-fa1c-e5df-3b8e-0c36a912c836@dunslane.net>
<CABUevEwiiU-kzoqKbBt91UL4c2Ln8dQQmXrk1rBcKHFCpxoLcA@mail.gmail.com>
<20210304203008.zy3op3fisra5tlun@alap3.anarazel.de>
<CABUevEx9FK3ZP+6Re-CKdVM1dDdi-N5UynkpcTs3z4M3JQJkGA@mail.gmail.com>
<20210304204859.65z6ynqicmlobi7r@alap3.anarazel.de>
Hi,
On 2021-03-04 12:48:59 -0800, Andres Freund wrote:
> On 2021-03-04 21:36:23 +0100, Magnus Hagander wrote:
> > > I think that's a good answer for pg_ctl - not so sure about postgres
> > > itself, at least once it's up and running. I don't know what lead to all
> > > of this autodetection stuff, but is there the possibility of blocking on
> > > whatever stderr is set too as a service?
> > >
> > > Perhaps we could make the service detection more reliable by checking
> > > whether stderr is actually something useful?
> >
> > So IIRC, and mind that this is like 15 years ago, there is something
> > that looks like stderr, but the contents are thrown away. It probably
> > exists specifically so that programs won't crash when run as a
> > service...
>
> Yea, that'd make sense.
>
> I wish we had tests for the service stuff, but that's from long before
> there were tap tests...
After fighting with a windows VM for a bit (ugh), it turns out that yes,
there is stderr, but that fileno(stderr) returns -2, and
GetStdHandle(STD_ERROR_HANDLE) returns NULL (not INVALID_HANDLE_VALUE).
The complexity however is that while that's true for pg_ctl within
pgwin32_ServiceMain:
checking what stderr=00007FF8687DFCB0 is (handle: 0, fileno=-2)
but not for postmaster or backends
WARNING: 01000: checking what stderr=00007FF880F5FCB0 is (handle: 92, fileno=2)
which makes sense in a way, because we don't tell CreateProcessAsUser()
that it should pass stdin/out/err down (which then seems to magically
get access to the "topmost" console applications output - damn, this
stuff is weird).
You'd earlier mentioned that other distributions may not use pg_ctl
register - but I assume they use pg_ctl runservice? Or do they actually
re-implement all those magic incantations in pg_ctl.c?
Greetings,
Andres Freund
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: andres@anarazel.de, magnus@hagander.net, alvherre@alvh.no-ip.org, michael@paquier.xyz, dpage@pgadmin.org, andrew@dunslane.net, thomas.munro@gmail.com, heikki.linnakangas@iki.fi
Subject: Re: CI/windows docker vs "am a service" autodetection on windows
In-Reply-To: <20210305185752.3up5eq2eanb7ofmb@alap3.anarazel.de>
* 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