Commit 1af55e27 authored by Peter Eisentraut's avatar Peter Eisentraut

Use consistent format for reporting GetLastError()

Use something like "error code %lu" for reporting GetLastError()
values on Windows.  Previously, a mix of different wordings and
formats were in use.
parent 6c6a4153
...@@ -1405,8 +1405,8 @@ pg_SSPI_recvauth(Port *port) ...@@ -1405,8 +1405,8 @@ pg_SSPI_recvauth(Port *port)
secur32 = LoadLibrary("SECUR32.DLL"); secur32 = LoadLibrary("SECUR32.DLL");
if (secur32 == NULL) if (secur32 == NULL)
ereport(ERROR, ereport(ERROR,
(errmsg_internal("could not load secur32.dll: %d", (errmsg_internal("could not load secur32.dll: error code %lu",
(int) GetLastError()))); GetLastError())));
_QuerySecurityContextToken = (QUERY_SECURITY_CONTEXT_TOKEN_FN) _QuerySecurityContextToken = (QUERY_SECURITY_CONTEXT_TOKEN_FN)
GetProcAddress(secur32, "QuerySecurityContextToken"); GetProcAddress(secur32, "QuerySecurityContextToken");
...@@ -1414,8 +1414,8 @@ pg_SSPI_recvauth(Port *port) ...@@ -1414,8 +1414,8 @@ pg_SSPI_recvauth(Port *port)
{ {
FreeLibrary(secur32); FreeLibrary(secur32);
ereport(ERROR, ereport(ERROR,
(errmsg_internal("could not locate QuerySecurityContextToken in secur32.dll: %d", (errmsg_internal("could not locate QuerySecurityContextToken in secur32.dll: error code %lu",
(int) GetLastError()))); GetLastError())));
} }
r = (_QuerySecurityContextToken) (sspictx, &token); r = (_QuerySecurityContextToken) (sspictx, &token);
...@@ -1437,8 +1437,8 @@ pg_SSPI_recvauth(Port *port) ...@@ -1437,8 +1437,8 @@ pg_SSPI_recvauth(Port *port)
if (!GetTokenInformation(token, TokenUser, NULL, 0, &retlen) && GetLastError() != 122) if (!GetTokenInformation(token, TokenUser, NULL, 0, &retlen) && GetLastError() != 122)
ereport(ERROR, ereport(ERROR,
(errmsg_internal("could not get token user size: error code %d", (errmsg_internal("could not get token user size: error code %lu",
(int) GetLastError()))); GetLastError())));
tokenuser = malloc(retlen); tokenuser = malloc(retlen);
if (tokenuser == NULL) if (tokenuser == NULL)
...@@ -1447,14 +1447,14 @@ pg_SSPI_recvauth(Port *port) ...@@ -1447,14 +1447,14 @@ pg_SSPI_recvauth(Port *port)
if (!GetTokenInformation(token, TokenUser, tokenuser, retlen, &retlen)) if (!GetTokenInformation(token, TokenUser, tokenuser, retlen, &retlen))
ereport(ERROR, ereport(ERROR,
(errmsg_internal("could not get user token: error code %d", (errmsg_internal("could not get user token: error code %lu",
(int) GetLastError()))); GetLastError())));
if (!LookupAccountSid(NULL, tokenuser->User.Sid, accountname, &accountnamesize, if (!LookupAccountSid(NULL, tokenuser->User.Sid, accountname, &accountnamesize,
domainname, &domainnamesize, &accountnameuse)) domainname, &domainnamesize, &accountnameuse))
ereport(ERROR, ereport(ERROR,
(errmsg_internal("could not look up account SID: error code %d", (errmsg_internal("could not look up account SID: error code %lu",
(int) GetLastError()))); GetLastError())));
free(tokenuser); free(tokenuser);
......
...@@ -144,8 +144,8 @@ crashDumpHandler(struct _EXCEPTION_POINTERS * pExceptionInfo) ...@@ -144,8 +144,8 @@ crashDumpHandler(struct _EXCEPTION_POINTERS * pExceptionInfo)
NULL); NULL);
if (dumpFile == INVALID_HANDLE_VALUE) if (dumpFile == INVALID_HANDLE_VALUE)
{ {
write_stderr("could not open crash dump file \"%s\" for writing: error code %u\n", write_stderr("could not open crash dump file \"%s\" for writing: error code %lu\n",
dumpPath, (unsigned int) GetLastError()); dumpPath, GetLastError());
return EXCEPTION_CONTINUE_SEARCH; return EXCEPTION_CONTINUE_SEARCH;
} }
...@@ -153,8 +153,8 @@ crashDumpHandler(struct _EXCEPTION_POINTERS * pExceptionInfo) ...@@ -153,8 +153,8 @@ crashDumpHandler(struct _EXCEPTION_POINTERS * pExceptionInfo)
NULL, NULL)) NULL, NULL))
write_stderr("wrote crash dump to file \"%s\"\n", dumpPath); write_stderr("wrote crash dump to file \"%s\"\n", dumpPath);
else else
write_stderr("could not write crash dump to file \"%s\": error code %08x\n", write_stderr("could not write crash dump to file \"%s\": error code %lu\n",
dumpPath, (unsigned int) GetLastError()); dumpPath, GetLastError());
CloseHandle(dumpFile); CloseHandle(dumpFile);
} }
......
...@@ -42,8 +42,8 @@ LoadKernel32() ...@@ -42,8 +42,8 @@ LoadKernel32()
kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0); kernel32 = LoadLibraryEx("kernel32.dll", NULL, 0);
if (kernel32 == NULL) if (kernel32 == NULL)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not load kernel32.dll: %d", (errmsg_internal("could not load kernel32.dll: error code %lu",
(int) GetLastError()))); GetLastError())));
} }
...@@ -73,8 +73,8 @@ RegisterWaitForSingleObject(PHANDLE phNewWaitObject, ...@@ -73,8 +73,8 @@ RegisterWaitForSingleObject(PHANDLE phNewWaitObject,
if (_RegisterWaitForSingleObject == NULL) if (_RegisterWaitForSingleObject == NULL)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not locate RegisterWaitForSingleObject in kernel32.dll: %d", (errmsg_internal("could not locate RegisterWaitForSingleObject in kernel32.dll: error code %lu",
(int) GetLastError()))); GetLastError())));
} }
return (_RegisterWaitForSingleObject) return (_RegisterWaitForSingleObject)
......
...@@ -40,8 +40,8 @@ pgwin32_is_admin(void) ...@@ -40,8 +40,8 @@ pgwin32_is_admin(void)
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &AccessToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &AccessToken))
{ {
write_stderr("could not open process token: error code %d\n", write_stderr("could not open process token: error code %lu\n",
(int) GetLastError()); GetLastError());
exit(1); exit(1);
} }
...@@ -60,8 +60,8 @@ pgwin32_is_admin(void) ...@@ -60,8 +60,8 @@ pgwin32_is_admin(void)
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0,
0, &AdministratorsSid)) 0, &AdministratorsSid))
{ {
write_stderr("could not get SID for Administrators group: error code %d\n", write_stderr("could not get SID for Administrators group: error code %lu\n",
(int) GetLastError()); GetLastError());
exit(1); exit(1);
} }
...@@ -69,8 +69,8 @@ pgwin32_is_admin(void) ...@@ -69,8 +69,8 @@ pgwin32_is_admin(void)
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0,
0, &PowerUsersSid)) 0, &PowerUsersSid))
{ {
write_stderr("could not get SID for PowerUsers group: error code %d\n", write_stderr("could not get SID for PowerUsers group: error code %lu\n",
(int) GetLastError()); GetLastError());
exit(1); exit(1);
} }
...@@ -129,8 +129,8 @@ pgwin32_is_service(void) ...@@ -129,8 +129,8 @@ pgwin32_is_service(void)
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &AccessToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_READ, &AccessToken))
{ {
fprintf(stderr, "could not open process token: error code %d\n", fprintf(stderr, "could not open process token: error code %lu\n",
(int) GetLastError()); GetLastError());
return -1; return -1;
} }
...@@ -223,8 +223,8 @@ pgwin32_get_dynamic_tokeninfo(HANDLE token, TOKEN_INFORMATION_CLASS class, ...@@ -223,8 +223,8 @@ pgwin32_get_dynamic_tokeninfo(HANDLE token, TOKEN_INFORMATION_CLASS class,
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{ {
snprintf(errbuf, errsize, "could not get token information: error code %d\n", snprintf(errbuf, errsize, "could not get token information: error code %lu\n",
(int) GetLastError()); GetLastError());
return FALSE; return FALSE;
} }
...@@ -239,8 +239,8 @@ pgwin32_get_dynamic_tokeninfo(HANDLE token, TOKEN_INFORMATION_CLASS class, ...@@ -239,8 +239,8 @@ pgwin32_get_dynamic_tokeninfo(HANDLE token, TOKEN_INFORMATION_CLASS class,
if (!GetTokenInformation(token, class, *InfoBuffer, if (!GetTokenInformation(token, class, *InfoBuffer,
InfoBufferSize, &InfoBufferSize)) InfoBufferSize, &InfoBufferSize))
{ {
snprintf(errbuf, errsize, "could not get token information: error code %d\n", snprintf(errbuf, errsize, "could not get token information: error code %lu\n",
(int) GetLastError()); GetLastError());
return FALSE; return FALSE;
} }
......
...@@ -83,7 +83,7 @@ pgwin32_signal_initialize(void) ...@@ -83,7 +83,7 @@ pgwin32_signal_initialize(void)
pgwin32_signal_event = CreateEvent(NULL, TRUE, FALSE, NULL); pgwin32_signal_event = CreateEvent(NULL, TRUE, FALSE, NULL);
if (pgwin32_signal_event == NULL) if (pgwin32_signal_event == NULL)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not create signal event: %d", (int) GetLastError()))); (errmsg_internal("could not create signal event: error code %lu", GetLastError())));
/* Create thread for handling signals */ /* Create thread for handling signals */
signal_thread_handle = CreateThread(NULL, 0, pg_signal_thread, NULL, 0, NULL); signal_thread_handle = CreateThread(NULL, 0, pg_signal_thread, NULL, 0, NULL);
...@@ -186,8 +186,8 @@ pgwin32_create_signal_listener(pid_t pid) ...@@ -186,8 +186,8 @@ pgwin32_create_signal_listener(pid_t pid)
if (pipe == INVALID_HANDLE_VALUE) if (pipe == INVALID_HANDLE_VALUE)
ereport(ERROR, ereport(ERROR,
(errmsg("could not create signal listener pipe for PID %d: error code %d", (errmsg("could not create signal listener pipe for PID %d: error code %lu",
(int) pid, (int) GetLastError()))); (int) pid, GetLastError())));
return pipe; return pipe;
} }
...@@ -266,7 +266,7 @@ pg_signal_thread(LPVOID param) ...@@ -266,7 +266,7 @@ pg_signal_thread(LPVOID param)
if (pipe == INVALID_HANDLE_VALUE) if (pipe == INVALID_HANDLE_VALUE)
{ {
write_stderr("could not create signal listener pipe: error code %d; retrying\n", (int) GetLastError()); write_stderr("could not create signal listener pipe: error code %lu; retrying\n", GetLastError());
SleepEx(500, FALSE); SleepEx(500, FALSE);
continue; continue;
} }
...@@ -298,7 +298,7 @@ pg_signal_thread(LPVOID param) ...@@ -298,7 +298,7 @@ pg_signal_thread(LPVOID param)
* is nothing else we can do other than abort the whole * is nothing else we can do other than abort the whole
* process which will be even worse. * process which will be even worse.
*/ */
write_stderr("could not create signal listener pipe: error code %d; retrying\n", (int) GetLastError()); write_stderr("could not create signal listener pipe: error code %lu; retrying\n", GetLastError());
/* /*
* Keep going so we at least dispatch this signal. Hopefully, * Keep going so we at least dispatch this signal. Hopefully,
...@@ -309,8 +309,8 @@ pg_signal_thread(LPVOID param) ...@@ -309,8 +309,8 @@ pg_signal_thread(LPVOID param)
(LPTHREAD_START_ROUTINE) pg_signal_dispatch_thread, (LPTHREAD_START_ROUTINE) pg_signal_dispatch_thread,
(LPVOID) pipe, 0, NULL); (LPVOID) pipe, 0, NULL);
if (hThread == INVALID_HANDLE_VALUE) if (hThread == INVALID_HANDLE_VALUE)
write_stderr("could not create signal dispatch thread: error code %d\n", write_stderr("could not create signal dispatch thread: error code %lu\n",
(int) GetLastError()); GetLastError());
else else
CloseHandle(hThread); CloseHandle(hThread);
......
...@@ -143,11 +143,11 @@ pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout) ...@@ -143,11 +143,11 @@ pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
if (waitevent == INVALID_HANDLE_VALUE) if (waitevent == INVALID_HANDLE_VALUE)
ereport(ERROR, ereport(ERROR,
(errmsg_internal("could not create socket waiting event: %d", (int) GetLastError()))); (errmsg_internal("could not create socket waiting event: error code %lu", GetLastError())));
} }
else if (!ResetEvent(waitevent)) else if (!ResetEvent(waitevent))
ereport(ERROR, ereport(ERROR,
(errmsg_internal("could not reset socket waiting event: %d", (int) GetLastError()))); (errmsg_internal("could not reset socket waiting event: error code %lu", GetLastError())));
/* /*
* make sure we don't multiplex this kernel event object with a different * make sure we don't multiplex this kernel event object with a different
...@@ -221,7 +221,7 @@ pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout) ...@@ -221,7 +221,7 @@ pgwin32_waitforsinglesocket(SOCKET s, int what, int timeout)
if (r == WAIT_TIMEOUT) if (r == WAIT_TIMEOUT)
return 0; return 0;
ereport(ERROR, ereport(ERROR,
(errmsg_internal("unrecognized return value from WaitForMultipleObjects: %d (%d)", r, (int) GetLastError()))); (errmsg_internal("unrecognized return value from WaitForMultipleObjects: %d (%lu)", r, GetLastError())));
return 0; return 0;
} }
...@@ -567,7 +567,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c ...@@ -567,7 +567,7 @@ pgwin32_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, c
ZeroMemory(&resEvents, sizeof(resEvents)); ZeroMemory(&resEvents, sizeof(resEvents));
if (WSAEnumNetworkEvents(sockets[i], events[i], &resEvents) == SOCKET_ERROR) if (WSAEnumNetworkEvents(sockets[i], events[i], &resEvents) == SOCKET_ERROR)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("failed to enumerate network events: %d", (int) GetLastError()))); (errmsg_internal("failed to enumerate network events: error code %lu", GetLastError())));
/* Read activity? */ /* Read activity? */
if (readfds && FD_ISSET(sockets[i], readfds)) if (readfds && FD_ISSET(sockets[i], readfds))
{ {
...@@ -645,7 +645,7 @@ pgwin32_socket_strerror(int err) ...@@ -645,7 +645,7 @@ pgwin32_socket_strerror(int err)
handleDLL = LoadLibraryEx("netmsg.dll", NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE); handleDLL = LoadLibraryEx("netmsg.dll", NULL, DONT_RESOLVE_DLL_REFERENCES | LOAD_LIBRARY_AS_DATAFILE);
if (handleDLL == NULL) if (handleDLL == NULL)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not load netmsg.dll: %d", (int) GetLastError()))); (errmsg_internal("could not load netmsg.dll: error code %lu", GetLastError())));
} }
ZeroMemory(&wserrbuf, sizeof(wserrbuf)); ZeroMemory(&wserrbuf, sizeof(wserrbuf));
......
...@@ -97,8 +97,8 @@ setitimer(int which, const struct itimerval * value, struct itimerval * ovalue) ...@@ -97,8 +97,8 @@ setitimer(int which, const struct itimerval * value, struct itimerval * ovalue)
timerCommArea.event = CreateEvent(NULL, TRUE, FALSE, NULL); timerCommArea.event = CreateEvent(NULL, TRUE, FALSE, NULL);
if (timerCommArea.event == NULL) if (timerCommArea.event == NULL)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not create timer event: %d", (errmsg_internal("could not create timer event: error code %lu",
(int) GetLastError()))); GetLastError())));
MemSet(&timerCommArea.value, 0, sizeof(struct itimerval)); MemSet(&timerCommArea.value, 0, sizeof(struct itimerval));
...@@ -107,8 +107,8 @@ setitimer(int which, const struct itimerval * value, struct itimerval * ovalue) ...@@ -107,8 +107,8 @@ setitimer(int which, const struct itimerval * value, struct itimerval * ovalue)
timerThreadHandle = CreateThread(NULL, 0, pg_timer_thread, NULL, 0, NULL); timerThreadHandle = CreateThread(NULL, 0, pg_timer_thread, NULL, 0, NULL);
if (timerThreadHandle == INVALID_HANDLE_VALUE) if (timerThreadHandle == INVALID_HANDLE_VALUE)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not create timer thread: %d", (errmsg_internal("could not create timer thread: error code %lu",
(int) GetLastError()))); GetLastError())));
} }
/* Request the timer thread to change settings */ /* Request the timer thread to change settings */
......
...@@ -38,7 +38,7 @@ InitLatch(volatile Latch *latch) ...@@ -38,7 +38,7 @@ InitLatch(volatile Latch *latch)
latch->event = CreateEvent(NULL, TRUE, FALSE, NULL); latch->event = CreateEvent(NULL, TRUE, FALSE, NULL);
if (latch->event == NULL) if (latch->event == NULL)
elog(ERROR, "CreateEvent failed: error code %d", (int) GetLastError()); elog(ERROR, "CreateEvent failed: error code %lu", GetLastError());
} }
void void
...@@ -59,7 +59,7 @@ InitSharedLatch(volatile Latch *latch) ...@@ -59,7 +59,7 @@ InitSharedLatch(volatile Latch *latch)
latch->event = CreateEvent(&sa, TRUE, FALSE, NULL); latch->event = CreateEvent(&sa, TRUE, FALSE, NULL);
if (latch->event == NULL) if (latch->event == NULL)
elog(ERROR, "CreateEvent failed: error code %d", (int) GetLastError()); elog(ERROR, "CreateEvent failed: error code %lu", GetLastError());
} }
void void
...@@ -150,7 +150,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, ...@@ -150,7 +150,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
* will return immediately. * will return immediately.
*/ */
if (!ResetEvent(latchevent)) if (!ResetEvent(latchevent))
elog(ERROR, "ResetEvent failed: error code %d", (int) GetLastError()); elog(ERROR, "ResetEvent failed: error code %lu", GetLastError());
if ((wakeEvents & WL_LATCH_SET) && latch->is_set) if ((wakeEvents & WL_LATCH_SET) && latch->is_set)
{ {
result |= WL_LATCH_SET; result |= WL_LATCH_SET;
...@@ -164,7 +164,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, ...@@ -164,7 +164,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
rc = WaitForMultipleObjects(numevents, events, FALSE, timeout); rc = WaitForMultipleObjects(numevents, events, FALSE, timeout);
if (rc == WAIT_FAILED) if (rc == WAIT_FAILED)
elog(ERROR, "WaitForMultipleObjects() failed: error code %d", (int) GetLastError()); elog(ERROR, "WaitForMultipleObjects() failed: error code %lu", GetLastError());
/* Participate in Windows signal emulation */ /* Participate in Windows signal emulation */
else if (rc == WAIT_OBJECT_0 + 1) else if (rc == WAIT_OBJECT_0 + 1)
...@@ -188,7 +188,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, ...@@ -188,7 +188,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
ZeroMemory(&resEvents, sizeof(resEvents)); ZeroMemory(&resEvents, sizeof(resEvents));
if (WSAEnumNetworkEvents(sock, sockevent, &resEvents) == SOCKET_ERROR) if (WSAEnumNetworkEvents(sock, sockevent, &resEvents) == SOCKET_ERROR)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("failed to enumerate network events: %d", (int) GetLastError()))); (errmsg_internal("failed to enumerate network events: error code %lu", GetLastError())));
if ((wakeEvents & WL_SOCKET_READABLE) && if ((wakeEvents & WL_SOCKET_READABLE) &&
(resEvents.lNetworkEvents & FD_READ)) (resEvents.lNetworkEvents & FD_READ))
...@@ -203,7 +203,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock, ...@@ -203,7 +203,7 @@ WaitLatchOrSocket(volatile Latch *latch, int wakeEvents, pgsocket sock,
} }
/* Otherwise it must be the latch event */ /* Otherwise it must be the latch event */
else if (rc != WAIT_OBJECT_0) else if (rc != WAIT_OBJECT_0)
elog(ERROR, "unexpected return code from WaitForMultipleObjects(): %d", (int) rc); elog(ERROR, "unexpected return code from WaitForMultipleObjects(): %lu", rc);
} }
while (result == 0); while (result == 0);
......
...@@ -91,7 +91,7 @@ PGSemaphoreCreate(PGSemaphore sema) ...@@ -91,7 +91,7 @@ PGSemaphoreCreate(PGSemaphore sema)
} }
else else
ereport(PANIC, ereport(PANIC,
(errmsg("could not create semaphore: error code %d", (int) GetLastError()))); (errmsg("could not create semaphore: error code %lu", GetLastError())));
} }
/* /*
...@@ -158,7 +158,7 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK) ...@@ -158,7 +158,7 @@ PGSemaphoreLock(PGSemaphore sema, bool interruptOK)
if (errno != 0) if (errno != 0)
ereport(FATAL, ereport(FATAL,
(errmsg("could not lock semaphore: error code %d", (int) GetLastError()))); (errmsg("could not lock semaphore: error code %lu", GetLastError())));
} }
/* /*
...@@ -171,7 +171,7 @@ PGSemaphoreUnlock(PGSemaphore sema) ...@@ -171,7 +171,7 @@ PGSemaphoreUnlock(PGSemaphore sema)
{ {
if (!ReleaseSemaphore(*sema, 1, NULL)) if (!ReleaseSemaphore(*sema, 1, NULL))
ereport(FATAL, ereport(FATAL,
(errmsg("could not unlock semaphore: error code %d", (int) GetLastError()))); (errmsg("could not unlock semaphore: error code %lu", GetLastError())));
} }
/* /*
...@@ -200,7 +200,7 @@ PGSemaphoreTryLock(PGSemaphore sema) ...@@ -200,7 +200,7 @@ PGSemaphoreTryLock(PGSemaphore sema)
/* Otherwise we are in trouble */ /* Otherwise we are in trouble */
ereport(FATAL, ereport(FATAL,
(errmsg("could not try-lock semaphore: error code %d", (int) GetLastError()))); (errmsg("could not try-lock semaphore: error code %lu", GetLastError())));
/* keep compiler quiet */ /* keep compiler quiet */
return false; return false;
......
...@@ -45,7 +45,7 @@ GetSharedMemName(void) ...@@ -45,7 +45,7 @@ GetSharedMemName(void)
bufsize = GetFullPathName(DataDir, 0, NULL, NULL); bufsize = GetFullPathName(DataDir, 0, NULL, NULL);
if (bufsize == 0) if (bufsize == 0)
elog(FATAL, "could not get size for full pathname of datadir %s: %lu", elog(FATAL, "could not get size for full pathname of datadir %s: error code %lu",
DataDir, GetLastError()); DataDir, GetLastError());
retptr = malloc(bufsize + 18); /* 18 for Global\PostgreSQL: */ retptr = malloc(bufsize + 18); /* 18 for Global\PostgreSQL: */
...@@ -55,7 +55,7 @@ GetSharedMemName(void) ...@@ -55,7 +55,7 @@ GetSharedMemName(void)
strcpy(retptr, "Global\\PostgreSQL:"); strcpy(retptr, "Global\\PostgreSQL:");
r = GetFullPathName(DataDir, bufsize, retptr + 18, NULL); r = GetFullPathName(DataDir, bufsize, retptr + 18, NULL);
if (r == 0 || r > bufsize) if (r == 0 || r > bufsize)
elog(FATAL, "could not generate full pathname for datadir %s: %lu", elog(FATAL, "could not generate full pathname for datadir %s: error code %lu",
DataDir, GetLastError()); DataDir, GetLastError());
/* /*
...@@ -165,7 +165,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -165,7 +165,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
if (!hmap) if (!hmap)
ereport(FATAL, ereport(FATAL,
(errmsg("could not create shared memory segment: %lu", GetLastError()), (errmsg("could not create shared memory segment: error code %lu", GetLastError()),
errdetail("Failed system call was CreateFileMapping(size=%lu, name=%s).", errdetail("Failed system call was CreateFileMapping(size=%lu, name=%s).",
(unsigned long) size, szShareMem))); (unsigned long) size, szShareMem)));
...@@ -200,7 +200,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -200,7 +200,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
*/ */
if (!DuplicateHandle(GetCurrentProcess(), hmap, GetCurrentProcess(), &hmap2, 0, TRUE, DUPLICATE_SAME_ACCESS)) if (!DuplicateHandle(GetCurrentProcess(), hmap, GetCurrentProcess(), &hmap2, 0, TRUE, DUPLICATE_SAME_ACCESS))
ereport(FATAL, ereport(FATAL,
(errmsg("could not create shared memory segment: %lu", GetLastError()), (errmsg("could not create shared memory segment: error code %lu", GetLastError()),
errdetail("Failed system call was DuplicateHandle."))); errdetail("Failed system call was DuplicateHandle.")));
/* /*
...@@ -208,7 +208,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -208,7 +208,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
* care. * care.
*/ */
if (!CloseHandle(hmap)) if (!CloseHandle(hmap))
elog(LOG, "could not close handle to shared memory: %lu", GetLastError()); elog(LOG, "could not close handle to shared memory: error code %lu", GetLastError());
/* Register on-exit routine to delete the new segment */ /* Register on-exit routine to delete the new segment */
...@@ -221,7 +221,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port) ...@@ -221,7 +221,7 @@ PGSharedMemoryCreate(Size size, bool makePrivate, int port)
memAddress = MapViewOfFileEx(hmap2, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 0, NULL); memAddress = MapViewOfFileEx(hmap2, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, 0, NULL);
if (!memAddress) if (!memAddress)
ereport(FATAL, ereport(FATAL,
(errmsg("could not create shared memory segment: %lu", GetLastError()), (errmsg("could not create shared memory segment: error code %lu", GetLastError()),
errdetail("Failed system call was MapViewOfFileEx."))); errdetail("Failed system call was MapViewOfFileEx.")));
...@@ -272,12 +272,12 @@ PGSharedMemoryReAttach(void) ...@@ -272,12 +272,12 @@ PGSharedMemoryReAttach(void)
* Release memory region reservation that was made by the postmaster * Release memory region reservation that was made by the postmaster
*/ */
if (VirtualFree(UsedShmemSegAddr, 0, MEM_RELEASE) == 0) if (VirtualFree(UsedShmemSegAddr, 0, MEM_RELEASE) == 0)
elog(FATAL, "failed to release reserved memory region (addr=%p): %lu", elog(FATAL, "failed to release reserved memory region (addr=%p): error code %lu",
UsedShmemSegAddr, GetLastError()); UsedShmemSegAddr, GetLastError());
hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr); hdr = (PGShmemHeader *) MapViewOfFileEx(UsedShmemSegID, FILE_MAP_READ | FILE_MAP_WRITE, 0, 0, 0, UsedShmemSegAddr);
if (!hdr) if (!hdr)
elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): %lu", elog(FATAL, "could not reattach to shared memory (key=%p, addr=%p): error code %lu",
UsedShmemSegID, UsedShmemSegAddr, GetLastError()); UsedShmemSegID, UsedShmemSegAddr, GetLastError());
if (hdr != origUsedShmemSegAddr) if (hdr != origUsedShmemSegAddr)
elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)", elog(FATAL, "reattaching to shared memory returned unexpected address (got %p, expected %p)",
...@@ -302,7 +302,7 @@ PGSharedMemoryDetach(void) ...@@ -302,7 +302,7 @@ PGSharedMemoryDetach(void)
if (UsedShmemSegAddr != NULL) if (UsedShmemSegAddr != NULL)
{ {
if (!UnmapViewOfFile(UsedShmemSegAddr)) if (!UnmapViewOfFile(UsedShmemSegAddr))
elog(LOG, "could not unmap view of shared memory: %lu", GetLastError()); elog(LOG, "could not unmap view of shared memory: error code %lu", GetLastError());
UsedShmemSegAddr = NULL; UsedShmemSegAddr = NULL;
} }
...@@ -318,7 +318,7 @@ pgwin32_SharedMemoryDelete(int status, Datum shmId) ...@@ -318,7 +318,7 @@ pgwin32_SharedMemoryDelete(int status, Datum shmId)
{ {
PGSharedMemoryDetach(); PGSharedMemoryDetach();
if (!CloseHandle(DatumGetPointer(shmId))) if (!CloseHandle(DatumGetPointer(shmId)))
elog(LOG, "could not close handle to shared memory: %lu", GetLastError()); elog(LOG, "could not close handle to shared memory: error code %lu", GetLastError());
} }
/* /*
...@@ -351,7 +351,7 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild) ...@@ -351,7 +351,7 @@ pgwin32_ReserveSharedMemoryRegion(HANDLE hChild)
if (address == NULL) if (address == NULL)
{ {
/* Don't use FATAL since we're running in the postmaster */ /* Don't use FATAL since we're running in the postmaster */
elog(LOG, "could not reserve shared memory region (addr=%p) for child %p: %lu", elog(LOG, "could not reserve shared memory region (addr=%p) for child %p: error code %lu",
UsedShmemSegAddr, hChild, GetLastError()); UsedShmemSegAddr, hChild, GetLastError());
return false; return false;
} }
......
...@@ -3705,16 +3705,16 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3705,16 +3705,16 @@ internal_forkexec(int argc, char *argv[], Port *port)
NULL); NULL);
if (paramHandle == INVALID_HANDLE_VALUE) if (paramHandle == INVALID_HANDLE_VALUE)
{ {
elog(LOG, "could not create backend parameter file mapping: error code %d", elog(LOG, "could not create backend parameter file mapping: error code %lu",
(int) GetLastError()); GetLastError());
return -1; return -1;
} }
param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0, sizeof(BackendParameters)); param = MapViewOfFile(paramHandle, FILE_MAP_WRITE, 0, 0, sizeof(BackendParameters));
if (!param) if (!param)
{ {
elog(LOG, "could not map backend parameter memory: error code %d", elog(LOG, "could not map backend parameter memory: error code %lu",
(int) GetLastError()); GetLastError());
CloseHandle(paramHandle); CloseHandle(paramHandle);
return -1; return -1;
} }
...@@ -3754,8 +3754,8 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3754,8 +3754,8 @@ internal_forkexec(int argc, char *argv[], Port *port)
if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED, if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED,
NULL, NULL, &si, &pi)) NULL, NULL, &si, &pi))
{ {
elog(LOG, "CreateProcess call failed: %m (error code %d)", elog(LOG, "CreateProcess call failed: %m (error code %lu)",
(int) GetLastError()); GetLastError());
return -1; return -1;
} }
...@@ -3767,8 +3767,8 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3767,8 +3767,8 @@ internal_forkexec(int argc, char *argv[], Port *port)
*/ */
if (!TerminateProcess(pi.hProcess, 255)) if (!TerminateProcess(pi.hProcess, 255))
ereport(LOG, ereport(LOG,
(errmsg_internal("could not terminate unstarted process: error code %d", (errmsg_internal("could not terminate unstarted process: error code %lu",
(int) GetLastError()))); GetLastError())));
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
return -1; /* log made by save_backend_variables */ return -1; /* log made by save_backend_variables */
...@@ -3776,11 +3776,11 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3776,11 +3776,11 @@ internal_forkexec(int argc, char *argv[], Port *port)
/* Drop the parameter shared memory that is now inherited to the backend */ /* Drop the parameter shared memory that is now inherited to the backend */
if (!UnmapViewOfFile(param)) if (!UnmapViewOfFile(param))
elog(LOG, "could not unmap view of backend parameter file: error code %d", elog(LOG, "could not unmap view of backend parameter file: error code %lu",
(int) GetLastError()); GetLastError());
if (!CloseHandle(paramHandle)) if (!CloseHandle(paramHandle))
elog(LOG, "could not close handle to backend parameter file: error code %d", elog(LOG, "could not close handle to backend parameter file: error code %lu",
(int) GetLastError()); GetLastError());
/* /*
* Reserve the memory region used by our main shared memory segment before * Reserve the memory region used by our main shared memory segment before
...@@ -3794,8 +3794,8 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3794,8 +3794,8 @@ internal_forkexec(int argc, char *argv[], Port *port)
*/ */
if (!TerminateProcess(pi.hProcess, 255)) if (!TerminateProcess(pi.hProcess, 255))
ereport(LOG, ereport(LOG,
(errmsg_internal("could not terminate process that failed to reserve memory: error code %d", (errmsg_internal("could not terminate process that failed to reserve memory: error code %lu",
(int) GetLastError()))); GetLastError())));
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
return -1; /* logging done made by return -1; /* logging done made by
...@@ -3812,8 +3812,8 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3812,8 +3812,8 @@ internal_forkexec(int argc, char *argv[], Port *port)
if (!TerminateProcess(pi.hProcess, 255)) if (!TerminateProcess(pi.hProcess, 255))
{ {
ereport(LOG, ereport(LOG,
(errmsg_internal("could not terminate unstartable process: error code %d", (errmsg_internal("could not terminate unstartable process: error code %lu",
(int) GetLastError()))); GetLastError())));
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
return -1; return -1;
...@@ -3821,8 +3821,8 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3821,8 +3821,8 @@ internal_forkexec(int argc, char *argv[], Port *port)
CloseHandle(pi.hProcess); CloseHandle(pi.hProcess);
CloseHandle(pi.hThread); CloseHandle(pi.hThread);
ereport(LOG, ereport(LOG,
(errmsg_internal("could not resume thread of unstarted process: error code %d", (errmsg_internal("could not resume thread of unstarted process: error code %lu",
(int) GetLastError()))); GetLastError())));
return -1; return -1;
} }
...@@ -3850,8 +3850,8 @@ internal_forkexec(int argc, char *argv[], Port *port) ...@@ -3850,8 +3850,8 @@ internal_forkexec(int argc, char *argv[], Port *port)
INFINITE, INFINITE,
WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD)) WT_EXECUTEONLYONCE | WT_EXECUTEINWAITTHREAD))
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not register process for wait: error code %d", (errmsg_internal("could not register process for wait: error code %lu",
(int) GetLastError()))); GetLastError())));
/* Don't close pi.hProcess here - the wait thread needs access to it */ /* Don't close pi.hProcess here - the wait thread needs access to it */
...@@ -4710,8 +4710,8 @@ write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE childProcess) ...@@ -4710,8 +4710,8 @@ write_duplicated_handle(HANDLE *dest, HANDLE src, HANDLE childProcess)
DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS)) DUPLICATE_CLOSE_SOURCE | DUPLICATE_SAME_ACCESS))
{ {
ereport(LOG, ereport(LOG,
(errmsg_internal("could not duplicate handle to be written to backend parameter file: error code %d", (errmsg_internal("could not duplicate handle to be written to backend parameter file: error code %lu",
(int) GetLastError()))); GetLastError())));
return false; return false;
} }
...@@ -4830,8 +4830,8 @@ read_backend_variables(char *id, Port *port) ...@@ -4830,8 +4830,8 @@ read_backend_variables(char *id, Port *port)
paramp = MapViewOfFile(paramHandle, FILE_MAP_READ, 0, 0, 0); paramp = MapViewOfFile(paramHandle, FILE_MAP_READ, 0, 0, 0);
if (!paramp) if (!paramp)
{ {
write_stderr("could not map view of backend variables: error code %d\n", write_stderr("could not map view of backend variables: error code %lu\n",
(int) GetLastError()); GetLastError());
exit(1); exit(1);
} }
...@@ -4839,15 +4839,15 @@ read_backend_variables(char *id, Port *port) ...@@ -4839,15 +4839,15 @@ read_backend_variables(char *id, Port *port)
if (!UnmapViewOfFile(paramp)) if (!UnmapViewOfFile(paramp))
{ {
write_stderr("could not unmap view of backend variables: error code %d\n", write_stderr("could not unmap view of backend variables: error code %lu\n",
(int) GetLastError()); GetLastError());
exit(1); exit(1);
} }
if (!CloseHandle(paramHandle)) if (!CloseHandle(paramHandle))
{ {
write_stderr("could not close handle to backend parameter variables: error code %d\n", write_stderr("could not close handle to backend parameter variables: error code %lu\n",
(int) GetLastError()); GetLastError());
exit(1); exit(1);
} }
#endif #endif
...@@ -5063,7 +5063,7 @@ InitPostmasterDeathWatchHandle(void) ...@@ -5063,7 +5063,7 @@ InitPostmasterDeathWatchHandle(void)
TRUE, TRUE,
DUPLICATE_SAME_ACCESS) == 0) DUPLICATE_SAME_ACCESS) == 0)
ereport(FATAL, ereport(FATAL,
(errmsg_internal("could not duplicate postmaster handle: error code %d", (errmsg_internal("could not duplicate postmaster handle: error code %lu",
(int) GetLastError()))); GetLastError())));
#endif /* WIN32 */ #endif /* WIN32 */
} }
...@@ -559,7 +559,7 @@ strftime_win32(char *dst, size_t dstlen, const wchar_t *format, const struct tm ...@@ -559,7 +559,7 @@ strftime_win32(char *dst, size_t dstlen, const wchar_t *format, const struct tm
len = WideCharToMultiByte(CP_UTF8, 0, wbuf, len, dst, dstlen, NULL, NULL); len = WideCharToMultiByte(CP_UTF8, 0, wbuf, len, dst, dstlen, NULL, NULL);
if (len == 0) if (len == 0)
elog(ERROR, elog(ERROR,
"could not convert string to UTF-8:error %lu", GetLastError()); "could not convert string to UTF-8: error code %lu", GetLastError());
dst[len] = '\0'; dst[len] = '\0';
if (encoding != PG_UTF8) if (encoding != PG_UTF8)
......
...@@ -1355,7 +1355,7 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid) ...@@ -1355,7 +1355,7 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
(LPWSTR) a1p, a1len / 2); (LPWSTR) a1p, a1len / 2);
if (!r) if (!r)
ereport(ERROR, ereport(ERROR,
(errmsg("could not convert string to UTF-16: error %lu", (errmsg("could not convert string to UTF-16: error code %lu",
GetLastError()))); GetLastError())));
} }
((LPWSTR) a1p)[r] = 0; ((LPWSTR) a1p)[r] = 0;
...@@ -1368,7 +1368,7 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid) ...@@ -1368,7 +1368,7 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
(LPWSTR) a2p, a2len / 2); (LPWSTR) a2p, a2len / 2);
if (!r) if (!r)
ereport(ERROR, ereport(ERROR,
(errmsg("could not convert string to UTF-16: error %lu", (errmsg("could not convert string to UTF-16: error code %lu",
GetLastError()))); GetLastError())));
} }
((LPWSTR) a2p)[r] = 0; ((LPWSTR) a2p)[r] = 0;
......
...@@ -2444,7 +2444,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo) ...@@ -2444,7 +2444,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo)
/* Open the current token to use as a base for the restricted one */ /* Open the current token to use as a base for the restricted one */
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken))
{ {
fprintf(stderr, "Failed to open process token: %lu\n", GetLastError()); fprintf(stderr, "Failed to open process token: error code %lu\n", GetLastError());
return 0; return 0;
} }
...@@ -2457,7 +2457,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo) ...@@ -2457,7 +2457,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo)
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0,
0, &dropSids[1].Sid)) 0, &dropSids[1].Sid))
{ {
fprintf(stderr, "Failed to allocate SIDs: %lu\n", GetLastError()); fprintf(stderr, "Failed to allocate SIDs: error code %lu\n", GetLastError());
return 0; return 0;
} }
...@@ -2476,7 +2476,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo) ...@@ -2476,7 +2476,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo)
if (!b) if (!b)
{ {
fprintf(stderr, "Failed to create restricted token: %lu\n", GetLastError()); fprintf(stderr, "Failed to create restricted token: error code %lu\n", GetLastError());
return 0; return 0;
} }
...@@ -2497,7 +2497,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo) ...@@ -2497,7 +2497,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo)
processInfo)) processInfo))
{ {
fprintf(stderr, "CreateProcessAsUser failed: %lu\n", GetLastError()); fprintf(stderr, "CreateProcessAsUser failed: error code %lu\n", GetLastError());
return 0; return 0;
} }
...@@ -2819,7 +2819,7 @@ main(int argc, char *argv[]) ...@@ -2819,7 +2819,7 @@ main(int argc, char *argv[])
if (!CreateRestrictedProcess(cmdline, &pi)) if (!CreateRestrictedProcess(cmdline, &pi))
{ {
fprintf(stderr, "Failed to re-exec with restricted token: %lu.\n", GetLastError()); fprintf(stderr, "Failed to re-exec with restricted token: error code %lu\n", GetLastError());
} }
else else
{ {
...@@ -2834,7 +2834,7 @@ main(int argc, char *argv[]) ...@@ -2834,7 +2834,7 @@ main(int argc, char *argv[])
if (!GetExitCodeProcess(pi.hProcess, &x)) if (!GetExitCodeProcess(pi.hProcess, &x))
{ {
fprintf(stderr, "Failed to get exit code from subprocess: %lu\n", GetLastError()); fprintf(stderr, "Failed to get exit code from subprocess: error code %lu\n", GetLastError());
exit(1); exit(1);
} }
exit(x); exit(x);
......
...@@ -1320,7 +1320,7 @@ pgwin32_doRegister(void) ...@@ -1320,7 +1320,7 @@ pgwin32_doRegister(void)
NULL, NULL, "RPCSS\0", register_username, register_password)) == NULL) NULL, NULL, "RPCSS\0", register_username, register_password)) == NULL)
{ {
CloseServiceHandle(hSCM); CloseServiceHandle(hSCM);
write_stderr(_("%s: could not register service \"%s\": error code %d\n"), progname, register_servicename, (int) GetLastError()); write_stderr(_("%s: could not register service \"%s\": error code %lu\n"), progname, register_servicename, GetLastError());
exit(1); exit(1);
} }
CloseServiceHandle(hService); CloseServiceHandle(hService);
...@@ -1348,14 +1348,14 @@ pgwin32_doUnregister(void) ...@@ -1348,14 +1348,14 @@ pgwin32_doUnregister(void)
if ((hService = OpenService(hSCM, register_servicename, DELETE)) == NULL) if ((hService = OpenService(hSCM, register_servicename, DELETE)) == NULL)
{ {
CloseServiceHandle(hSCM); CloseServiceHandle(hSCM);
write_stderr(_("%s: could not open service \"%s\": error code %d\n"), progname, register_servicename, (int) GetLastError()); write_stderr(_("%s: could not open service \"%s\": error code %lu\n"), progname, register_servicename, GetLastError());
exit(1); exit(1);
} }
if (!DeleteService(hService)) if (!DeleteService(hService))
{ {
CloseServiceHandle(hService); CloseServiceHandle(hService);
CloseServiceHandle(hSCM); CloseServiceHandle(hSCM);
write_stderr(_("%s: could not unregister service \"%s\": error code %d\n"), progname, register_servicename, (int) GetLastError()); write_stderr(_("%s: could not unregister service \"%s\": error code %lu\n"), progname, register_servicename, GetLastError());
exit(1); exit(1);
} }
CloseServiceHandle(hService); CloseServiceHandle(hService);
...@@ -1498,7 +1498,7 @@ pgwin32_doRunAsService(void) ...@@ -1498,7 +1498,7 @@ pgwin32_doRunAsService(void)
if (StartServiceCtrlDispatcher(st) == 0) if (StartServiceCtrlDispatcher(st) == 0)
{ {
write_stderr(_("%s: could not start service \"%s\": error code %d\n"), progname, register_servicename, (int) GetLastError()); write_stderr(_("%s: could not start service \"%s\": error code %lu\n"), progname, register_servicename, GetLastError());
exit(1); exit(1);
} }
} }
...@@ -1579,7 +1579,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser ...@@ -1579,7 +1579,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
/* Open the current token to use as a base for the restricted one */ /* Open the current token to use as a base for the restricted one */
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken))
{ {
write_stderr(_("%s: could not open process token: %lu\n"), progname, GetLastError()); write_stderr(_("%s: could not open process token: error code %lu\n"), progname, GetLastError());
return 0; return 0;
} }
...@@ -1592,7 +1592,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser ...@@ -1592,7 +1592,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0,
0, &dropSids[1].Sid)) 0, &dropSids[1].Sid))
{ {
write_stderr(_("%s: could not allocate SIDs: %lu\n"), progname, GetLastError()); write_stderr(_("%s: could not allocate SIDs: error code %lu\n"), progname, GetLastError());
return 0; return 0;
} }
...@@ -1611,7 +1611,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser ...@@ -1611,7 +1611,7 @@ CreateRestrictedProcess(char *cmd, PROCESS_INFORMATION *processInfo, bool as_ser
if (!b) if (!b)
{ {
write_stderr(_("%s: could not create restricted token: %lu\n"), progname, GetLastError()); write_stderr(_("%s: could not create restricted token: error code %lu\n"), progname, GetLastError());
return 0; return 0;
} }
......
...@@ -646,13 +646,13 @@ AddUserToTokenDacl(HANDLE hToken) ...@@ -646,13 +646,13 @@ AddUserToTokenDacl(HANDLE hToken)
if (!GetTokenInformation(hToken, tic, (LPVOID) ptdd, dwSize, &dwSize)) if (!GetTokenInformation(hToken, tic, (LPVOID) ptdd, dwSize, &dwSize))
{ {
log_error("could not get token information: %lu", GetLastError()); log_error("could not get token information: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
} }
else else
{ {
log_error("could not get token information buffer size: %lu", GetLastError()); log_error("could not get token information buffer size: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
} }
...@@ -662,7 +662,7 @@ AddUserToTokenDacl(HANDLE hToken) ...@@ -662,7 +662,7 @@ AddUserToTokenDacl(HANDLE hToken)
(DWORD) sizeof(ACL_SIZE_INFORMATION), (DWORD) sizeof(ACL_SIZE_INFORMATION),
AclSizeInformation)) AclSizeInformation))
{ {
log_error("could not get ACL information: %lu", GetLastError()); log_error("could not get ACL information: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
...@@ -672,7 +672,7 @@ AddUserToTokenDacl(HANDLE hToken) ...@@ -672,7 +672,7 @@ AddUserToTokenDacl(HANDLE hToken)
*/ */
if (!GetTokenUser(hToken, &pTokenUser)) if (!GetTokenUser(hToken, &pTokenUser))
{ {
log_error("could not get user token: %lu", GetLastError()); log_error("could not get user token: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
...@@ -690,7 +690,7 @@ AddUserToTokenDacl(HANDLE hToken) ...@@ -690,7 +690,7 @@ AddUserToTokenDacl(HANDLE hToken)
if (!InitializeAcl(pacl, dwNewAclSize, ACL_REVISION)) if (!InitializeAcl(pacl, dwNewAclSize, ACL_REVISION))
{ {
log_error("could not initialize ACL: %lu", GetLastError()); log_error("could not initialize ACL: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
...@@ -699,13 +699,13 @@ AddUserToTokenDacl(HANDLE hToken) ...@@ -699,13 +699,13 @@ AddUserToTokenDacl(HANDLE hToken)
{ {
if (!GetAce(ptdd->DefaultDacl, i, (LPVOID *) &pace)) if (!GetAce(ptdd->DefaultDacl, i, (LPVOID *) &pace))
{ {
log_error("could not get ACE: %lu", GetLastError()); log_error("could not get ACE: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
if (!AddAce(pacl, ACL_REVISION, MAXDWORD, pace, ((PACE_HEADER) pace)->AceSize)) if (!AddAce(pacl, ACL_REVISION, MAXDWORD, pace, ((PACE_HEADER) pace)->AceSize))
{ {
log_error("could not add ACE: %lu", GetLastError()); log_error("could not add ACE: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
} }
...@@ -713,7 +713,7 @@ AddUserToTokenDacl(HANDLE hToken) ...@@ -713,7 +713,7 @@ AddUserToTokenDacl(HANDLE hToken)
/* Add the new ACE for the current user */ /* Add the new ACE for the current user */
if (!AddAccessAllowedAceEx(pacl, ACL_REVISION, OBJECT_INHERIT_ACE, GENERIC_ALL, pTokenUser->User.Sid)) if (!AddAccessAllowedAceEx(pacl, ACL_REVISION, OBJECT_INHERIT_ACE, GENERIC_ALL, pTokenUser->User.Sid))
{ {
log_error("could not add access allowed ACE: %lu", GetLastError()); log_error("could not add access allowed ACE: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
...@@ -722,7 +722,7 @@ AddUserToTokenDacl(HANDLE hToken) ...@@ -722,7 +722,7 @@ AddUserToTokenDacl(HANDLE hToken)
if (!SetTokenInformation(hToken, tic, (LPVOID) &tddNew, dwNewAclSize)) if (!SetTokenInformation(hToken, tic, (LPVOID) &tddNew, dwNewAclSize))
{ {
log_error("could not set token information: %lu", GetLastError()); log_error("could not set token information: error code %lu", GetLastError());
goto cleanup; goto cleanup;
} }
...@@ -774,7 +774,7 @@ GetTokenUser(HANDLE hToken, PTOKEN_USER *ppTokenUser) ...@@ -774,7 +774,7 @@ GetTokenUser(HANDLE hToken, PTOKEN_USER *ppTokenUser)
} }
else else
{ {
log_error("could not get token information buffer size: %lu", GetLastError()); log_error("could not get token information buffer size: error code %lu", GetLastError());
return FALSE; return FALSE;
} }
} }
...@@ -788,7 +788,7 @@ GetTokenUser(HANDLE hToken, PTOKEN_USER *ppTokenUser) ...@@ -788,7 +788,7 @@ GetTokenUser(HANDLE hToken, PTOKEN_USER *ppTokenUser)
LocalFree(*ppTokenUser); LocalFree(*ppTokenUser);
*ppTokenUser = NULL; *ppTokenUser = NULL;
log_error("could not get token information: %lu", GetLastError()); log_error("could not get token information: error code %lu", GetLastError());
return FALSE; return FALSE;
} }
......
...@@ -999,7 +999,7 @@ spawn_process(const char *cmdline) ...@@ -999,7 +999,7 @@ spawn_process(const char *cmdline)
/* Open the current token to use as base for the restricted one */ /* Open the current token to use as base for the restricted one */
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken)) if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ALL_ACCESS, &origToken))
{ {
fprintf(stderr, _("could not open process token: %lu\n"), fprintf(stderr, _("could not open process token: error code %lu\n"),
GetLastError()); GetLastError());
exit_nicely(2); exit_nicely(2);
} }
...@@ -1011,7 +1011,7 @@ spawn_process(const char *cmdline) ...@@ -1011,7 +1011,7 @@ spawn_process(const char *cmdline)
!AllocateAndInitializeSid(&NtAuthority, 2, !AllocateAndInitializeSid(&NtAuthority, 2,
SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, 0, &dropSids[1].Sid)) SECURITY_BUILTIN_DOMAIN_RID, DOMAIN_ALIAS_RID_POWER_USERS, 0, 0, 0, 0, 0, 0, &dropSids[1].Sid))
{ {
fprintf(stderr, _("could not allocate SIDs: %lu\n"), GetLastError()); fprintf(stderr, _("could not allocate SIDs: error code %lu\n"), GetLastError());
exit_nicely(2); exit_nicely(2);
} }
...@@ -1030,7 +1030,7 @@ spawn_process(const char *cmdline) ...@@ -1030,7 +1030,7 @@ spawn_process(const char *cmdline)
if (!b) if (!b)
{ {
fprintf(stderr, _("could not create restricted token: %lu\n"), fprintf(stderr, _("could not create restricted token: error code %lu\n"),
GetLastError()); GetLastError());
exit_nicely(2); exit_nicely(2);
} }
...@@ -1054,7 +1054,7 @@ spawn_process(const char *cmdline) ...@@ -1054,7 +1054,7 @@ spawn_process(const char *cmdline)
&si, &si,
&pi)) &pi))
{ {
fprintf(stderr, _("could not start process for \"%s\": %lu\n"), fprintf(stderr, _("could not start process for \"%s\": error code %lu\n"),
cmdline2, GetLastError()); cmdline2, GetLastError());
exit_nicely(2); exit_nicely(2);
} }
...@@ -1380,7 +1380,7 @@ wait_for_tests(PID_TYPE * pids, int *statuses, char **names, int num_tests) ...@@ -1380,7 +1380,7 @@ wait_for_tests(PID_TYPE * pids, int *statuses, char **names, int num_tests)
r = WaitForMultipleObjects(tests_left, active_pids, FALSE, INFINITE); r = WaitForMultipleObjects(tests_left, active_pids, FALSE, INFINITE);
if (r < WAIT_OBJECT_0 || r >= WAIT_OBJECT_0 + tests_left) if (r < WAIT_OBJECT_0 || r >= WAIT_OBJECT_0 + tests_left)
{ {
fprintf(stderr, _("failed to wait for subprocesses: %lu\n"), fprintf(stderr, _("failed to wait for subprocesses: error code %lu\n"),
GetLastError()); GetLastError());
exit_nicely(2); exit_nicely(2);
} }
...@@ -2295,7 +2295,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc ...@@ -2295,7 +2295,7 @@ regression_main(int argc, char *argv[], init_function ifunc, test_function tfunc
progname, strerror(errno)); progname, strerror(errno));
#else #else
if (TerminateProcess(postmaster_pid, 255) == 0) if (TerminateProcess(postmaster_pid, 255) == 0)
fprintf(stderr, _("\n%s: could not kill failed postmaster: %lu\n"), fprintf(stderr, _("\n%s: could not kill failed postmaster: error code %lu\n"),
progname, GetLastError()); progname, GetLastError());
#endif #endif
......
...@@ -1114,8 +1114,8 @@ identify_system_timezone(void) ...@@ -1114,8 +1114,8 @@ identify_system_timezone(void)
&rootKey) != ERROR_SUCCESS) &rootKey) != ERROR_SUCCESS)
{ {
ereport(LOG, ereport(LOG,
(errmsg("could not open registry key to identify system time zone: %d", (errmsg("could not open registry key to identify system time zone: error code %lu",
(int) GetLastError()), GetLastError()),
errdetail("The PostgreSQL time zone will be set to \"%s\".", errdetail("The PostgreSQL time zone will be set to \"%s\".",
"GMT"), "GMT"),
errhint("You can specify the correct timezone in postgresql.conf."))); errhint("You can specify the correct timezone in postgresql.conf.")));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment