pgsql: Blind attempt at a Cygwin fix

Started by Alvaro Herreraabout 10 years ago8 messages
#1Alvaro Herrera
alvherre@alvh.no-ip.org

Blind attempt at a Cygwin fix

Further portability fix for a967613911f7. Mingw- and MSVC-based builds
appear to be working fine, but Cygwin needs an extra tweak whereby the
new win32security.c file is explicitely added to the list of files to
build in pgport, per Cygwin members brolga and lorikeet.

Author: Michael Paquier

Branch
------
master

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

Modified Files
--------------
configure | 6 ++++++
configure.in | 1 +
2 files changed, 7 insertions(+)

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#1)
Re: pgsql: Blind attempt at a Cygwin fix

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

Blind attempt at a Cygwin fix

According to
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=brolga&amp;dt=2016-01-08%2014%3A51%3A27

brolga now tries to compile win32security.c, which it evidently was not
doing before, but the compile blows up; looks like it is missing #include
calls (which must exist in other places where this code lives ...)

regards, tom lane

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

#3Alvaro Herrera
alvherre@2ndquadrant.com
In reply to: Tom Lane (#2)
Re: [COMMITTERS] pgsql: Blind attempt at a Cygwin fix

Tom Lane wrote:

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

Blind attempt at a Cygwin fix

According to
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=brolga&amp;dt=2016-01-08%2014%3A51%3A27

brolga now tries to compile win32security.c, which it evidently was not
doing before, but the compile blows up; looks like it is missing #include
calls (which must exist in other places where this code lives ...)

Obviously this wasn't the best idea ever. Andrew suggests on IM to
revert this on Cygwin to just do the "isatty" check as originally.

I'm CC'ing Marco Atzeri, who has done Cygwin work lately. Maybe he can
spend some time getting this port fixed.

--
�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)
1 attachment(s)
Re: [COMMITTERS] pgsql: Blind attempt at a Cygwin fix

Alvaro Herrera wrote:

Tom Lane wrote:

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:

Blind attempt at a Cygwin fix

According to
http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=brolga&amp;dt=2016-01-08%2014%3A51%3A27

brolga now tries to compile win32security.c, which it evidently was not
doing before, but the compile blows up; looks like it is missing #include
calls (which must exist in other places where this code lives ...)

Obviously this wasn't the best idea ever. Andrew suggests on IM to
revert this on Cygwin to just do the "isatty" check as originally.

Here's a proposed patch. Thoughts?

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

Attachments:

Revert-Blind-attempt-at-a-Cygwin-fix.patchtext/x-diff; charset=us-asciiDownload
>From af7989c37cb8a1d647e6ce7d01857491b42b01b5 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 8 Jan 2016 12:36:18 -0300
Subject: [PATCH] Revert "Blind attempt at a Cygwin fix"

This reverts commit e9282e953205a2f3125fc8d1052bc01cb77cd2a3, which blew
up in a pretty spectacular way.  Introduce the original code while we
search for a real fix.
---
 configure               | 6 ------
 configure.in            | 1 -
 src/bin/pg_ctl/pg_ctl.c | 9 +++++++++
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/configure b/configure
index ab213a1..3dd1b15 100755
--- a/configure
+++ b/configure
@@ -13075,12 +13075,6 @@ if test "$PORTNAME" = "cygwin"; then
  ;;
 esac
 
-  case " $LIBOBJS " in
-  *" win32security.$ac_objext "* ) ;;
-  *) LIBOBJS="$LIBOBJS win32security.$ac_objext"
- ;;
-esac
-
 fi
 
 ac_fn_c_check_decl "$LINENO" "sys_siglist" "ac_cv_have_decl_sys_siglist" "#include <signal.h>
diff --git a/configure.in b/configure.in
index 41402df..9398482 100644
--- a/configure.in
+++ b/configure.in
@@ -1596,7 +1596,6 @@ fi
 # Cygwin needs only a bit of that
 if test "$PORTNAME" = "cygwin"; then
   AC_LIBOBJ(dirmod)
