Skip to content

Commit 53c949c

Browse files
committed
Remove Cygwin-specific code from pg_ctl
This code has been there for a long time, but it's never really been needed. Cygwin has its own utility for registering, unregistering, stopping and starting Windows services, and that's what's used in the Cygwin postgres packages. So now pg_ctl for Cygwin looks like it is for any Unix platform. Michael Paquier and me
1 parent 85f2228 commit 53c949c

File tree

1 file changed

+17
-52
lines changed

1 file changed

+17
-52
lines changed

src/bin/pg_ctl/pg_ctl.c

Lines changed: 17 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@
3939
#include "getopt_long.h"
4040
#include "miscadmin.h"
4141

42-
#if defined(__CYGWIN__)
43-
#include <sys/cygwin.h>
44-
#include <windows.h>
45-
/* Cygwin defines WIN32 in windows.h, but we don't want it. */
46-
#undef WIN32
47-
#endif
48-
4942
/* PID can be negative for standalone backend */
5043
typedef long pgpid_t;
5144

@@ -105,7 +98,7 @@ static char backup_file[MAXPGPATH];
10598
static char recovery_file[MAXPGPATH];
10699
static char promote_file[MAXPGPATH];
107100

108-
#if defined(WIN32) || defined(__CYGWIN__)
101+
#ifdef WIN32
109102
static DWORD pgctl_start_type = SERVICE_AUTO_START;
110103
static SERVICE_STATUS status;
111104
static SERVICE_STATUS_HANDLE hStatus = (SERVICE_STATUS_HANDLE) 0;
@@ -133,7 +126,7 @@ static void do_kill(pgpid_t pid);
133126
static void print_msg(const char *msg);
134127
static void adjust_data_dir(void);
135128

136-
#if defined(WIN32) || defined(__CYGWIN__)
129+
#ifdef WIN32
137130
#if (_MSC_VER >= 1800)
138131
#include <versionhelpers.h>
139132
#else
@@ -165,7 +158,7 @@ static void unlimit_core_size(void);
165158
#endif
166159

167160

168-
#if defined(WIN32) || defined(__CYGWIN__)
161+
#ifdef WIN32
169162
static void
170163
write_eventlog(int level, const char *line)
171164
{
@@ -207,20 +200,11 @@ write_stderr(const char *fmt,...)
207200
va_list ap;
208201

209202
va_start(ap, fmt);
210-
#if !defined(WIN32) && !defined(__CYGWIN__)
203+
#ifndef WIN32
211204
/* On Unix, we just fprintf to stderr */
212205
vfprintf(stderr, fmt, ap);
213206
#else
214207

215-
/*
216-
* On Cygwin, we don't yet have a reliable mechanism to detect when
217-
* we're being run as a service, so fall back to the old (and broken)
218-
* stderr test.
219-
*/
220-
#ifdef __CYGWIN__
221-
#define pgwin32_is_service() (isatty(fileno(stderr)))
222-
#endif
223-
224208
/*
225209
* On Win32, we print to stderr if running on a console, or write to
226210
* eventlog if running as a service
@@ -718,7 +702,7 @@ test_postmaster_connection(pgpid_t pm_pid, bool do_checkpoint)
718702
#endif
719703

720704
/* No response, or startup still in process; wait */
721-
#if defined(WIN32)
705+
#ifdef WIN32
722706
if (do_checkpoint)
723707
{
724708
/*
@@ -1342,7 +1326,7 @@ do_kill(pgpid_t pid)
13421326
}
13431327
}
13441328

1345-
#if defined(WIN32) || defined(__CYGWIN__)
1329+
#ifdef WIN32
13461330

13471331
#if (_MSC_VER < 1800)
13481332
static bool
@@ -1408,20 +1392,6 @@ pgwin32_CommandLine(bool registration)
14081392
}
14091393
}
14101394

1411-
#ifdef __CYGWIN__
1412-
/* need to convert to windows path */
1413-
{
1414-
char buf[MAXPGPATH];
1415-
1416-
#if CYGWIN_VERSION_DLL_MAJOR >= 1007
1417-
cygwin_conv_path(CCP_POSIX_TO_WIN_A, cmdPath, buf, sizeof(buf));
1418-
#else
1419-
cygwin_conv_to_full_win32_path(cmdPath, buf);
1420-
#endif
1421-
strcpy(cmdPath, buf);
1422-
}
1423-
#endif
1424-
14251395
/* if path does not end in .exe, append it */
14261396
if (strlen(cmdPath) < 4 ||
14271397
pg_strcasecmp(cmdPath + strlen(cmdPath) - 4, ".exe") != 0)
@@ -1775,10 +1745,8 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
17751745
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken))
17761746
{
17771747
/*
1778-
* Most Windows targets make DWORD a 32-bit unsigned long. Cygwin
1779-
* x86_64, an LP64 target, makes it a 32-bit unsigned int. In code
1780-
* built for Cygwin as well as for native Windows targets, cast DWORD
1781-
* before printing.
1748+
* Most Windows targets make DWORD a 32-bit unsigned long, but
1749+
* in case it doesn't cast DWORD before printing.
17821750
*/
17831751
write_stderr(_("%s: could not open process token: error code %lu\n"),
17841752
progname, (unsigned long) GetLastError());
@@ -1819,10 +1787,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
18191787
return 0;
18201788
}
18211789

