Skip to content

Commit 4cdf51e

Browse files
committed
Drops in the CreateProcess calls for Win32 (essentially wrapping up the
fork/exec portion of the port), and fixes a handful of whitespace issues Claudio Natoli
1 parent ca7a1f0 commit 4cdf51e

File tree

6 files changed

+100
-16
lines changed

6 files changed

+100
-16
lines changed

src/backend/main/main.c

+14-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*
1515
* IDENTIFICATION
16-
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.70 2004/01/06 23:15:22 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/main/main.c,v 1.71 2004/01/11 03:49:31 momjian Exp $
1717
*
1818
*-------------------------------------------------------------------------
1919
*/
@@ -87,6 +87,19 @@ main(int argc, char *argv[])
8787
#endif
8888
#endif /* NOFIXADE || NOPRINTADE */
8989

90+
#if defined(WIN32)
91+
{
92+
WSADATA wsaData;
93+
int err = WSAStartup(MAKEWORD(2,2), &wsaData);
94+
if (err != 0)
95+
{
96+
fprintf(stderr, "%s: WSAStartup failed: %d\n",
97+
argv[0], err);
98+
exit(1);
99+
}
100+
}
101+
#endif
102+
90103
#ifdef __BEOS__
91104
/* BeOS-specific actions on startup */
92105
beos_startup(argc, argv);

src/backend/postmaster/pgstat.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* Copyright (c) 2001-2003, PostgreSQL Global Development Group
1515
*
16-
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.52 2004/01/09 04:58:09 momjian Exp $
16+
* $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.53 2004/01/11 03:49:31 momjian Exp $
1717
* ----------
1818
*/
1919
#include "postgres.h"
@@ -50,6 +50,9 @@
5050
#include "utils/ps_status.h"
5151
#include "utils/syscache.h"
5252

53+
#ifdef WIN32
54+
extern pid_t win32_forkexec(const char* path, char *argv[]);
55+
#endif
5356

5457
/* ----------
5558
* GUC parameters
@@ -402,10 +405,13 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
402405
Assert(ac <= lengthof(av));
403406

404407
/* Fire off execv in child */
408+
#ifdef WIN32
409+
pid = win32_forkexec(pg_pathname,av);
410+
#else
405411
if ((pid = fork()) == 0 && (execv(pg_pathname,av) == -1))
406412
/* FIXME: [fork/exec] suggestions for what to do here? Can't call elog... */
407413
abort();
408-
414+
#endif
409415
return pid; /* Parent returns pid */
410416
}
411417

src/backend/postmaster/postmaster.c

+67-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
*
3838
*
3939
* IDENTIFICATION
40-
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.357 2004/01/09 23:27:20 momjian Exp $
40+
* $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.358 2004/01/11 03:49:31 momjian Exp $
4141
*
4242
* NOTES
4343
*
@@ -297,6 +297,10 @@ postmaster_error(const char *fmt,...)
297297
__attribute__((format(printf, 1, 2)));
298298

299299
#ifdef EXEC_BACKEND
300+
#ifdef WIN32
301+
pid_t win32_forkexec(const char* path, char *argv[]);
302+
#endif
303+
300304
static pid_t Backend_forkexec(Port *port);
301305

302306
static unsigned long tmpBackendFileNum = 0;
@@ -923,7 +927,12 @@ pmdaemonize(int argc, char *argv[])
923927
getitimer(ITIMER_PROF, &prof_itimer);
924928
#endif
925929

930+
#ifdef WIN32
931+
/* FIXME: [fork/exec] to be implemented? */
932+
abort();
933+
#else
926934
pid = fork();
935+
#endif
927936
if (pid == (pid_t) -1)
928937
{
929938
postmaster_error("could not fork background process: %s",
@@ -2692,14 +2701,17 @@ Backend_forkexec(Port *port)
26922701
av[ac++] = NULL;
26932702
Assert(ac <= lengthof(av));
26942703

2704+
#ifdef WIN32
2705+
pid = win32_forkexec(pg_pathname,av); /* logs on error */
2706+
#else
26952707
/* Fire off execv in child */
26962708
if ((pid = fork()) == 0 && (execv(pg_pathname,av) == -1))
26972709
/*
26982710
* FIXME: [fork/exec] suggestions for what to do here?
26992711
* Probably OK to issue error (unlike pgstat case)
27002712
*/
27012713
abort();
2702-
2714+
#endif
27032715
return pid; /* Parent returns pid */
27042716
}
27052717

@@ -3039,12 +3051,16 @@ SSDataBase(int xlop)
30393051

30403052
#ifdef EXEC_BACKEND
30413053
/* EXEC_BACKEND case; fork/exec here */
3054+
#ifdef WIN32
3055+
pid = win32_forkexec(pg_pathname,av); /* logs on error */
3056+
#else
30423057
if ((pid = fork()) == 0 && (execv(pg_pathname,av) == -1))
30433058
{
30443059
/* in child */
30453060
elog(ERROR,"unable to execv in SSDataBase: %m");
30463061
exit(0);
30473062
}
3063+
#endif
30483064
#else
30493065
BootstrapMain(ac, av);
30503066
ExitPostmaster(0);
@@ -3335,3 +3351,52 @@ read_backend_variables(unsigned long id, Port *port)
33353351
}
33363352