-  AC_LIBOBJ(win32security)
 fi
 
 AC_CHECK_DECLS([sys_siglist], [], [],
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 28d3cf2..919d764 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -212,6 +212,15 @@ write_stderr(const char *fmt,...)
 	vfprintf(stderr, fmt, ap);
 #else
 
+/*
+ * On Cygwin, we don't yet have a reliable mechanism to detect when
+ * we're being run as a service, so fall back to the old (and broken)
+ * stderr test.
+ */
+#ifdef __CYGWIN__
+#define	pgwin32_is_service()	(isatty(fileno(stderr)))
+#endif
+
 	/*
 	 * On Win32, we print to stderr if running on a console, or write to
 	 * eventlog if running as a service
-- 
2.1.4

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Alvaro Herrera (#4)
Re: [COMMITTERS] pgsql: Blind attempt at a Cygwin fix

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

Alvaro Herrera wrote:

Obviously this wasn't the best idea ever. Andrew suggests on IM to
revert this on Cygwin to just do the "isatty" check as originally.

Here's a proposed patch. Thoughts?

Ugly, but it will hold the fort until someone can debug the service
code for Cygwin.

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

#6Andrew Dunstan
andrew@dunslane.net
In reply to: Tom Lane (#5)
Re: [COMMITTERS] pgsql: Blind attempt at a Cygwin fix

On 01/08/2016 11:17 AM, Tom Lane wrote:

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

Alvaro Herrera wrote:

Obviously this wasn't the best idea ever. Andrew suggests on IM to
revert this on Cygwin to just do the "isatty" check as originally.

Here's a proposed patch. Thoughts?

Ugly, but it will hold the fort until someone can debug the service
code for Cygwin.

I downloaded the official Cygwin packages into a Cygwin instance and
checked how they do things. As I rather expected, they do not use pg_ctl
at all to install or run as a service. Rather, they use the standard
Cygwin service utility cygrunsrv. This is all managed via a SYSV style
init script.

So if anything I'd be inclined to disable all the service-related code
in pg_ctl for Cygwin, and treat it just as we treat Unix.

cheers

andrew

--
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@gmail.com
In reply to: Andrew Dunstan (#6)
Re: [COMMITTERS] pgsql: Blind attempt at a Cygwin fix

On Sun, Jan 10, 2016 at 2:00 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

I downloaded the official Cygwin packages into a Cygwin instance and checked
how they do things. As I rather expected, they do not use pg_ctl at all to
install or run as a service. Rather, they use the standard Cygwin service
utility cygrunsrv. This is all managed via a SYSV style init script.

Thanks for the investigation!

So if anything I'd be inclined to disable all the service-related code in
pg_ctl for Cygwin, and treat it just as we treat Unix.

We had better do the same for back branches then. Need of a patch?
--
Michael

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

#8Michael Paquier
michael.paquier@gmail.com
In reply to: Michael Paquier (#7)
1 attachment(s)
Re: [COMMITTERS] pgsql: Blind attempt at a Cygwin fix

On Sun, Jan 10, 2016 at 8:10 AM, Michael Paquier
<michael.paquier@gmail.com> wrote:

On Sun, Jan 10, 2016 at 2:00 AM, Andrew Dunstan <andrew@dunslane.net> wrote:

I downloaded the official Cygwin packages into a Cygwin instance and checked
how they do things. As I rather expected, they do not use pg_ctl at all to
install or run as a service. Rather, they use the standard Cygwin service
utility cygrunsrv. This is all managed via a SYSV style init script.

Thanks for the investigation!

So if anything I'd be inclined to disable all the service-related code in
pg_ctl for Cygwin, and treat it just as we treat Unix.

We had better do the same for back branches then. Need of a patch?

OK, here is a patch to disable all the service-related code in pg_ctl
for cygwin. This time it is not a blind shot and this compiles
correctly. Changing the option layer is fine for me if this is
HEAD-only. For back-branches, I would suggest to do nothing, the
service-related code paths are not going to run anyway, any output
going to stderr.
--
Michael

Attachments:

cygwin-removal-service-master.patchtext/x-diff; charset=US-ASCII; name=cygwin-removal-service-master.patchDownload
diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c
index 919d764..192f587 100644
--- a/src/bin/pg_ctl/pg_ctl.c
+++ b/src/bin/pg_ctl/pg_ctl.c
@@ -105,7 +105,7 @@ static char backup_file[MAXPGPATH];
 static char recovery_file[MAXPGPATH];
 static char promote_file[MAXPGPATH];
 
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 static DWORD pgctl_start_type = SERVICE_AUTO_START;
 static SERVICE_STATUS status;
 static SERVICE_STATUS_HANDLE hStatus = (SERVICE_STATUS_HANDLE) 0;
@@ -133,7 +133,7 @@ static void do_kill(pgpid_t pid);
 static void print_msg(const char *msg);
 static void adjust_data_dir(void);
 
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 #if (_MSC_VER >= 1800)
 #include <versionhelpers.h>
 #else
@@ -165,7 +165,7 @@ static void unlimit_core_size(void);
 #endif
 
 
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 static void
 write_eventlog(int level, const char *line)
 {
@@ -207,20 +207,11 @@ write_stderr(const char *fmt,...)
 	va_list		ap;
 
 	va_start(ap, fmt);
-#if !defined(WIN32) && !defined(__CYGWIN__)
+#ifndef WIN32
 	/* On Unix, we just fprintf to stderr */
 	vfprintf(stderr, fmt, ap);
 #else
 
-/*
- * On Cygwin, we don't yet have a reliable mechanism to detect when
- * we're being run as a service, so fall back to the old (and broken)
- * stderr test.
- */
-#ifdef __CYGWIN__
-#define	pgwin32_is_service()	(isatty(fileno(stderr)))
-#endif
-
 	/*
 	 * On Win32, we print to stderr if running on a console, or write to
 	 * eventlog if running as a service
@@ -718,7 +709,7 @@ test_postmaster_connection(pgpid_t pm_pid, bool do_checkpoint)
 #endif
 
 		/* No response, or startup still in process; wait */
-#if defined(WIN32)
+#ifdef WIN32
 		if (do_checkpoint)
 		{
 			/*
@@ -1342,7 +1333,7 @@ do_kill(pgpid_t pid)
 	}
 }
 
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 
 #if (_MSC_VER < 1800)
 static bool
@@ -1408,20 +1399,6 @@ pgwin32_CommandLine(bool registration)
 		}
 	}
 
-#ifdef __CYGWIN__
-	/* need to convert to windows path */
-	{
-		char		buf[MAXPGPATH];
-
-#if CYGWIN_VERSION_DLL_MAJOR >= 1007
-		cygwin_conv_path(CCP_POSIX_TO_WIN_A, cmdPath, buf, sizeof(buf));
-#else
-		cygwin_conv_to_full_win32_path(cmdPath, buf);
-#endif
-		strcpy(cmdPath, buf);
-	}
-#endif
-
 	/* if path does not end in .exe, append it */
 	if (strlen(cmdPath) < 4 ||
 		pg_strcasecmp(cmdPath + strlen(cmdPath) - 4, ".exe") != 0)
@@ -1926,7 +1903,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
 	 */
 	return r;
 }
-#endif   /* defined(WIN32) || defined(__CYGWIN__) */
+#endif   /* WIN32 */
 
 static void
 do_advice(void)
@@ -1950,7 +1927,7 @@ do_help(void)
 	printf(_("  %s status  [-D DATADIR]\n"), progname);
 	printf(_("  %s promote [-D DATADIR] [-s]\n"), progname);
 	printf(_("  %s kill    SIGNALNAME PID\n"), progname);
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 	printf(_("  %s register   [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR]\n"
 			 "                    [-S START-TYPE] [-w] [-t SECS] [-o \"OPTIONS\"]\n"), progname);
 	printf(_("  %s unregister [-N SERVICENAME]\n"), progname);
@@ -1958,7 +1935,7 @@ do_help(void)
 
 	printf(_("\nCommon options:\n"));
 	printf(_("  -D, --pgdata=DATADIR   location of the database storage area\n"));
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 	printf(_("  -e SOURCE              event source for logging when running as a service\n"));
 #endif
 	printf(_("  -s, --silent           only print errors, no informational messages\n"));
@@ -1991,7 +1968,7 @@ do_help(void)
 	printf(_("\nAllowed signal names for kill:\n"));
 	printf("  ABRT HUP INT QUIT TERM USR1 USR2\n");
 
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 	printf(_("\nOptions for register and unregister:\n"));
 	printf(_("  -N SERVICENAME  service name with which to register PostgreSQL server\n"));
 	printf(_("  -P PASSWORD     password of account to register PostgreSQL server\n"));
@@ -2067,7 +2044,7 @@ set_sig(char *signame)
 }
 
 
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 static void
 set_starttype(char *starttypeopt)
 {
@@ -2280,7 +2257,7 @@ main(int argc, char **argv)
 					silent_mode = true;
 					break;
 				case 'S':
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 					set_starttype(optarg);
 #else
 					write_stderr(_("%s: -S option not supported on this platform\n"),
@@ -2353,7 +2330,7 @@ main(int argc, char **argv)
 				set_sig(argv[++optind]);
 				killproc = atol(argv[++optind]);
 			}
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 			else if (strcmp(argv[optind], "register") == 0)
 				ctl_command = REGISTER_COMMAND;
 			else if (strcmp(argv[optind], "unregister") == 0)
@@ -2457,7 +2434,7 @@ main(int argc, char **argv)
 		case KILL_COMMAND:
 			do_kill(killproc);
 			break;
-#if defined(WIN32) || defined(__CYGWIN__)
+#ifdef WIN32
 		case REGISTER_COMMAND:
 			pgwin32_doRegister();
 			break;