I have applied the attached patch which will allow service use on Cygwin
using pg_ctl. A few of your #ifndef changes were backwards so you might
want to test the attached version to make sure it still works on Cygwin.
---------------------------------------------------------------------------
Reini Urban wrote:
> I'd like to have this nice new features also :)
>
> Just redefine WIN32 #ifdef __CYGWIN___ or the clean and long way as in
> my patch?
> I'm not sure about any dirty side-effects.
>
> Builds fine and works as expected.
> (Just tablespace symlinks not yet. Will get to that soon.)
> --- postgresql-8.0.0cvs/src/bin/pg_ctl/pg_ctl.c.orig 2004-09-02 22:07:50.000000000 +0200
> +++ postgresql-8.0.0cvs/src/bin/pg_ctl/pg_ctl.c 2004-10-07 05:29:28.938946400 +0200
> @@ -20,6 +20,9 @@
>
> #include "libpq/pqsignal.h"
> #include "getopt_long.h"
> +#if defined(__CYGWIN__)
> +#include <windows.h>
> +#endif
>
> #ifndef HAVE_OPTRESET
> int optreset;
> @@ -95,7 +98,7 @@
> static void do_status(void);
> static void do_kill(pgpid_t pid);
>
> -#ifdef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> static bool pgwin32_IsInstalled(SC_HANDLE);
> static char *pgwin32_CommandLine(bool);
> static void pgwin32_doRegister();
> @@ -116,7 +119,7 @@
> static char conf_file[MAXPGPATH];
>
>
> -#ifdef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> static void
> write_eventlog(int level, const char *line)
> {
> @@ -154,7 +157,7 @@
> va_list ap;
>
> va_start(ap, fmt);
> -#ifndef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> /* On Unix, we just fprintf to stderr */
> vfprintf(stderr, fmt, ap);
> #else
> @@ -317,7 +320,7 @@
> * http://dev.remotenetworktechnology.com/cmd/cmdfaq.htm
> */
> if (log_file != NULL)
> -#ifndef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1 &%s",
> #else
> snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s",
> @@ -325,7 +328,7 @@
> SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
> DEVNULL, log_file, SYSTEMQUOTE);
> else
> -#ifndef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" 2>&1 &%s",
> #else
> snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" 2>&1%s",
> @@ -803,7 +806,7 @@
> }
> }
>
> -#ifdef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
>
> static bool
> pgwin32_IsInstalled(SC_HANDLE hSCM)
> @@ -1197,7 +1200,7 @@
> int c;
> pgpid_t killproc = 0;
>
> -#ifdef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> setvbuf(stderr, NULL, _IONBF, 0);
> #endif
>
> @@ -1344,7 +1347,7 @@
> set_sig(argv[++optind]);
> killproc = atol(argv[++optind]);
> }
> -#ifdef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> else if (strcmp(argv[optind], "register") == 0)
> ctl_command = REGISTER_COMMAND;
> else if (strcmp(argv[optind], "unregister") == 0)
> @@ -1434,7 +1437,7 @@
> case KILL_COMMAND:
> do_kill(killproc);
> break;
> -#ifdef WIN32
> +#if defined(WIN32) || defined(__CYGWIN__)
> case REGISTER_COMMAND:
> pgwin32_doRegister();
> break;
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
--
Bruce Momjian | http://candle.pha.pa.us
pgman@candle.pha.pa.us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
Index: src/bin/pg_ctl/pg_ctl.c
===================================================================
RCS file: /cvsroot/pgsql/src/bin/pg_ctl/pg_ctl.c,v
retrieving revision 1.34
diff -c -c -r1.34 pg_ctl.c
*** src/bin/pg_ctl/pg_ctl.c 12 Oct 2004 21:54:43 -0000 1.34
--- src/bin/pg_ctl/pg_ctl.c 13 Oct 2004 10:32:41 -0000
***************
*** 21,26 ****
--- 21,30 ----
#include "libpq/pqsignal.h"
#include "getopt_long.h"
+ #if defined(__CYGWIN__)
+ #include <windows.h>
+ #endif
+
#ifndef HAVE_OPTRESET
int optreset;
#endif
***************
*** 95,101 ****
static void do_status(void);
static void do_kill(pgpid_t pid);
! #ifdef WIN32
static bool pgwin32_IsInstalled(SC_HANDLE);
static char *pgwin32_CommandLine(bool);
static void pgwin32_doRegister();
--- 99,105 ----
static void do_status(void);
static void do_kill(pgpid_t pid);
! #if defined(WIN32) || defined(__CYGWIN__)
static bool pgwin32_IsInstalled(SC_HANDLE);
static char *pgwin32_CommandLine(bool);
static void pgwin32_doRegister();
***************
*** 116,122 ****
static char conf_file[MAXPGPATH];
! #ifdef WIN32
static void
write_eventlog(int level, const char *line)
{
--- 120,126 ----
static char conf_file[MAXPGPATH];
! #if defined(WIN32) || defined(__CYGWIN__)
static void
write_eventlog(int level, const char *line)
{
***************
*** 154,160 ****
va_list ap;
va_start(ap, fmt);
! #ifndef WIN32
/* On Unix, we just fprintf to stderr */
vfprintf(stderr, fmt, ap);
#else
--- 158,164 ----
va_list ap;
va_start(ap, fmt);
! #if !defined(WIN32) && !defined(__CYGWIN__)
/* On Unix, we just fprintf to stderr */
vfprintf(stderr, fmt, ap);
#else
***************
*** 318,324 ****
* http://dev.remotenetworktechnology.com/cmd/cmdfaq.htm
*/
if (log_file != NULL)
! #ifndef WIN32
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1 &%s",
#else
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s",
--- 322,328 ----
* http://dev.remotenetworktechnology.com/cmd/cmdfaq.htm
*/
if (log_file != NULL)
! #if !defined(WIN32) && !defined(__CYGWIN__)
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" >> \"%s\" 2>&1 &%s",
#else
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" >> \"%s\" 2>&1%s",
***************
*** 326,332 ****
SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
DEVNULL, log_file, SYSTEMQUOTE);
else
! #ifndef WIN32
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" 2>&1 &%s",
#else
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" 2>&1%s",
--- 330,336 ----
SYSTEMQUOTE, postgres_path, pgdata_opt, post_opts,
DEVNULL, log_file, SYSTEMQUOTE);
else
! #if !defined(WIN32) && !defined(__CYGWIN__)
snprintf(cmd, MAXPGPATH, "%s\"%s\" %s%s < \"%s\" 2>&1 &%s",
#else
snprintf(cmd, MAXPGPATH, "%sSTART /B \"\" \"%s\" %s%s < \"%s\" 2>&1%s",
***************
*** 807,813 ****
}
}
! #ifdef WIN32
static bool
pgwin32_IsInstalled(SC_HANDLE hSCM)
--- 811,817 ----
}
}
! #if defined(WIN32) || defined(__CYGWIN__)
static bool
pgwin32_IsInstalled(SC_HANDLE hSCM)
***************
*** 1085,1098 ****
printf(_(" %s reload [-D DATADIR] [-s]\n"), progname);
printf(_(" %s status [-D DATADIR]\n"), progname);
printf(_(" %s kill SIGNALNAME PROCESSID\n"), progname);
! #ifdef WIN32
printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR] [-w] [-o \"OPTIONS\"]\n"),
progname);
printf(_(" %s unregister [-N SERVICENAME]\n"), progname);
#endif
printf(_("Common options:\n"));
printf(_(" -D, --pgdata DATADIR location of the database storage area\n"));
printf(_(" -s, --silent only print errors, no informational messages\n"));
! #ifdef WIN32
printf(_(" -N service name with which to register PostgreSQL server\n"));
printf(_(" -P password of account to register PostgreSQL server\n"));
printf(_(" -U user name of account to register PostgreSQL server\n"));
--- 1089,1102 ----
printf(_(" %s reload [-D DATADIR] [-s]\n"), progname);
printf(_(" %s status [-D DATADIR]\n"), progname);
printf(_(" %s kill SIGNALNAME PROCESSID\n"), progname);
! #if defined(WIN32) || defined(__CYGWIN__)
printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR] [-w] [-o \"OPTIONS\"]\n"),
progname);
printf(_(" %s unregister [-N SERVICENAME]\n"), progname);
#endif
printf(_("Common options:\n"));
printf(_(" -D, --pgdata DATADIR location of the database storage area\n"));
printf(_(" -s, --silent only print errors, no informational messages\n"));
! #if defined(WIN32) || defined(__CYGWIN__)
printf(_(" -N service name with which to register PostgreSQL server\n"));
printf(_(" -P password of account to register PostgreSQL server\n"));
printf(_(" -U user name of account to register PostgreSQL server\n"));
***************
*** 1201,1207 ****
int c;
pgpid_t killproc = 0;
! #ifdef WIN32
setvbuf(stderr, NULL, _IONBF, 0);
#endif
--- 1205,1211 ----
int c;
pgpid_t killproc = 0;
! #if defined(WIN32) || defined(__CYGWIN__)
setvbuf(stderr, NULL, _IONBF, 0);
#endif
***************
*** 1348,1354 ****
set_sig(argv[++optind]);
killproc = atol(argv[++optind]);
}
! #ifdef WIN32
else if (strcmp(argv[optind], "register") == 0)
ctl_command = REGISTER_COMMAND;
else if (strcmp(argv[optind], "unregister") == 0)
--- 1352,1358 ----
set_sig(argv[++optind]);
killproc = atol(argv[++optind]);
}
! #if defined(WIN32) || defined(__CYGWIN__)
else if (strcmp(argv[optind], "register") == 0)
ctl_command = REGISTER_COMMAND;
else if (strcmp(argv[optind], "unregister") == 0)
***************
*** 1438,1444 ****
case KILL_COMMAND:
do_kill(killproc);
break;
! #ifdef WIN32
case REGISTER_COMMAND:
pgwin32_doRegister();
break;
--- 1442,1448 ----
case KILL_COMMAND:
do_kill(killproc);
break;
! #if defined(WIN32) || defined(__CYGWIN__)
case REGISTER_COMMAND:
pgwin32_doRegister();
break;