bufsize = GetFullPathName(DataDir, 0, NULL, NULL); if (bufsize == 0)
elog(FATAL, "could not get size for full pathname of datadir %s: error code %lu",
DataDir, GetLastError());
retptr = malloc(bufsize + 18); /* 18 for Global\PostgreSQL: */ if (retptr == NULL)
elog(FATAL, "could not allocate memory for shared memory name");
strcpy(retptr, "Global\\PostgreSQL:");
r = GetFullPathName(DataDir, bufsize, retptr + 18, NULL); if (r == 0 || r > bufsize)
elog(FATAL, "could not generate full pathname for datadir %s: error code %lu",
DataDir, GetLastError());
/* *XXX:IntentionallyoverwritingtheGlobal\parthere.Thiswasnotthe *originalapproach,butputtingitintheactualGlobal\namespace *causespermissionerrorsinalotofcases,soweleaveitinthe *defaultnamespacefornow.
*/ for (cp = retptr; *cp; cp++) if (*cp == '\\')
*cp = '/';
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken))
{
ereport(elevel,
(errmsg("could not enable user right \"%s\": error code %lu",
/* *translator:ThisisatermfromWindowsandshouldbetranslatedto *matchtheWindowslocalization.
*/
_("Lock pages in memory"),
GetLastError()),
errdetail("Failed system call was %s.", "OpenProcessToken"))); returnFALSE;
}
if (!LookupPrivilegeValue(NULL, SE_LOCK_MEMORY_NAME, &luid))
{
ereport(elevel,
(errmsg("could not enable user right \"%s\": error code %lu", _("Lock pages in memory"), GetLastError()),
errdetail("Failed system call was %s.", "LookupPrivilegeValue")));
CloseHandle(hToken); returnFALSE;
}
tp.PrivilegeCount = 1;
tp.Privileges[0].Luid = luid;
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, NULL, NULL))
{
ereport(elevel,
(errmsg("could not enable user right \"%s\": error code %lu", _("Lock pages in memory"), GetLastError()),
errdetail("Failed system call was %s.", "AdjustTokenPrivileges")));
CloseHandle(hToken); returnFALSE;
}
if (GetLastError() != ERROR_SUCCESS)
{ if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
ereport(elevel,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("could not enable user right \"%s\"", _("Lock pages in memory")),
errhint("Assign user right \"%s\" to the Windows user account which runs PostgreSQL.",
_("Lock pages in memory")))); else
ereport(elevel,
(errmsg("could not enable user right \"%s\": error code %lu", _("Lock pages in memory"), GetLastError()),
errdetail("Failed system call was %s.", "AdjustTokenPrivileges")));
CloseHandle(hToken); returnFALSE;
}
/* *Ifthesegmentalreadyexisted,CreateFileMapping()willreturna *handletotheexistingoneandsetERROR_ALREADY_EXISTS.
*/ if (GetLastError() == ERROR_ALREADY_EXISTS)
{
CloseHandle(hmap); /* Close the handle, since we got a valid one
* to the previous segment. */
hmap = NULL;
Sleep(1000); continue;
} break;
}
/* *IfthelastcallintheloopstillreturnedERROR_ALREADY_EXISTS,this *sharedmemorysegmentexistsandweassumeitbelongstosomebodyelse.
*/ if (!hmap)
ereport(FATAL,
(errmsg("pre-existing shared memory block is still in use"),
errhint("Check if there are any old server processes still running, and terminate them.")));
free(szShareMem);
/* *Makethehandleinheritable
*/ if (!DuplicateHandle(GetCurrentProcess(), hmap, GetCurrentProcess(), &hmap2, 0, TRUE, DUPLICATE_SAME_ACCESS))
ereport(FATAL,
(errmsg("could not create shared memory segment: error code %lu", GetLastError()),
errdetail("Failed system call was DuplicateHandle.")));
/* *Closetheold,non-inheritablehandle.Ifthisfailswedon'treally *care.
*/ if (!CloseHandle(hmap))
elog(LOG, "could not close handle to shared memory: error code %lu", GetLastError());
desiredAccess = FILE_MAP_WRITE | FILE_MAP_READ;
#ifdef FILE_MAP_LARGE_PAGES /* Set large pages if wanted. */ if ((flProtect & SEC_LARGE_PAGES) != 0)
desiredAccess |= FILE_MAP_LARGE_PAGES; #endif
/* *Getapointertothenewsharedmemorysegment.Mapthewholesegment *atonce,andletthesystemdecideontheinitialaddress.
*/
memAddress = MapViewOfFileEx(hmap2, desiredAccess, 0, 0, 0, NULL); if (!memAddress)
ereport(FATAL,
(errmsg("could not create shared memory segment: error code %lu", GetLastError()),
errdetail("Failed system call was MapViewOfFileEx.")));
/* Unmap the view, if it's mapped */ if (UsedShmemSegAddr != NULL)
{ if (!UnmapViewOfFile(UsedShmemSegAddr))
elog(LOG, "could not unmap view of shared memory: error code %lu",
GetLastError());
UsedShmemSegAddr = NULL;
}
/* And close the shmem handle, if we have one */ if (UsedShmemSegID != INVALID_HANDLE_VALUE)
{ if (!CloseHandle(UsedShmemSegID))
elog(LOG, "could not close handle to shared memory: error code %lu",
GetLastError());
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.