33373353
#endif
3354+
3355+
#ifdef WIN32
3356+
3357+
pid_t win32_forkexec(const char* path, char *argv[])
3358+
{
3359+
STARTUPINFO si;
3360+
PROCESS_INFORMATION pi;
3361+
char *p;
3362+
int i;
3363+
char cmdLine[MAXPGPATH];
3364+
3365+
/* Format the cmd line */
3366+
snprintf(cmdLine,sizeof(cmdLine),"%s",path);
3367+
i = 0;
3368+
while (argv[++i] != NULL)
3369+
{
3370+
/* FIXME: [fork/exec] some strlen checks might be prudent here */
3371+
strcat(cmdLine," ");
3372+
strcat(cmdLine,argv[i]);
3373+
}
3374+
3375+
/*
3376+
* The following snippet can disappear when we consistently
3377+
* use forward slashes.
3378+
*/
3379+
p = cmdLine;
3380+
while (*(p++) != '\0')
3381+
if (*p == '/') *p = '\\';
3382+
3383+
memset(&pi,0,sizeof(pi));
3384+
memset(&si,0,sizeof(si));
3385+
si.cb = sizeof(si);
3386+
if (!CreateProcess(NULL,cmdLine,NULL,NULL,TRUE,0,NULL,NULL,&si,&pi))
3387+
{
3388+
elog(ERROR,"CreateProcess call failed (%d): %m",GetLastError());
3389+
return -1;
3390+
}
3391+
3392+
/*
3393+
FIXME: [fork/exec] we might need to keep the following handle/s,
3394+
depending on how we implement signalling.
3395+
*/
3396+
CloseHandle(pi.hProcess);
3397+
CloseHandle(pi.hThread);
3398+
3399+
return pi.dwProcessId;
3400+
}
3401+
3402+
#endif

src/backend/storage/freespace/freespace.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.28 2003/12/20 17:31:21 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.29 2004/01/11 03:49:31 momjian Exp $
1212
*
1313
*
1414
* NOTES:
@@ -274,7 +274,7 @@ InitFreeSpaceMap(void)
274274
(errcode(ERRCODE_OUT_OF_MEMORY),
275275
errmsg("insufficient shared memory for free space map")));
276276
if (!found)
277-
MemSet(FreeSpaceMap, 0, sizeof(FSMHeader));
277+
MemSet(FreeSpaceMap, 0, sizeof(FSMHeader));
278278

279279
/* Create hashtable for FSMRelations */
280280
info.keysize = sizeof(RelFileNode);

src/backend/storage/ipc/pmsignal.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Portions Copyright (c) 1994, Regents of the University of California
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.7 2003/12/20 17:31:21 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.8 2004/01/11 03:49:31 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -49,7 +49,7 @@ PMSignalInit(void)
4949
ShmemInitStruct("PMSignalFlags",NUM_PMSIGNALS * sizeof(sig_atomic_t),&found);
5050

5151
if (!found)
52-
MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
52+
MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
5353
}
5454

5555
/*

src/backend/storage/ipc/shmem.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.77 2003/12/30 00:03:03 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.78 2004/01/11 03:49:31 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -118,10 +118,10 @@ InitShmemAllocation(void *seghdr, bool init)
118118

119119
SpinLockInit(ShmemLock);
120120
SpinLockInit(ShmemIndexLock);
121-
121+
122122
/* ShmemIndex can't be set up yet (need LWLocks first) */
123123
ShmemIndex = (HTAB *) NULL;
124-
124+
125125
/*
126126
* Initialize ShmemVariableCache for transaction manager.
127127
*/
@@ -234,19 +234,19 @@ InitShmemIndex(void)
234234
{
235235
MemSet(item.key, 0, SHMEM_INDEX_KEYSIZE);
236236
strncpy(item.key, "ShmemIndex", SHMEM_INDEX_KEYSIZE);
237-
237+
238238
result = (ShmemIndexEnt *)
239239
hash_search(ShmemIndex, (void *) &item, HASH_ENTER, &found);
240240
if (!result)
241241
ereport(FATAL,
242242
(errcode(ERRCODE_OUT_OF_MEMORY),
243243
errmsg("out of shared memory")));
244-
244+
245245
Assert(ShmemBootstrap && !found);
246-
246+
247247
result->location = MAKE_OFFSET(ShmemIndex->hctl);
248248
result->size = SHMEM_INDEX_SIZE;
249-
249+
250250
ShmemBootstrap = false;
251251
}
252252

0 commit comments

Comments
 (0)