1822-
#ifndef __CYGWIN__
18231790
AddUserToTokenDacl(restrictedToken);
1824-
#endif
1825-
18261791
r = CreateProcessAsUser(restrictedToken, NULL, cmd, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, processInfo);
18271792

18281793
Kernel32Handle = LoadLibrary("KERNEL32.DLL");
@@ -1926,7 +1891,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
19261891
*/
19271892
return r;
19281893
}
1929-
#endif /* defined(WIN32) || defined(__CYGWIN__) */
1894+
#endif /* WIN32 */
19301895

19311896
static void
19321897
do_advice(void)
@@ -1950,15 +1915,15 @@ do_help(void)
19501915
printf(_(" %s status [-D DATADIR]\n"), progname);
19511916
printf(_(" %s promote [-D DATADIR] [-s]\n"), progname);
19521917
printf(_(" %s kill SIGNALNAME PID\n"), progname);
1953-
#if defined(WIN32) || defined(__CYGWIN__)
1918+
#ifdef WIN32
19541919
printf(_(" %s register [-N SERVICENAME] [-U USERNAME] [-P PASSWORD] [-D DATADIR]\n"
19551920
" [-S START-TYPE] [-w] [-t SECS] [-o \"OPTIONS\"]\n"), progname);
19561921
printf(_(" %s unregister [-N SERVICENAME]\n"), progname);
19571922
#endif
19581923

19591924
printf(_("\nCommon options:\n"));
19601925
printf(_(" -D, --pgdata=DATADIR location of the database storage area\n"));
1961-
#if defined(WIN32) || defined(__CYGWIN__)
1926+
#ifdef WIN32
19621927
printf(_(" -e SOURCE event source for logging when running as a service\n"));
19631928
#endif
19641929
printf(_(" -s, --silent only print errors, no informational messages\n"));
@@ -1991,7 +1956,7 @@ do_help(void)
19911956
printf(_("\nAllowed signal names for kill:\n"));
19921957
printf(" ABRT HUP INT QUIT TERM USR1 USR2\n");
19931958

1994-
#if defined(WIN32) || defined(__CYGWIN__)
1959+
#ifdef WIN32
19951960
printf(_("\nOptions for register and unregister:\n"));
19961961
printf(_(" -N SERVICENAME service name with which to register PostgreSQL server\n"));
19971962
printf(_(" -P PASSWORD password of account to register PostgreSQL server\n"));
@@ -2067,7 +2032,7 @@ set_sig(char *signame)
20672032
}
20682033

20692034

2070-
#if defined(WIN32) || defined(__CYGWIN__)
2035+
#ifdef WIN32
20712036
static void
20722037
set_starttype(char *starttypeopt)
20732038
{
@@ -2167,7 +2132,7 @@ main(int argc, char **argv)
21672132
int c;
21682133
pgpid_t killproc = 0;
21692134

2170-
#if defined(WIN32) || defined(__CYGWIN__)
2135+
#ifdef WIN32
21712136
setvbuf(stderr, NULL, _IONBF, 0);
21722137
#endif
21732138

@@ -2280,7 +2245,7 @@ main(int argc, char **argv)
22802245
silent_mode = true;
22812246
break;
22822247
case 'S':
2283-
#if defined(WIN32) || defined(__CYGWIN__)
2248+
#ifdef WIN32
22842249
set_starttype(optarg);
22852250
#else
22862251
write_stderr(_("%s: -S option not supported on this platform\n"),
@@ -2353,7 +2318,7 @@ main(int argc, char **argv)
23532318
set_sig(argv[++optind]);
23542319
killproc = atol(argv[++optind]);
23552320
}
2356-
#if defined(WIN32) || defined(__CYGWIN__)
2321+
#ifdef WIN32
23572322
else if (strcmp(argv[optind], "register") == 0)
23582323
ctl_command = REGISTER_COMMAND;
23592324
else if (strcmp(argv[optind], "unregister") == 0)
@@ -2457,7 +2422,7 @@ main(int argc, char **argv)
24572422
case KILL_COMMAND:
24582423
do_kill(killproc);
24592424
break;
2460-
#if defined(WIN32) || defined(__CYGWIN__)
2425+
#ifdef WIN32
24612426
case REGISTER_COMMAND:
24622427
pgwin32_doRegister();
24632428
break;

0 commit comments

Comments
 (0)