MCPcopy Create free account
hub / github.com/apache/cloudberry / choose_dsm_implementation

Function choose_dsm_implementation

src/bin/initdb/initdb.c:898–932  ·  view source on GitHub ↗

* Determine which dynamic shared memory implementation should be used on * this platform. POSIX shared memory is preferable because the default * allocation limits are much higher than the limits for System V on most * systems that support both, but the fact that a platform has shm_open * doesn't guarantee that that call will succeed when attempted. So, we * attempt to reproduce what the po

Source from the content-addressed store, hash-verified

896 * memory instead.
897 */
898static const char *
899choose_dsm_implementation(void)
900{
901#ifdef HAVE_SHM_OPEN
902 int ntries = 10;
903
904 /* Initialize random(); this function is its only user in this program. */
905 srandom((unsigned int) (getpid() ^ time(NULL)));
906
907 while (ntries > 0)
908 {
909 uint32 handle;
910 char name[64];
911 int fd;
912
913 handle = random();
914 snprintf(name, 64, "/PostgreSQL.%u", handle);
915 if ((fd = shm_open(name, O_CREAT | O_RDWR | O_EXCL, 0600)) != -1)
916 {
917 close(fd);
918 shm_unlink(name);
919 return "posix";
920 }
921 if (errno != EEXIST)
922 break;
923 --ntries;
924 }
925#endif
926
927#ifdef WIN32
928 return "windows";
929#else
930 return "sysv";
931#endif
932}
933
934/*
935 * Determine platform-specific config settings

Callers 1

test_config_settingsFunction · 0.85

Calls 2

srandomFunction · 0.85
randomFunction · 0.85

Tested by 1

test_config_settingsFunction · 0.68