@ -18,7 +18,9 @@
# endif
# endif
# include "postgres_fe.h"
# include "postgres_fe.h"
# include "libpq-fe.h"
# include "libpq-fe.h"
# include "pqexpbuffer.h"
# include <fcntl.h>
# include <fcntl.h>
# include <locale.h>
# include <locale.h>
@ -1238,16 +1240,13 @@ pgwin32_IsInstalled(SC_HANDLE hSCM)
static char *
static char *
pgwin32_CommandLine ( bool registration )
pgwin32_CommandLine ( bool registration )
{
{
static char cmdLine [ MAXPGPATH ] ;
PQExpBuffer cmdLine = createPQExpBuffer ( ) ;
char cmdPath [ MAXPGPATH ] ;
int ret ;
int ret ;
# ifdef __CYGWIN__
char buf [ MAXPGPATH ] ;
# endif
if ( registration )
if ( registration )
{
{
ret = find_my_exec ( argv0 , cmdLine ) ;
ret = find_my_exec ( argv0 , cmdPath ) ;
if ( ret ! = 0 )
if ( ret ! = 0 )
{
{
write_stderr ( _ ( " %s: could not find own program executable \n " ) , progname ) ;
write_stderr ( _ ( " %s: could not find own program executable \n " ) , progname ) ;
@ -1257,7 +1256,7 @@ pgwin32_CommandLine(bool registration)
else
else
{
{
ret = find_other_exec ( argv0 , " postgres " , PG_BACKEND_VERSIONSTR ,
ret = find_other_exec ( argv0 , " postgres " , PG_BACKEND_VERSIONSTR ,
cmdLine ) ;
cmdPath ) ;
if ( ret ! = 0 )
if ( ret ! = 0 )
{
{
write_stderr ( _ ( " %s: could not find postgres program executable \n " ) , progname ) ;
write_stderr ( _ ( " %s: could not find postgres program executable \n " ) , progname ) ;
@ -1267,54 +1266,57 @@ pgwin32_CommandLine(bool registration)
# ifdef __CYGWIN__
# ifdef __CYGWIN__
/* need to convert to windows path */
/* need to convert to windows path */
{
char buf [ MAXPGPATH ] ;
# if CYGWIN_VERSION_DLL_MAJOR >= 1007
# if CYGWIN_VERSION_DLL_MAJOR >= 1007
cygwin_conv_path ( CCP_POSIX_TO_WIN_A , cmdLine , buf , sizeof ( buf ) ) ;
cygwin_conv_path ( CCP_POSIX_TO_WIN_A , cmdPath , buf , sizeof ( buf ) ) ;
# else
# else
cygwin_conv_to_full_win32_path ( cmdLine , buf ) ;
cygwin_conv_to_full_win32_path ( cmdPath , buf ) ;
# endif
# endif
strcpy ( cmdLine , buf ) ;
strcpy ( cmdPath , buf ) ;
}
# endif
# endif
/* if path does not end in .exe, append it */
if ( strlen ( cmdPath ) < 4 | |
pg_strcasecmp ( cmdPath + strlen ( cmdPath ) - 4 , " .exe " ) ! = 0 )
snprintf ( cmdPath + strlen ( cmdPath ) , sizeof ( cmdPath ) - strlen ( cmdPath ) ,
" .exe " ) ;
/* use backslashes in path to avoid problems with some third-party tools */
make_native_path ( cmdPath ) ;
/* be sure to double-quote the executable's name in the command */
appendPQExpBuffer ( cmdLine , " \" %s \" " , cmdPath ) ;
/* append assorted switches to the command line, as needed */
if ( registration )
if ( registration )
{
appendPQExpBuffer ( cmdLine , " runservice -N \" %s \" " ,
if ( pg_strcasecmp ( cmdLine + strlen ( cmdLine ) - 4 , " .exe " ) ! = 0 )
register_servicename ) ;
{
/* If commandline does not end in .exe, append it */
strcat ( cmdLine , " .exe " ) ;
}
strcat ( cmdLine , " runservice -N \" " ) ;
strcat ( cmdLine , register_servicename ) ;
strcat ( cmdLine , " \" " ) ;
}
if ( pg_config )
if ( pg_config )
{
appendPQExpBuffer ( cmdLine , " -D \" %s \" " , pg_config ) ;
strcat ( cmdLine , " -D \" " ) ;
strcat ( cmdLine , pg_config ) ;
strcat ( cmdLine , " \" " ) ;
}
if ( registration & & do_wait )
if ( registration & & do_wait )
strcat ( cmdLine , " -w " ) ;
appendPQExpBuffer ( cmdLine , " -w " ) ;
if ( registration & & wait_seconds ! = DEFAULT_WAIT )
if ( registration & & wait_seconds ! = DEFAULT_WAIT )
/* concatenate */
appendPQExpBuffer ( cmdLine , " -t %d " , wait_seconds ) ;
sprintf ( cmdLine + strlen ( cmdLine ) , " -t %d " , wait_seconds ) ;
if ( registration & & silent_mode )
if ( registration & & silent_mode )
strcat ( cmdLine , " -s " ) ;
appendPQExpBuffer ( cmdLine , " -s " ) ;
if ( post_opts )
if ( post_opts )
{
{
strcat ( cmdLine , " " ) ;
if ( registration )
strcat ( cmdLine , " -o \" " ) ;
strcat ( cmdLine , post_opts ) ;
if ( registration )
if ( registration )
strcat ( cmdLine , " \" " ) ;
appendPQExpBuffer ( cmdLine , " -o \" %s \" " , post_opts ) ;
else
appendPQExpBuffer ( cmdLine , " %s " , post_opts ) ;
}
}
return cmdLine ;
return cmdLine - > data ;
}
}
static void
static void
@ -1745,7 +1747,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
*/
*/
return r ;
return r ;
}
}
# endif
# endif /* defined(WIN32) || defined(__CYGWIN__) */
static void
static void
do_advice ( void )
do_advice ( void )