Drops in the CreateProcess calls for Win32 (essentially wrapping up the
authorBruce Momjian <bruce@momjian.us>
Sun, 11 Jan 2004 03:49:31 +0000 (03:49 +0000)
committerBruce Momjian <bruce@momjian.us>
Sun, 11 Jan 2004 03:49:31 +0000 (03:49 +0000)
fork/exec portion of the port), and fixes a handful of whitespace issues

Claudio Natoli

src/backend/main/main.c
src/backend/postmaster/pgstat.c
src/backend/postmaster/postmaster.c
src/backend/storage/freespace/freespace.c
src/backend/storage/ipc/pmsignal.c
src/backend/storage/ipc/shmem.c

index b8dffc430a10c6e36503b78f13e3a97246649ee9..fe8879940efb2e2e05993b856bdc5b019f4a15f5 100644 (file)
@@ -13,7 +13,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/main/main.c,v 1.70 2004/01/06 23:15:22 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/main/main.c,v 1.71 2004/01/11 03:49:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -87,6 +87,19 @@ main(int argc, char *argv[])
 #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 2522793d2a5d9f40ea6c8eba62c1557537febd2c..6b9b8ac1bc806a287775a5404a4cb65581ddfc95 100644 (file)
@@ -13,7 +13,7 @@
  *
  * Copyright (c) 2001-2003, PostgreSQL Global Development Group
  *
- * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.52 2004/01/09 04:58:09 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/postmaster/pgstat.c,v 1.53 2004/01/11 03:49:31 momjian Exp $
  * ----------
  */
 #include "postgres.h"
@@ -50,6 +50,9 @@
 #include "utils/ps_status.h"
 #include "utils/syscache.h"
 
+#ifdef WIN32
+extern pid_t win32_forkexec(const char* path, char *argv[]);
+#endif
 
 /* ----------
  * GUC parameters
@@ -402,10 +405,13 @@ pgstat_forkexec(STATS_PROCESS_TYPE procType)
    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 6ce0fe629b50d0194cbdcc18332bfcb77c9239f1..56fec21acb37752db76060b8825000bb9fc3833b 100644 (file)
@@ -37,7 +37,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.357 2004/01/09 23:27:20 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/postmaster/postmaster.c,v 1.358 2004/01/11 03:49:31 momjian Exp $
  *
  * NOTES
  *
@@ -297,6 +297,10 @@ postmaster_error(const char *fmt,...)
 __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,7 +927,12 @@ pmdaemonize(int argc, char *argv[])
    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",
@@ -2692,6 +2701,9 @@ Backend_forkexec(Port *port)
    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))
        /*
@@ -2699,7 +2711,7 @@ Backend_forkexec(Port *port)
         *  Probably OK to issue error (unlike pgstat case)
         */
        abort();
-
+#endif
    return pid; /* Parent returns pid */
 }
 
@@ -3039,12 +3051,16 @@ SSDataBase(int xlop)
 
 #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);
@@ -3335,3 +3351,52 @@ read_backend_variables(unsigned long id, Port *port)
 }
 
 #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 84f5c65c928239a5c82fee8c0e42272457619cf5..20f21866295f7cdb67d3960062594005c1be2845 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.28 2003/12/20 17:31:21 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/freespace/freespace.c,v 1.29 2004/01/11 03:49:31 momjian Exp $
  *
  *
  * NOTES:
@@ -274,7 +274,7 @@ InitFreeSpaceMap(void)
                (errcode(ERRCODE_OUT_OF_MEMORY),
               errmsg("insufficient shared memory for free space map")));
    if (!found)
-   MemSet(FreeSpaceMap, 0, sizeof(FSMHeader));
+       MemSet(FreeSpaceMap, 0, sizeof(FSMHeader));
 
    /* Create hashtable for FSMRelations */
    info.keysize = sizeof(RelFileNode);
index fb2b2faca0f9467e685194b772c990213977d9ba..137e864aa50db48f0829eba7b81e713f321c65ba 100644 (file)
@@ -8,7 +8,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.7 2003/12/20 17:31:21 momjian Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/ipc/pmsignal.c,v 1.8 2004/01/11 03:49:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -49,7 +49,7 @@ PMSignalInit(void)
        ShmemInitStruct("PMSignalFlags",NUM_PMSIGNALS * sizeof(sig_atomic_t),&found);
 
    if (!found)
-   MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
+       MemSet(PMSignalFlags, 0, NUM_PMSIGNALS * sizeof(sig_atomic_t));
 }
 
 /*
index 49af9287131b130f0317f6bdf650885f066a312c..7323cca62d1c96d501225620c1c615bee045c6f1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.77 2003/12/30 00:03:03 tgl Exp $
+ *   $PostgreSQL: pgsql/src/backend/storage/ipc/shmem.c,v 1.78 2004/01/11 03:49:31 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -118,10 +118,10 @@ InitShmemAllocation(void *seghdr, bool init)
 
        SpinLockInit(ShmemLock);
        SpinLockInit(ShmemIndexLock);
-   
+
        /* ShmemIndex can't be set up yet (need LWLocks first) */
        ShmemIndex = (HTAB *) NULL;
-   
+
        /*
         * Initialize ShmemVariableCache for transaction manager.
         */
@@ -234,19 +234,19 @@ InitShmemIndex(void)
    {
        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;
    }