pgsql: Windows: Make pg_ctl reliably detect service status

Started by Alvaro Herreraover 10 years ago7 messageshackers
Jump to latest
#1Alvaro Herrera
alvherre@2ndquadrant.com

Windows: Make pg_ctl reliably detect service status

pg_ctl is using isatty() to verify whether the process is running in a
terminal, and if not it sends its output to Windows' Event Log ... which
does the wrong thing when the output has been redirected to a pipe, as
reported in bug #13592.

To fix, make pg_ctl use the code we already have to detect service-ness:
in the master branch, move src/backend/port/win32/security.c to src/port
(with suitable tweaks so that it runs properly in backend and frontend
environments); pg_ctl already has access to pgport so it Just Works. In
older branches, that's likely to cause trouble, so instead duplicate the
required code in pg_ctl.c.

Author: Michael Paquier
Bug report and diagnosis: Egon Kocjan
Backpatch: all supported branches

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/a967613911f7ef7b6387b9e8718f0ab8f0c4d9c8

Modified Files
--------------
src/backend/port/win32/Makefile | 2 +-
src/backend/port/win32/security.c | 248 --------------------------------
src/bin/pg_ctl/pg_ctl.c | 2 +-
src/include/port/win32.h | 7 +-
src/port/win32security.c | 282 +++++++++++++++++++++++++++++++++++++
src/tools/msvc/Mkvcbuild.pm | 2 +-
6 files changed, 289 insertions(+), 254 deletions(-)

--
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers

#2Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#1)
Re: [COMMITTERS] pgsql: Windows: Make pg_ctl reliably detect service status

Alvaro Herrera wrote:

Windows: Make pg_ctl reliably detect service status

pg_ctl is using isatty() to verify whether the process is running in a
terminal, and if not it sends its output to Windows' Event Log ... which
does the wrong thing when the output has been redirected to a pipe, as
reported in bug #13592.

This broke the mingw port. Looking.

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#2)
Re: Re: [COMMITTERS] pgsql: Windows: Make pg_ctl reliably detect service status

Alvaro Herrera wrote:

Alvaro Herrera wrote:

Windows: Make pg_ctl reliably detect service status

pg_ctl is using isatty() to verify whether the process is running in a
terminal, and if not it sends its output to Windows' Event Log ... which
does the wrong thing when the output has been redirected to a pipe, as
reported in bug #13592.

This broke the mingw port. Looking.

A bit of grepping appears to say that I ought to patch configure.in to
add
AC_LIBOBJ(win32security)
around line 1580 and rerun autoconf, but this seems completely at odds
with the documented use of AC_LIBOBJS. Is this black magic?

--
�lvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#4Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Alvaro Herrera (#3)
Re: Re: [COMMITTERS] pgsql: Windows: Make pg_ctl reliably detect service status

Alvaro Herrera wrote:

Alvaro Herrera wrote:

Alvaro Herrera wrote:

Windows: Make pg_ctl reliably detect service status

pg_ctl is using isatty() to verify whether the process is running in a
terminal, and if not it sends its output to Windows' Event Log ... which
does the wrong thing when the output has been redirected to a pipe, as
reported in bug #13592.

This broke the mingw port. Looking.

A bit of grepping appears to say that I ought to patch configure.in to
add
AC_LIBOBJ(win32security)
around line 1580 and rerun autoconf, but this seems completely at odds
with the documented use of AC_LIBOBJS. Is this black magic?

I confirmed that adding that line makes the new file get compiled. I
also noticed these warnings when compiling it:

In file included from /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/stdarg.h:1:0,
from /pgsql/source/master/src/include/c.h:85,
from /pgsql/source/master/src/include/postgres_fe.h:25,
from /pgsql/source/master/src/port/win32security.c:17:
/pgsql/source/master/src/port/win32security.c: In function ‘log_error’:
/pgsql/source/master/src/port/win32security.c:37:11: warning: passing argument 1 of ‘__builtin_va_start’ from incompatible pointer type
va_start(fmt, ap);
^
/pgsql/source/master/src/port/win32security.c:37:11: note: expected ‘char **’ but argument is of type ‘const char **’
/pgsql/source/master/src/port/win32security.c:37:2: warning: second parameter of ‘va_start’ not last named argument [-Wvarargs]
va_start(fmt, ap);
^

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#4)
Re: Re: [COMMITTERS] pgsql: Windows: Make pg_ctl reliably detect service status

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

I confirmed that adding that line makes the new file get compiled. I
also noticed these warnings when compiling it:

In file included from /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/stdarg.h:1:0,
from /pgsql/source/master/src/include/c.h:85,
from /pgsql/source/master/src/include/postgres_fe.h:25,
from /pgsql/source/master/src/port/win32security.c:17:
/pgsql/source/master/src/port/win32security.c: In function ‘log_error’:
/pgsql/source/master/src/port/win32security.c:37:11: warning: passing argument 1 of ‘__builtin_va_start’ from incompatible pointer type
va_start(fmt, ap);
^

I take it this code is quite untested, because what that's whining
about is that the arguments of va_start() are reversed.

regards, tom lane

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#6Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#5)
Re: Re: [COMMITTERS] pgsql: Windows: Make pg_ctl reliably detect service status

Tom Lane wrote:

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

I confirmed that adding that line makes the new file get compiled. I
also noticed these warnings when compiling it:

In file included from /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/stdarg.h:1:0,
from /pgsql/source/master/src/include/c.h:85,
from /pgsql/source/master/src/include/postgres_fe.h:25,
from /pgsql/source/master/src/port/win32security.c:17:
/pgsql/source/master/src/port/win32security.c: In function ‘log_error’:
/pgsql/source/master/src/port/win32security.c:37:11: warning: passing argument 1 of ‘__builtin_va_start’ from incompatible pointer type
va_start(fmt, ap);
^

I take it this code is quite untested, because what that's whining
about is that the arguments of va_start() are reversed.

It is untested by me, yes. Pushed a fix for this problem.

--
Álvaro Herrera http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

#7Michael Paquier
michael@paquier.xyz
In reply to: Alvaro Herrera (#6)
Re: Re: [COMMITTERS] pgsql: Windows: Make pg_ctl reliably detect service status

On Fri, Jan 8, 2016 at 8:38 AM, Alvaro Herrera <alvherre@2ndquadrant.com> wrote:

Tom Lane wrote:

Alvaro Herrera <alvherre@2ndquadrant.com> writes:

I confirmed that adding that line makes the new file get compiled. I
also noticed these warnings when compiling it:

In file included from /usr/lib/gcc/x86_64-w64-mingw32/4.9-win32/include/stdarg.h:1:0,
from /pgsql/source/master/src/include/c.h:85,
from /pgsql/source/master/src/include/postgres_fe.h:25,
from /pgsql/source/master/src/port/win32security.c:17:
/pgsql/source/master/src/port/win32security.c: In function ‘log_error’:
/pgsql/source/master/src/port/win32security.c:37:11: warning: passing argument 1 of ‘__builtin_va_start’ from incompatible pointer type
va_start(fmt, ap);
^

I take it this code is quite untested, because what that's whining
about is that the arguments of va_start() are reversed.

It is untested by me, yes. Pushed a fix for this problem.

Arg, thanks! My MS 2010 compiler did not complain about that. That's a
bit depressing...
--
Michael

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers