Index: src/backend/bootstrap/bootstrap.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/bootstrap/bootstrap.c,v retrieving revision 1.175 diff -c -r1.175 bootstrap.c *** src/backend/bootstrap/bootstrap.c 7 Jan 2004 18:56:25 -0000 1.175 --- src/backend/bootstrap/bootstrap.c 5 Feb 2004 12:36:15 -0000 *************** *** 428,434 **** #ifdef EXEC_BACKEND if (IsUnderPostmaster) ! AttachSharedMemoryAndSemaphores(); #endif XLOGPathInit(); --- 428,434 ---- #ifdef EXEC_BACKEND if (IsUnderPostmaster) ! CreateSharedMemoryAndSemaphores(false, MaxBackends, 0); #endif XLOGPathInit(); Index: src/backend/commands/user.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/commands/user.c,v retrieving revision 1.136 diff -c -r1.136 user.c *** src/backend/commands/user.c 2 Feb 2004 17:21:07 -0000 1.136 --- src/backend/commands/user.c 5 Feb 2004 12:36:16 -0000 *************** *** 139,149 **** bufsize = strlen(filename) + 12; tempname = (char *) palloc(bufsize); snprintf(tempname, bufsize, "%s.%d", filename, MyProcPid); ! #if defined(WIN32) || defined(CYGWIN) filename = repalloc(filename, strlen(filename) + 1 + strlen(".new")); strcat(filename, ".new"); #endif ! oumask = umask((mode_t) 077); fp = AllocateFile(tempname, "w"); umask(oumask); --- 139,149 ---- bufsize = strlen(filename) + 12; tempname = (char *) palloc(bufsize); snprintf(tempname, bufsize, "%s.%d", filename, MyProcPid); ! #if defined(WIN32) || defined(__CYGWIN__) filename = repalloc(filename, strlen(filename) + 1 + strlen(".new")); strcat(filename, ".new"); #endif ! oumask = umask((mode_t) 077); fp = AllocateFile(tempname, "w"); umask(oumask); *************** *** 290,296 **** bufsize = strlen(filename) + 12; tempname = (char *) palloc(bufsize); snprintf(tempname, bufsize, "%s.%d", filename, MyProcPid); ! #if defined(WIN32) || defined(CYGWIN) filename = repalloc(filename, strlen(filename) + 1 + strlen(".new")); strcat(filename, ".new"); #endif --- 290,296 ---- bufsize = strlen(filename) + 12; tempname = (char *) palloc(bufsize); snprintf(tempname, bufsize, "%s.%d", filename, MyProcPid); ! #if defined(WIN32) || defined(__CYGWIN__) filename = repalloc(filename, strlen(filename) + 1 + strlen(".new")); strcat(filename, ".new"); #endif *************** *** 465,471 **** user_file_update_needed = false; write_user_file(urel); heap_close(urel, NoLock); ! #if defined(WIN32) || defined(CYGWIN) { /* Rename active file while not holding an exclusive lock */ char *filename = user_getfilename(), *filename_new; --- 465,471 ---- user_file_update_needed = false; write_user_file(urel); heap_close(urel, NoLock); ! #if defined(WIN32) || defined(__CYGWIN__) { /* Rename active file while not holding an exclusive lock */ char *filename = user_getfilename(), *filename_new; *************** *** 484,490 **** group_file_update_needed = false; write_group_file(grel); heap_close(grel, NoLock); ! #if defined(WIN32) || defined(CYGWIN) { /* Rename active file while not holding an exclusive lock */ char *filename = group_getfilename(), *filename_new; --- 484,490 ---- group_file_update_needed = false; write_group_file(grel); heap_close(grel, NoLock); ! #if defined(WIN32) || defined(__CYGWIN__) { /* Rename active file while not holding an exclusive lock */ char *filename = group_getfilename(), *filename_new; Index: src/backend/port/sysv_shmem.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/port/sysv_shmem.c,v retrieving revision 1.30 diff -c -r1.30 sysv_shmem.c *** src/backend/port/sysv_shmem.c 2 Feb 2004 00:11:31 -0000 1.30 --- src/backend/port/sysv_shmem.c 5 Feb 2004 12:36:17 -0000 *************** *** 255,261 **** { void* origUsedShmemSegAddr = UsedShmemSegAddr; ! #ifdef CYGWIN /* cygipc (currently) appears to not detach on exec. */ PGSharedMemoryDetach(); UsedShmemSegAddr = origUsedShmemSegAddr; --- 255,261 ---- { void* origUsedShmemSegAddr = UsedShmemSegAddr; ! #ifdef __CYGWIN__ /* cygipc (currently) appears to not detach on exec. */ PGSharedMemoryDetach(); UsedShmemSegAddr = origUsedShmemSegAddr; *************** *** 374,380 **** if (UsedShmemSegAddr != NULL) { if ((shmdt(UsedShmemSegAddr) < 0) ! #if (defined(EXEC_BACKEND) && defined(CYGWIN)) /* Work-around for cygipc exec bug */ && shmdt(NULL) < 0 #endif --- 374,380 ---- if (UsedShmemSegAddr != NULL) { if ((shmdt(UsedShmemSegAddr) < 0) ! #if (defined(EXEC_BACKEND) && defined(__CYGWIN__)) /* Work-around for cygipc exec bug */ && shmdt(NULL) < 0 #endif Index: src/backend/postmaster/postmaster.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.364 diff -c -r1.364 postmaster.c *** src/backend/postmaster/postmaster.c 28 Jan 2004 21:02:40 -0000 1.364 --- src/backend/postmaster/postmaster.c 5 Feb 2004 12:36:19 -0000 *************** *** 2721,2727 **** load_group(); /* Attach process to shared segments */ ! AttachSharedMemoryAndSemaphores(); /* Run backend */ proc_exit(BackendRun(&port)); --- 2721,2727 ---- load_group(); /* Attach process to shared segments */ ! CreateSharedMemoryAndSemaphores(false, MaxBackends, 0); /* Run backend */ proc_exit(BackendRun(&port)); Index: src/backend/storage/ipc/ipci.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/storage/ipc/ipci.c,v retrieving revision 1.63 diff -c -r1.63 ipci.c *** src/backend/storage/ipc/ipci.c 26 Jan 2004 22:59:53 -0000 1.63 --- src/backend/storage/ipc/ipci.c 5 Feb 2004 12:36:19 -0000 *************** *** 36,43 **** * Creates and initializes shared memory and semaphores. * * This is called by the postmaster or by a standalone backend. ! * It is NEVER called by a backend forked from the postmaster; ! * for such a backend, the shared memory is already ready-to-go. * * If "makePrivate" is true then we only need private memory, not shared * memory. This is true for a standalone backend, false for a postmaster. --- 36,45 ---- * Creates and initializes shared memory and semaphores. * * This is called by the postmaster or by a standalone backend. ! * It is also called by a backend forked from the postmaster under ! * the EXEC_BACKEND case ! * ! * In the non EXEC_BACKEND case, backends already have shared memory ready-to-go. * * If "makePrivate" is true then we only need private memory, not shared * memory. This is true for a standalone backend, false for a postmaster. *************** *** 47,102 **** int maxBackends, int port) { ! int size; ! int numSemas; ! PGShmemHeader *seghdr; ! ! /* ! * Size of the Postgres shared-memory block is estimated via ! * moderately-accurate estimates for the big hogs, plus 100K for the ! * stuff that's too small to bother with estimating. ! */ ! size = BufferShmemSize(); ! size += LockShmemSize(maxBackends); ! size += XLOGShmemSize(); ! size += CLOGShmemSize(); ! size += LWLockShmemSize(); ! size += SInvalShmemSize(maxBackends); ! size += FreeSpaceShmemSize(); #ifdef EXEC_BACKEND ! size += ShmemBackendArraySize(); #endif #ifdef STABLE_MEMORY_STORAGE ! size += MMShmemSize(); #endif ! size += 100000; ! /* might as well round it off to a multiple of a typical page size */ ! size += 8192 - (size % 8192); ! ! elog(DEBUG3, "invoking IpcMemoryCreate(size=%d)", size); ! ! /* ! * Create the shmem segment ! */ ! seghdr = PGSharedMemoryCreate(size, makePrivate, port); - /* - * Create semaphores - */ - numSemas = ProcGlobalSemas(maxBackends); - numSemas += SpinlockSemas(); - PGReserveSemaphores(numSemas, port); /* * Set up shared memory allocation mechanism */ ! InitShmemAllocation(seghdr, true); /* * Now initialize LWLocks, which do shared memory allocation and are * needed for InitShmemIndex. */ ! CreateLWLocks(); /* * Set up shmem.c index hashtable --- 49,119 ---- int maxBackends, int port) { ! PGShmemHeader *seghdr = NULL; ! if (!IsUnderPostmaster) ! { ! int size; ! int numSemas; ! ! /* ! * Size of the Postgres shared-memory block is estimated via ! * moderately-accurate estimates for the big hogs, plus 100K for the ! * stuff that's too small to bother with estimating. ! */ ! size = BufferShmemSize(); ! size += LockShmemSize(maxBackends); ! size += XLOGShmemSize(); ! size += CLOGShmemSize(); ! size += LWLockShmemSize(); ! size += SInvalShmemSize(maxBackends); ! size += FreeSpaceShmemSize(); #ifdef EXEC_BACKEND ! size += ShmemBackendArraySize(); #endif #ifdef STABLE_MEMORY_STORAGE ! size += MMShmemSize(); #endif ! size += 100000; ! /* might as well round it off to a multiple of a typical page size */ ! size += 8192 - (size % 8192); ! ! elog(DEBUG3, "invoking IpcMemoryCreate(size=%d)", size); ! ! /* ! * Create the shmem segment ! */ ! seghdr = PGSharedMemoryCreate(size, makePrivate, port); ! ! /* ! * Create semaphores ! */ ! numSemas = ProcGlobalSemas(maxBackends); ! numSemas += SpinlockSemas(); ! PGReserveSemaphores(numSemas, port); ! } ! else ! { ! /* ! * Attach to the shmem segment. ! * (this should only ever be reached by EXEC_BACKEND code, ! * and only then with makePrivate == false) ! */ ! Assert(ExecBackend && !makePrivate); ! seghdr = PGSharedMemoryCreate(-1, makePrivate, 0); ! } /* * Set up shared memory allocation mechanism */ ! InitShmemAllocation(seghdr, !IsUnderPostmaster); /* * Now initialize LWLocks, which do shared memory allocation and are * needed for InitShmemIndex. */ ! if (!IsUnderPostmaster) ! CreateLWLocks(); /* * Set up shmem.c index hashtable *************** *** 140,180 **** /* * Alloc the win32 shared backend array */ ! ShmemBackendArrayAllocation(); #endif } - - - #ifdef EXEC_BACKEND - /* - * AttachSharedMemoryAndSemaphores - * Attaches to the existing shared resources. - */ - - /* FIXME: [fork/exec] This function is starting to look pretty much like - CreateSharedMemoryAndSemaphores. Refactor? */ - void - AttachSharedMemoryAndSemaphores(void) - { - PGShmemHeader *seghdr = PGSharedMemoryCreate(-1,false,-1); - - InitShmemAllocation(seghdr, false); - - InitShmemIndex(); - - XLOGShmemInit(); - CLOGShmemInit(); - InitBufferPool(); - - InitLocks(); - InitLockTable(MaxBackends); - - InitProcGlobal(MaxBackends); - - CreateSharedInvalidationState(MaxBackends); - - InitFreeSpaceMap(); - - PMSignalInit(); - } - #endif --- 157,163 ---- /* * Alloc the win32 shared backend array */ ! if (!IsUnderPostmaster) ! ShmemBackendArrayAllocation(); #endif } Index: src/backend/utils/adt/datetime.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/adt/datetime.c,v retrieving revision 1.124 diff -c -r1.124 datetime.c *** src/backend/utils/adt/datetime.c 19 Jan 2004 19:04:40 -0000 1.124 --- src/backend/utils/adt/datetime.c 5 Feb 2004 12:36:22 -0000 *************** *** 1611,1616 **** --- 1611,1620 ---- * and reassemble to get a representation of local time. */ tx = localtime(&mytime); + if (!tx) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range"))); day = date2j(tx->tm_year + 1900, tx->tm_mon + 1, tx->tm_mday) - UNIX_EPOCH_JDATE; locsec = tx->tm_sec + (tx->tm_min + (day * 24 + tx->tm_hour) * 60) * 60; *************** *** 1632,1637 **** --- 1636,1645 ---- mysec += delta1; mytime = (time_t) mysec; tx = localtime(&mytime); + if (!tx) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range"))); day = date2j(tx->tm_year + 1900, tx->tm_mon + 1, tx->tm_mday) - UNIX_EPOCH_JDATE; locsec = tx->tm_sec + (tx->tm_min + (day * 24 + tx->tm_hour) * 60) * 60; *************** *** 1653,1658 **** --- 1661,1670 ---- mysec += (delta2 - delta1); mytime = (time_t) mysec; tx = localtime(&mytime); + if (!tx) + ereport(ERROR, + (errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE), + errmsg("timestamp out of range"))); day = date2j(tx->tm_year + 1900, tx->tm_mon + 1, tx->tm_mday) - UNIX_EPOCH_JDATE; locsec = tx->tm_sec + (tx->tm_min + (day * 24 + tx->tm_hour) * 60) * 60; Index: src/backend/utils/cache/relcache.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/utils/cache/relcache.c,v retrieving revision 1.196 diff -c -r1.196 relcache.c *** src/backend/utils/cache/relcache.c 2 Feb 2004 00:17:21 -0000 1.196 --- src/backend/utils/cache/relcache.c 5 Feb 2004 12:36:26 -0000 *************** *** 3359,3371 **** * OK, rename the temp file to its final name, deleting any * previously-existing init file. */ ! #if defined(WIN32) || defined(CYGWIN) rename(tempfilename, finalfilename); LWLockRelease(RelCacheInitLock); #else { char finalfilename_new[MAXPGPATH]; ! snprintf(finalfilename_new, sizeof(finalfilename_new), "%s.new", finalfilename); rename(tempfilename, finalfilename_new); LWLockRelease(RelCacheInitLock); --- 3359,3371 ---- * OK, rename the temp file to its final name, deleting any * previously-existing init file. */ ! #if defined(WIN32) || defined(__CYGWIN__) rename(tempfilename, finalfilename); LWLockRelease(RelCacheInitLock); #else { char finalfilename_new[MAXPGPATH]; ! snprintf(finalfilename_new, sizeof(finalfilename_new), "%s.new", finalfilename); rename(tempfilename, finalfilename_new); LWLockRelease(RelCacheInitLock); Index: src/include/port.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/port.h,v retrieving revision 1.18 diff -c -r1.18 port.h *** src/include/port.h 2 Feb 2004 22:20:33 -0000 1.18 --- src/include/port.h 5 Feb 2004 12:36:27 -0000 *************** *** 30,36 **** extern off_t ftello(FILE *stream); #endif ! #if defined(WIN32) || defined(CYGWIN) /* * Win32 doesn't have reliable rename/unlink during concurrent access */ --- 30,36 ---- extern off_t ftello(FILE *stream); #endif ! #if defined(WIN32) || defined(__CYGWIN__) /* * Win32 doesn't have reliable rename/unlink during concurrent access */ Index: src/include/storage/ipc.h =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/include/storage/ipc.h,v retrieving revision 1.64 diff -c -r1.64 ipc.h *** src/include/storage/ipc.h 20 Dec 2003 17:31:21 -0000 1.64 --- src/include/storage/ipc.h 5 Feb 2004 12:36:27 -0000 *************** *** 30,39 **** /* ipci.c */ extern void CreateSharedMemoryAndSemaphores(bool makePrivate, ! int maxBackends, ! int port); ! #ifdef EXEC_BACKEND ! extern void AttachSharedMemoryAndSemaphores(void); ! #endif ! #endif /* IPC_H */ --- 30,35 ---- /* ipci.c */ extern void CreateSharedMemoryAndSemaphores(bool makePrivate, ! int maxBackends, ! int port); #endif /* IPC_H */ Index: src/port/dirmod.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/port/dirmod.c,v retrieving revision 1.10 diff -c -r1.10 dirmod.c *** src/port/dirmod.c 2 Feb 2004 22:20:33 -0000 1.10 --- src/port/dirmod.c 5 Feb 2004 12:36:28 -0000 *************** *** 17,29 **** #ifndef TEST_VERSION ! #if defined(WIN32) || defined(CYGWIN) #ifndef FRONTEND #include "postgres.h" #else #include "postgres_fe.h" #endif #undef rename #undef unlink --- 17,34 ---- #ifndef TEST_VERSION ! #if defined(WIN32) || defined(__CYGWIN__) ! ! #ifdef __CYGWIN__ ! #include /* timeval definition for PG_USLEEP */ ! #endif #ifndef FRONTEND #include "postgres.h" #else #include "postgres_fe.h" #endif + #include "miscadmin.h" #undef rename #undef unlink *************** *** 36,54 **** #ifdef WIN32 while (!MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)) #endif ! #ifdef CYGWIN while (rename(from, to) < 0) #endif { #ifdef WIN32 if (GetLastError() != ERROR_ACCESS_DENIED) #endif ! #ifdef CYGWIN if (errno != EACCES) #endif /* set errno? */ return -1; ! Sleep(100); /* ms */ if (loops == 30) #ifndef FRONTEND elog(LOG, "could not rename \"%s\" to \"%s\", continuing to try", --- 41,59 ---- #ifdef WIN32 while (!MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING)) #endif ! #ifdef __CYGWIN__ while (rename(from, to) < 0) #endif { #ifdef WIN32 if (GetLastError() != ERROR_ACCESS_DENIED) #endif ! #ifdef __CYGWIN__ if (errno != EACCES) #endif /* set errno? */ return -1; ! PG_USLEEP(100000); /* us */ if (loops == 30) #ifndef FRONTEND elog(LOG, "could not rename \"%s\" to \"%s\", continuing to try", *************** *** 80,86 **** if (errno != EACCES) /* set errno? */ return -1; ! Sleep(100); /* ms */ if (loops == 30) #ifndef FRONTEND elog(LOG, "could not unlink \"%s\", continuing to try", --- 85,91 ---- if (errno != EACCES) /* set errno? */ return -1; ! PG_USLEEP(100000); /* us */ if (loops == 30) #ifndef FRONTEND elog(LOG, "could not unlink \"%s\", continuing to try", Index: src/utils/dllinit.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/utils/dllinit.c,v retrieving revision 1.15 diff -c -r1.15 dllinit.c *** src/utils/dllinit.c 2 Feb 2004 17:21:08 -0000 1.15 --- src/utils/dllinit.c 5 Feb 2004 12:36:29 -0000 *************** *** 1,4 **** ! #ifdef CYGWIN #include #endif #if CYGWIN_VERSION_DLL_MAJOR < 1001 --- 1,4 ---- ! #ifdef __CYGWIN__ #include #endif #if CYGWIN_VERSION_DLL_MAJOR < 1001 *************** *** 88,94 **** --- 88,96 ---- __hDllInstance_base = hInst; #endif /* __CYGWIN__ */ + #ifdef __CYGWIN__ _impure_ptr = __imp_reent_data; + #endif switch (reason) {