@ -39,13 +39,6 @@
# include "getopt_long.h"
# include "getopt_long.h"
# include "miscadmin.h"
# include "miscadmin.h"
# if defined(__CYGWIN__)
# include <sys/cygwin.h>
# include <windows.h>
/* Cygwin defines WIN32 in windows.h, but we don't want it. */
# undef WIN32
# endif
/* PID can be negative for standalone backend */
/* PID can be negative for standalone backend */
typedef long pgpid_t ;
typedef long pgpid_t ;
@ -105,7 +98,7 @@ static char backup_file[MAXPGPATH];
static char recovery_file [ MAXPGPATH ] ;
static char recovery_file [ MAXPGPATH ] ;
static char promote_file [ MAXPGPATH ] ;
static char promote_file [ MAXPGPATH ] ;
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
static DWORD pgctl_start_type = SERVICE_AUTO_START ;
static DWORD pgctl_start_type = SERVICE_AUTO_START ;
static SERVICE_STATUS status ;
static SERVICE_STATUS status ;
static SERVICE_STATUS_HANDLE hStatus = ( SERVICE_STATUS_HANDLE ) 0 ;
static SERVICE_STATUS_HANDLE hStatus = ( SERVICE_STATUS_HANDLE ) 0 ;
@ -133,7 +126,7 @@ static void do_kill(pgpid_t pid);
static void print_msg ( const char * msg ) ;
static void print_msg ( const char * msg ) ;
static void adjust_data_dir ( void ) ;
static void adjust_data_dir ( void ) ;
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
# if (_MSC_VER >= 1800)
# if (_MSC_VER >= 1800)
# include <versionhelpers.h>
# include <versionhelpers.h>
# else
# else
@ -165,7 +158,7 @@ static void unlimit_core_size(void);
# endif
# endif
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
static void
static void
write_eventlog ( int level , const char * line )
write_eventlog ( int level , const char * line )
{
{
@ -207,20 +200,11 @@ write_stderr(const char *fmt,...)
va_list ap ;
va_list ap ;
va_start ( ap , fmt ) ;
va_start ( ap , fmt ) ;
# if !defined(WIN32) && !defined(__CYGWIN__)
# ifndef WIN32
/* On Unix, we just fprintf to stderr */
/* On Unix, we just fprintf to stderr */
vfprintf ( stderr , fmt , ap ) ;
vfprintf ( stderr , fmt , ap ) ;
# else
# 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
* On Win32 , we print to stderr if running on a console , or write to
* eventlog if running as a service
* eventlog if running as a service
@ -718,7 +702,7 @@ test_postmaster_connection(pgpid_t pm_pid, bool do_checkpoint)
# endif
# endif
/* No response, or startup still in process; wait */
/* No response, or startup still in process; wait */
# if defined(WIN32)
# ifdef WIN32
if ( do_checkpoint )
if ( do_checkpoint )
{
{
/*
/*
@ -1342,7 +1326,7 @@ do_kill(pgpid_t pid)
}
}
}
}
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
# if (_MSC_VER < 1800)
# if (_MSC_VER < 1800)
static bool
static bool
@ -1408,20 +1392,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 path does not end in .exe, append it */
if ( strlen ( cmdPath ) < 4 | |
if ( strlen ( cmdPath ) < 4 | |
pg_strcasecmp ( cmdPath + strlen ( cmdPath ) - 4 , " .exe " ) ! = 0 )
pg_strcasecmp ( cmdPath + strlen ( cmdPath ) - 4 , " .exe " ) ! = 0 )
@ -1775,10 +1745,8 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
if ( ! OpenProcessToken ( GetCurrentProcess ( ) , TOKEN_ALL_ACCESS , & origToken ) )
if ( ! OpenProcessToken ( GetCurrentProcess ( ) , TOKEN_ALL_ACCESS , & origToken ) )
{
{
/*
/*
* Most Windows targets make DWORD a 32 - bit unsigned long . Cygwin
* Most Windows targets make DWORD a 32 - bit unsigned long , but
* x86_64 , an LP64 target , makes it a 32 - bit unsigned int . In code
* in case it doesn ' t cast DWORD before printing .
* built for Cygwin as well as for native Windows targets , cast DWORD
* before printing .
*/
*/
write_stderr ( _ ( " %s: could not open process token: error code %lu \n " ) ,
write_stderr ( _ ( " %s: could not open process token: error code %lu \n " ) ,
progname , ( unsigned long ) GetLastError ( ) ) ;
progname , ( unsigned long ) GetLastError ( ) ) ;
@ -1819,10 +1787,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
return 0 ;
return 0 ;
}
}
# ifndef __CYGWIN__
AddUserToTokenDacl ( restrictedToken ) ;
AddUserToTokenDacl ( restrictedToken ) ;
# endif
r = CreateProcessAsUser ( restrictedToken , NULL , cmd , NULL , NULL , TRUE , CREATE_SUSPENDED , NULL , NULL , & si , processInfo ) ;
r = CreateProcessAsUser ( restrictedToken , NULL , cmd , NULL , NULL , TRUE , CREATE_SUSPENDED , NULL , NULL , & si , processInfo ) ;
Kernel32Handle = LoadLibrary ( " KERNEL32.DLL " ) ;
Kernel32Handle = LoadLibrary ( " KERNEL32.DLL " ) ;
@ -1926,7 +1891,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
*/
*/
return r ;
return r ;
}
}
# endif /* defined( WIN32) || defined(__CYGWIN__) */
# endif /* WIN32 */
static void
static void
do_advice ( void )
do_advice ( void )
@ -1950,7 +1915,7 @@ do_help(void)
printf ( _ ( " %s status [-D DATADIR] \n " ) , progname ) ;
printf ( _ ( " %s status [-D DATADIR] \n " ) , progname ) ;
printf ( _ ( " %s promote [-D DATADIR] [-s] \n " ) , progname ) ;
printf ( _ ( " %s promote [-D DATADIR] [-s] \n " ) , progname ) ;
printf ( _ ( " %s kill SIGNALNAME PID \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 "
printf ( _ ( " %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR] \n "
" [-S START-TYPE] [-w] [-t SECS] [-o \" OPTIONS \" ] \n " ) , progname ) ;
" [-S START-TYPE] [-w] [-t SECS] [-o \" OPTIONS \" ] \n " ) , progname ) ;
printf ( _ ( " %s unregister [-N SERVICENAME] \n " ) , progname ) ;
printf ( _ ( " %s unregister [-N SERVICENAME] \n " ) , progname ) ;
@ -1958,7 +1923,7 @@ do_help(void)
printf ( _ ( " \n Common options: \n " ) ) ;
printf ( _ ( " \n Common options: \n " ) ) ;
printf ( _ ( " -D, --pgdata=DATADIR location of the database storage area \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 " ) ) ;
printf ( _ ( " -e SOURCE event source for logging when running as a service \n " ) ) ;
# endif
# endif
printf ( _ ( " -s, --silent only print errors, no informational messages \n " ) ) ;
printf ( _ ( " -s, --silent only print errors, no informational messages \n " ) ) ;
@ -1991,7 +1956,7 @@ do_help(void)
printf ( _ ( " \n Allowed signal names for kill: \n " ) ) ;
printf ( _ ( " \n Allowed signal names for kill: \n " ) ) ;
printf ( " ABRT HUP INT QUIT TERM USR1 USR2 \n " ) ;
printf ( " ABRT HUP INT QUIT TERM USR1 USR2 \n " ) ;
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
printf ( _ ( " \n Options for register and unregister: \n " ) ) ;
printf ( _ ( " \n Options for register and unregister: \n " ) ) ;
printf ( _ ( " -N SERVICENAME service name with which to register PostgreSQL server \n " ) ) ;
printf ( _ ( " -N SERVICENAME service name with which to register PostgreSQL server \n " ) ) ;
printf ( _ ( " -P PASSWORD password of account to register PostgreSQL server \n " ) ) ;
printf ( _ ( " -P PASSWORD password of account to register PostgreSQL server \n " ) ) ;
@ -2067,7 +2032,7 @@ set_sig(char *signame)
}
}
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
static void
static void
set_starttype ( char * starttypeopt )
set_starttype ( char * starttypeopt )
{
{
@ -2167,7 +2132,7 @@ main(int argc, char **argv)
int c ;
int c ;
pgpid_t killproc = 0 ;
pgpid_t killproc = 0 ;
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
setvbuf ( stderr , NULL , _IONBF , 0 ) ;
setvbuf ( stderr , NULL , _IONBF , 0 ) ;
# endif
# endif
@ -2280,7 +2245,7 @@ main(int argc, char **argv)
silent_mode = true ;
silent_mode = true ;
break ;
break ;
case ' S ' :
case ' S ' :
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
set_starttype ( optarg ) ;
set_starttype ( optarg ) ;
# else
# else
write_stderr ( _ ( " %s: -S option not supported on this platform \n " ) ,
write_stderr ( _ ( " %s: -S option not supported on this platform \n " ) ,
@ -2353,7 +2318,7 @@ main(int argc, char **argv)
set_sig ( argv [ + + optind ] ) ;
set_sig ( argv [ + + optind ] ) ;
killproc = atol ( argv [ + + optind ] ) ;
killproc = atol ( argv [ + + optind ] ) ;
}
}
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
else if ( strcmp ( argv [ optind ] , " register " ) = = 0 )
else if ( strcmp ( argv [ optind ] , " register " ) = = 0 )
ctl_command = REGISTER_COMMAND ;
ctl_command = REGISTER_COMMAND ;
else if ( strcmp ( argv [ optind ] , " unregister " ) = = 0 )
else if ( strcmp ( argv [ optind ] , " unregister " ) = = 0 )
@ -2457,7 +2422,7 @@ main(int argc, char **argv)
case KILL_COMMAND :
case KILL_COMMAND :
do_kill ( killproc ) ;
do_kill ( killproc ) ;
break ;
break ;
# if defined(WIN32) || defined(__CYGWIN__)
# ifdef WIN32
case REGISTER_COMMAND :
case REGISTER_COMMAND :
pgwin32_doRegister ( ) ;
pgwin32_doRegister ( ) ;
break ;
break ;