Index: src/backend/main/main.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/main/main.c,v retrieving revision 1.70 diff -c -r1.70 main.c *** src/backend/main/main.c 6 Jan 2004 23:15:22 -0000 1.70 --- src/backend/main/main.c 8 Jan 2004 07:23:44 -0000 *************** *** 87,92 **** --- 87,105 ---- #endif #endif /* NOFIXADE || NOPRINTADE */ + #if defined(WIN32) + { + WSADATA wsaData; + int err = WSAStartup(MAKEWORD(2,2), &wsaData); + if (err != 0) + { + fprintf(stderr, "%s: WSAStartup failed: %d\n", + argv[0], err); + exit(1); + } + } + #endif + #ifdef __BEOS__ /* BeOS-specific actions on startup */ beos_startup(argc, argv); Index: src/backend/postmaster/pgstat.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/pgstat.c,v retrieving revision 1.51 diff -c -r1.51 pgstat.c *** src/backend/postmaster/pgstat.c 6 Jan 2004 23:15:22 -0000 1.51 --- src/backend/postmaster/pgstat.c 8 Jan 2004 07:23:46 -0000 *************** *** 50,55 **** --- 50,58 ---- #include "utils/ps_status.h" #include "utils/syscache.h" + #ifdef WIN32 + extern pid_t win32_forkexec(const char* path, char *argv[]); + #endif /* ---------- * GUC parameters *************** *** 389,398 **** Assert(ac <= lengthof(av)); /* Fire off execv in child */ if ((pid = fork()) == 0 && (execv(pg_pathname,av) == -1)) /* FIXME: [fork/exec] suggestions for what to do here? Can't call elog... */ abort(); ! return pid; /* Parent returns pid */ } --- 392,404 ---- Assert(ac <= lengthof(av)); /* Fire off execv in child */ + #ifdef WIN32 + pid = win32_forkexec(pg_pathname,av); + #else if ((pid = fork()) == 0 && (execv(pg_pathname,av) == -1)) /* FIXME: [fork/exec] suggestions for what to do here? Can't call elog... */ abort(); ! #endif return pid; /* Parent returns pid */ } Index: src/backend/postmaster/postmaster.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/postmaster/postmaster.c,v retrieving revision 1.355 diff -c -r1.355 postmaster.c *** src/backend/postmaster/postmaster.c 7 Jan 2004 18:56:27 -0000 1.355 --- src/backend/postmaster/postmaster.c 8 Jan 2004 07:23:49 -0000 *************** *** 297,302 **** --- 297,306 ---- __attribute__((format(printf, 1, 2))); #ifdef EXEC_BACKEND + #ifdef WIN32 + pid_t win32_forkexec(const char* path, char *argv[]); + #endif + static pid_t Backend_forkexec(Port *port); static unsigned long tmpBackendFileNum = 0; *************** *** 923,929 **** --- 927,938 ---- getitimer(ITIMER_PROF, &prof_itimer); #endif + #ifdef WIN32 + /* FIXME: [fork/exec] to be implemented? */ + abort(); + #else pid = fork(); + #endif if (pid == (pid_t) -1) { postmaster_error("could not fork background process: %s", *************** *** 2696,2701 **** --- 2705,2713 ---- av[ac++] = NULL; Assert(ac <= lengthof(av)); + #ifdef WIN32 + pid = win32_forkexec(pg_pathname,av); /* logs on error */ + #else /* Fire off execv in child */ if ((pid = fork()) == 0 && (execv(pg_pathname,av) == -1)) /* *************** *** 2703,2709 **** * Probably OK to issue error (unlike pgstat case) */ abort(); ! return pid; /* Parent returns pid */ } --- 2715,2721 ---- * Probably OK to issue error (unlike pgstat case) */ abort(); ! #endif return pid; /* Parent returns pid */ } *************** *** 3043,3054 **** --- 3055,3070 ---- #ifdef EXEC_BACKEND /* EXEC_BACKEND case; fork/exec here */ + #ifdef WIN32 + pid = win32_forkexec(pg_pathname,av); /* logs on error */ + #else if ((pid = fork()) == 0 && (execv(pg_pathname,av) == -1)) { /* in child */ elog(ERROR,"unable to execv in SSDataBase: %m"); exit(0); } + #endif #else BootstrapMain(ac, av); ExitPostmaster(0); *************** *** 3336,3341 **** --- 3352,3406 ---- ereport(WARNING, (errcode_for_file_access(), errmsg("could not remove file \"%s\": %m", filename))); + } + + #endif + + #ifdef WIN32 + + pid_t win32_forkexec(const char* path, char *argv[]) + { + STARTUPINFO si; + PROCESS_INFORMATION pi; + char *p; + int i; + char cmdLine[MAXPGPATH]; + + /* Format the cmd line */ + snprintf(cmdLine,sizeof(cmdLine),"%s",path); + i = 0; + while (argv[++i] != NULL) + { + /* FIXME: [fork/exec] some strlen checks might be prudent here */ + strcat(cmdLine," "); + strcat(cmdLine,argv[i]); + } + + /* + * The following snippet can disappear when we consistently + * use forward slashes. + */ + p = cmdLine; + while (*(p++) != '\0') + if (*p == '/') *p = '\\'; + + memset(&pi,0,sizeof(pi)); + memset(&si,0,sizeof(si)); + si.cb = sizeof(si); + if (!CreateProcess(NULL,cmdLine,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi)) + { + elog(ERROR,"CreateProcess call failed (%d): %m",GetLastError()); + return -1; + } + + /* + FIXME: [fork/exec] we might need to keep the following handle/s, + depending on how we implement signalling. + */ + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + + return pi.dwProcessId; } #endif Index: src/backend/storage/freespace/freespace.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/storage/freespace/freespace.c,v retrieving revision 1.28 diff -c -r1.28 freespace.c *** src/backend/storage/freespace/freespace.c 20 Dec 2003 17:31:21 -0000 1.28 --- src/backend/storage/freespace/freespace.c 8 Jan 2004 07:23:51 -0000 *************** *** 274,280 **** (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("insufficient shared memory for free space map"))); if (!found) ! MemSet(FreeSpaceMap, 0, sizeof(FSMHeader)); /* Create hashtable for FSMRelations */ info.keysize = sizeof(RelFileNode); --- 274,280 ---- (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("insufficient shared memory for free space map"))); if (!found) ! MemSet(FreeSpaceMap, 0, sizeof(FSMHeader)); /* Create hashtable for FSMRelations */ info.keysize = sizeof(RelFileNode); Index: src/backend/storage/ipc/pmsignal.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/storage/ipc/pmsignal.c,v retrieving revision 1.7 diff -c -r1.7 pmsignal.c *** src/backend/storage/ipc/pmsignal.c 20 Dec 2003 17:31:21 -0000 1.7 --- src/backend/storage/ipc/pmsignal.c 8 Jan 2004 07:23:51 -0000 *************** *** 49,55 **** ShmemInitStruct("PMSignalFlags",NUM_PMSIGNALS * sizeof(sig_atomic_t),&found); if (!found) ! MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t)); } /* --- 49,55 ---- ShmemInitStruct("PMSignalFlags",NUM_PMSIGNALS * sizeof(sig_atomic_t),&found); if (!found) ! MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t)); } /* Index: src/backend/storage/ipc/shmem.c =================================================================== RCS file: /projects/cvsroot/pgsql-server/src/backend/storage/ipc/shmem.c,v retrieving revision 1.77 diff -c -r1.77 shmem.c *** src/backend/storage/ipc/shmem.c 30 Dec 2003 00:03:03 -0000 1.77 --- src/backend/storage/ipc/shmem.c 8 Jan 2004 07:23:51 -0000 *************** *** 118,127 **** SpinLockInit(ShmemLock); SpinLockInit(ShmemIndexLock); ! /* ShmemIndex can't be set up yet (need LWLocks first) */ ShmemIndex = (HTAB *) NULL; ! /* * Initialize ShmemVariableCache for transaction manager. */ --- 118,127 ---- SpinLockInit(ShmemLock); SpinLockInit(ShmemIndexLock); ! /* ShmemIndex can't be set up yet (need LWLocks first) */ ShmemIndex = (HTAB *) NULL; ! /* * Initialize ShmemVariableCache for transaction manager. */ *************** *** 234,252 **** { MemSet(item.key, 0, SHMEM_INDEX_KEYSIZE); strncpy(item.key, "ShmemIndex", SHMEM_INDEX_KEYSIZE); ! result = (ShmemIndexEnt *) hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found); if (!result) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"))); ! Assert(ShmemBootstrap && !found); ! result->location = MAKE_OFFSET(ShmemIndex->hctl); result->size = SHMEM_INDEX_SIZE; ! ShmemBootstrap = false; } --- 234,252 ---- { MemSet(item.key, 0, SHMEM_INDEX_KEYSIZE); strncpy(item.key, "ShmemIndex", SHMEM_INDEX_KEYSIZE); ! result = (ShmemIndexEnt *) hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found); if (!result) ereport(FATAL, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of shared memory"))); ! Assert(ShmemBootstrap && !found); ! result->location = MAKE_OFFSET(ShmemIndex->hctl); result->size = SHMEM_INDEX_SIZE; ! ShmemBootstrap = false; }