summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Momjian2004-02-02 00:11:31 +0000
committerBruce Momjian2004-02-02 00:11:31 +0000
commitfaa6351ece661132c41d4d9f985ed3837191bfc8 (patch)
treebb796b1ace4581775550481f7e76ee540b9cdddd
parente77427443ca6e2d358b97785d3f7f1722ee589b9 (diff)
Briefly,
* configure + Makefile changes * shared memory attaching in EXEC_BACKEND case (+ minor fix for apparent cygwin bug under cygwin/EXEC_BACKEND case only) * PATH env var separator differences * missing win32 rand functions added * placeholder replacements for sync etc under port.h To those who are really interested, and there are a few of you: the attached patch + file will allow the source base to be compiled (and, for some definition, "run") under MingW, with the following caveats (I wanted to first properly fix all but the last of these, but y'all won't quit asking for a patch :-): * child death: SIGCHLD not yet sent, so as a minimum, you'll need to put in some sort of delay after StartupDatabase, and handle setting StartupPID to 0 etc (ie. the stuff the reaper() signal function is supposed to do) * dirmod.c: comment out the elog calls * dfmgr.c: some hackage required to substitute_libpath_macro * slru/xact.c: comment out the errno checking after the readdir (fixed by next version of MingW) Again, this is only if you *really* want to see postgres compile and start, and is a nice leg-up for working on the other Win32 TODO list items. Just don't expect too much else from it at this point... Claudio Natoli
-rwxr-xr-xconfigure3
-rw-r--r--src/Makefile.global.in5
-rw-r--r--src/backend/Makefile41
-rw-r--r--src/backend/main/main.c6
-rw-r--r--src/backend/port/sysv_shmem.c39
-rw-r--r--src/backend/port/win32/shmem.c2
-rw-r--r--src/backend/utils/init/findbe.c4
-rw-r--r--src/bin/initdb/initdb.c5
-rw-r--r--src/include/port.h21
-rw-r--r--src/interfaces/libpq/Makefile3
-rw-r--r--src/interfaces/libpq/pqsignal.c4
-rw-r--r--src/interfaces/libpq/win32.c2
-rw-r--r--src/port/rand.c78
13 files changed, 195 insertions, 18 deletions
diff --git a/configure b/configure
index 3c23e6647e..b691160818 100755
--- a/configure
+++ b/configure
@@ -2502,7 +2502,7 @@ echo "$as_me: using CFLAGS=$CFLAGS" >&6;}
# We already have this in Makefile.win32, but configure needs it too
if test "$PORTNAME" = "win32"; then
- CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32"
+ CPPFLAGS="$CPPFLAGS -I$srcdir/src/include/port/win32 -DEXEC_BACKEND"
fi
# Check if the compiler still works with the template settings
@@ -12079,6 +12079,7 @@ esac
case $host_os in mingw*)
LIBOBJS="$LIBOBJS dirmod.$ac_objext"
LIBOBJS="$LIBOBJS copydir.$ac_objext"
+LIBOBJS="$LIBOBJS rand.$ac_objext"
LIBOBJS="$LIBOBJS gettimeofday.$ac_objext"
LIBOBJS="$LIBOBJS pipe.$ac_objext" ;;
esac
diff --git a/src/Makefile.global.in b/src/Makefile.global.in
index cf0c2223e6..a99ce1f417 100644
--- a/src/Makefile.global.in
+++ b/src/Makefile.global.in
@@ -346,6 +346,11 @@ LIBS += -lpgport
LDFLAGS := -L$(top_builddir)/src/port $(LDFLAGS)
endif
+# to make ws2_32.lib the last library
+ifeq ($(PORTNAME),win32)
+LIBS += -lws2_32
+endif
+
# Not really standard libc functions, used by the backend.
TAS = @TAS@
diff --git a/src/backend/Makefile b/src/backend/Makefile
index 1c9d9b9005..7202b6c16b 100644
--- a/src/backend/Makefile
+++ b/src/backend/Makefile
@@ -32,12 +32,15 @@ endif
all: submake-libpgport postgres $(POSTGRES_IMP)
ifneq ($(PORTNAME), cygwin)
+ifneq ($(PORTNAME), win32)
postgres: $(OBJS)
$(CC) $(CFLAGS) $(LDFLAGS) $(export_dynamic) $^ $(LIBS) -o $@
-else # cygwin
+endif
+endif
+ifeq ($(PORTNAME), cygwin)
postgres: $(OBJS) $(DLLINIT) postgres.def libpostgres.a
$(DLLTOOL) --dllname $@$(X) --output-exp [email protected] --def postgres.def
$(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,[email protected] [email protected] $(OBJS) $(LIBS)
@@ -53,6 +56,24 @@ libpostgres.a: postgres.def
endif # cygwin
+ifeq ($(PORTNAME), win32)
+
+postgres: $(OBJS) $(DLLINIT) postgres.def libpostgres.a
+ $(DLLTOOL) --dllname $@$(X) --output-exp [email protected] --def postgres.def
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) -Wl,--base-file,[email protected] [email protected] $(OBJS) $(LIBS)
+ $(DLLTOOL) --dllname $@$(X) --base-file [email protected] --output-exp [email protected] --def postgres.def
+ $(CC) $(CFLAGS) $(LDFLAGS) -o $@$(X) [email protected] $(OBJS) $(LIBS)
+
+postgres.def: $(OBJS)
+ $(DLLTOOL) --export-all --output-def $@ $^
+
+libpostgres.a: postgres.def
+ $(DLLTOOL) --dllname postgres.exe --def postgres.def --output-lib $@
+
+endif # win32
+
+
ifeq ($(PORTNAME), aix)
postgres: $(POSTGRES_IMP)
@@ -131,6 +152,11 @@ ifeq ($(MAKE_DLL), true)
$(INSTALL_DATA) libpostgres.a $(DESTDIR)$(libdir)/libpostgres.a
endif
endif
+ifeq ($(PORTNAME), win32)
+ifeq ($(MAKE_DLL), true)
+ $(INSTALL_DATA) libpostgres.a $(DESTDIR)$(libdir)/libpostgres.a
+endif
+endif
$(MAKE) -C catalog install-data
$(INSTALL_DATA) $(srcdir)/libpq/pg_hba.conf.sample $(DESTDIR)$(datadir)/pg_hba.conf.sample
$(INSTALL_DATA) $(srcdir)/libpq/pg_ident.conf.sample $(DESTDIR)$(datadir)/pg_ident.conf.sample
@@ -157,6 +183,11 @@ ifeq ($(MAKE_DLL), true)
$(mkinstalldirs) $(DESTDIR)$(libdir)
endif
endif
+ifeq ($(PORTNAME), win32)
+ifeq ($(MAKE_DLL), true)
+ $(mkinstalldirs) $(DESTDIR)$(libdir)
+endif
+endif
ifeq ($(MAKE_EXPORTS), true)
$(mkinstalldirs) $(DESTDIR)$(pkglibdir)
endif
@@ -174,6 +205,11 @@ ifeq ($(MAKE_DLL), true)
rm -f $(DESTDIR)$(libdir)/libpostgres.a
endif
endif
+ifeq ($(PORTNAME), win32)
+ifeq ($(MAKE_DLL), true)
+ rm -f $(DESTDIR)$(libdir)/libpostgres.a
+endif
+endif
$(MAKE) -C catalog uninstall-data
rm -f $(DESTDIR)$(datadir)/pg_hba.conf.sample \
$(DESTDIR)$(datadir)/pg_service.conf.sample \
@@ -190,6 +226,9 @@ clean:
ifeq ($(PORTNAME), cygwin)
rm -f postgres.dll postgres.def libpostgres.a
endif
+ifeq ($(PORTNAME), win32)
+ rm -f postgres.dll postgres.def libpostgres.a
+endif
for i in $(DIRS); do $(MAKE) -C $$i clean || exit; done
distclean: clean
diff --git a/src/backend/main/main.c b/src/backend/main/main.c
index ea2a7c9173..8868448fd7 100644
--- a/src/backend/main/main.c
+++ b/src/backend/main/main.c
@@ -227,7 +227,11 @@ main(int argc, char *argv[])
*/
len = strlen(new_argv[0]);
- if (len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 0)
+ if ((len >= 10 && strcmp(new_argv[0] + len - 10, "postmaster") == 0)
+#ifdef WIN32
+ || (len >= 14 && strcmp(new_argv[0] + len - 14, "postmaster.exe") == 0)
+#endif
+ )
{
/* Called as "postmaster" */
exit(PostmasterMain(argc, new_argv));
diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c
index 40dd5ae3fd..7ffecf1653 100644
--- a/src/backend/port/sysv_shmem.c
+++ b/src/backend/port/sysv_shmem.c
@@ -140,8 +140,13 @@ InternalIpcMemoryCreate(IpcMemoryKey memKey, uint32 size)
/* use intimate shared memory on Solaris */
memAddress = shmat(shmid, 0, SHM_SHARE_MMU);
#else
+
+#ifdef EXEC_BACKEND
+ memAddress = shmat(shmid, UsedShmemSegAddr, 0);
+#else
memAddress = shmat(shmid, 0, 0);
#endif
+#endif
if (memAddress == (void *) -1)
elog(FATAL, "shmat(id=%d) failed: %m", shmid);
@@ -244,18 +249,32 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port)
PGShmemHeader *hdr;
IpcMemoryId shmid;
- /* Room for a header? */
- Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
-
+#ifdef EXEC_BACKEND
/* If Exec case, just attach and return the pointer */
- if (ExecBackend && UsedShmemSegAddr != NULL && !makePrivate)
+ if (UsedShmemSegAddr != NULL && !makePrivate)
{
+ void* origUsedShmemSegAddr = UsedShmemSegAddr;
+
+#ifdef CYGWIN
+ /* cygipc (currently) appears to not detach on exec. */
+ PGSharedMemoryDetach();
+ UsedShmemSegAddr = origUsedShmemSegAddr;
+#endif
+ elog(DEBUG3,"Attaching to %x",UsedShmemSegAddr);
hdr = PGSharedMemoryAttach((IpcMemoryKey) UsedShmemSegID, &shmid);
if (hdr == NULL)
- elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%lu, addr=%p) failed: %m",
- UsedShmemSegID, UsedShmemSegAddr);
+ elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %m",
+ (int) UsedShmemSegID, UsedShmemSegAddr);
+ if (hdr != origUsedShmemSegAddr)
+ elog(FATAL,"attaching to shared mem returned unexpected address (got %p, expected %p)",
+ hdr,UsedShmemSegAddr);
+ UsedShmemSegAddr = hdr;
return hdr;
}
+#endif
+
+ /* Room for a header? */
+ Assert(size > MAXALIGN(sizeof(PGShmemHeader)));
/* Make sure PGSharedMemoryAttach doesn't fail without need */
UsedShmemSegAddr = NULL;
@@ -354,12 +373,18 @@ PGSharedMemoryDetach(void)
{
if (UsedShmemSegAddr != NULL)
{
- if (shmdt(UsedShmemSegAddr) < 0)
+ if ((shmdt(UsedShmemSegAddr) < 0)
+#if (defined(EXEC_BACKEND) && defined(CYGWIN))
+ /* Work-around for cygipc exec bug */
+ && shmdt(NULL) < 0
+#endif
+ )
elog(LOG, "shmdt(%p) failed: %m", UsedShmemSegAddr);
UsedShmemSegAddr = NULL;
}
}
+
/*
* Attach to shared memory and make sure it has a Postgres header
*
diff --git a/src/backend/port/win32/shmem.c b/src/backend/port/win32/shmem.c
index e3ab1f724d..0048d7554a 100644
--- a/src/backend/port/win32/shmem.c
+++ b/src/backend/port/win32/shmem.c
@@ -32,7 +32,7 @@ shmat(int memId, void *shmaddr, int flag)
/* TODO -- shmat needs to count # attached to shared mem */
void *lpmem = MapViewOfFileEx((HANDLE) memId,
FILE_MAP_WRITE | FILE_MAP_READ,
- 0, 0, /* (DWORD)pshmdsc->segsize */ s_segsize, shmaddr);
+ 0, 0, /* (DWORD)pshmdsc->segsize */ 0 /* s_segsize */, shmaddr);
if (lpmem == NULL)
{
diff --git a/src/backend/utils/init/findbe.c b/src/backend/utils/init/findbe.c
index 267c4afb9a..49049b0d03 100644
--- a/src/backend/utils/init/findbe.c
+++ b/src/backend/utils/init/findbe.c
@@ -205,9 +205,9 @@ FindExec(char *full_path, const char *argv0, const char *binary_name)
{
elog(DEBUG2, "searching PATH for executable");
path = strdup(p); /* make a modifiable copy */
- for (startp = path, endp = strchr(path, ':');
+ for (startp = path, endp = strchr(path, PATHSEP);
startp && *startp;
- startp = endp + 1, endp = strchr(startp, ':'))
+ startp = endp + 1, endp = strchr(startp, PATHSEP))
{
if (startp == endp) /* it's a "::" */
continue;
diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c
index 4b228098d7..e97a0b9942 100644
--- a/src/bin/initdb/initdb.c
+++ b/src/bin/initdb/initdb.c
@@ -144,11 +144,6 @@ static const char *backend_options = "-F -O -c search_path=pg_catalog -c exit_on
#define DEVNULL "/dev/null"
#endif
-#ifdef WIN32
-#define PATHSEP ';'
-#else
-#define PATHSEP ':'
-#endif
/* detected path to postgres and (we assume) friends */
char *pgpath;
diff --git a/src/include/port.h b/src/include/port.h
index b53c29633c..445a189acf 100644
--- a/src/include/port.h
+++ b/src/include/port.h
@@ -44,6 +44,10 @@ extern int pgunlink(const char *path);
extern int copydir(char *fromdir, char *todir);
+/* Missing rand functions */
+extern long lrand48(void);
+extern void srand48(long seed);
+
/* Last parameter not used */
extern int gettimeofday(struct timeval * tp, struct timezone * tzp);
@@ -122,3 +126,20 @@ extern int pqGethostbyname(const char *name,
char *buffer, size_t buflen,
struct hostent **result,
int *herrno);
+
+/* $PATH (or %PATH%) path separator */
+#ifdef WIN32
+#define PATHSEP ';'
+#else
+#define PATHSEP ':'
+#endif
+
+/* FIXME: [win32] Placeholder win32 replacements, to allow continued development */
+#ifdef WIN32
+#define fsync(a) _commit(a)
+#define sync() _flushall()
+#define WEXITSTATUS(w) (((w) >> 8) & 0xff)
+#define WIFEXITED(w) (((w) & 0xff) == 0)
+#define WIFSIGNALED(w) (((w) & 0x7f) > 0 && (((w) & 0x7f) < 0x7f))
+#define WTERMSIG(w) ((w) & 0x7f)
+#endif
diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile
index 695a4f8abf..80be1ca63a 100644
--- a/src/interfaces/libpq/Makefile
+++ b/src/interfaces/libpq/Makefile
@@ -33,6 +33,9 @@ endif
# shared library link. (The order in which you list them here doesn't
# matter.)
SHLIB_LINK += $(filter -lcrypt -ldes -lkrb -lcom_err -lcrypto -lk5crypto -lkrb5 -lssl -lsocket -lnsl -lresolv -lintl, $(LIBS)) $(THREAD_LIBS)
+ifeq ($(PORTNAME), win32)
+SHLIB_LINK += -lwsock32 -lws2_32
+endif
all: all-lib
diff --git a/src/interfaces/libpq/pqsignal.c b/src/interfaces/libpq/pqsignal.c
index 61054e8899..80e5de0cce 100644
--- a/src/interfaces/libpq/pqsignal.c
+++ b/src/interfaces/libpq/pqsignal.c
@@ -44,6 +44,7 @@ pqsignal(int signo, pqsigfunc func)
pqsigfunc
pqsignalinquire(int signo)
{
+#ifndef WIN32
#if !defined(HAVE_POSIX_SIGNALS)
pqsigfunc old_sigfunc;
int old_sigmask;
@@ -61,4 +62,7 @@ pqsignalinquire(int signo)
return SIG_ERR;
return oact.sa_handler;
#endif /* !HAVE_POSIX_SIGNALS */
+#else
+ return SIG_DFL;
+#endif
}
diff --git a/src/interfaces/libpq/win32.c b/src/interfaces/libpq/win32.c
index de83c38e85..96097bca59 100644
--- a/src/interfaces/libpq/win32.c
+++ b/src/interfaces/libpq/win32.c
@@ -22,7 +22,9 @@
#define WIN32_LEAN_AND_MEAN
#define WIN32_EXTRA_LEAN
#define VC_EXTRALEAN
+#ifndef __MINGW32__
#define NOGDI
+#endif
#define NOCRYPT
#include <windows.h>
diff --git a/src/port/rand.c b/src/port/rand.c
new file mode 100644
index 0000000000..faeec88b28
--- /dev/null
+++ b/src/port/rand.c
@@ -0,0 +1,78 @@
+/*-------------------------------------------------------------------------
+ *
+ * rand.c
+ * Missing rand implementations for Win32
+ *
+ *-------------------------------------------------------------------------
+ */
+
+/*
+ * Copyright (c) 1993 Martin Birgmeier
+ * All rights reserved.
+ *
+ * You may redistribute unmodified or modified versions of this source
+ * code provided that the above copyright notice and this and the
+ * following conditions are retained.
+ *
+ * This software is provided ``as is'', and comes with no warranties
+ * of any kind. I shall in no event be liable for anything that happens
+ * to anyone/anything when using this software.
+ */
+#define RAND48_SEED_0 (0x330e)
+#define RAND48_SEED_1 (0xabcd)
+#define RAND48_SEED_2 (0x1234)
+#define RAND48_MULT_0 (0xe66d)
+#define RAND48_MULT_1 (0xdeec)
+#define RAND48_MULT_2 (0x0005)
+#define RAND48_ADD (0x000b)
+
+unsigned short _rand48_seed[3] = {
+ RAND48_SEED_0,
+ RAND48_SEED_1,
+ RAND48_SEED_2
+};
+unsigned short _rand48_mult[3] = {
+ RAND48_MULT_0,
+ RAND48_MULT_1,
+ RAND48_MULT_2
+};
+unsigned short _rand48_add = RAND48_ADD;
+
+void
+_dorand48(unsigned short xseed[3])
+{
+ unsigned long accu;
+ unsigned short temp[2];
+
+ accu = (unsigned long) _rand48_mult[0] * (unsigned long) xseed[0] +
+ (unsigned long) _rand48_add;
+ temp[0] = (unsigned short) accu; /* lower 16 bits */
+ accu >>= sizeof(unsigned short) * 8;
+ accu += (unsigned long) _rand48_mult[0] * (unsigned long) xseed[1] +
+ (unsigned long) _rand48_mult[1] * (unsigned long) xseed[0];
+ temp[1] = (unsigned short) accu; /* middle 16 bits */
+ accu >>= sizeof(unsigned short) * 8;
+ accu += _rand48_mult[0] * xseed[2] + _rand48_mult[1] * xseed[1] + _rand48_mult[2] * xseed[0];
+ xseed[0] = temp[0];
+ xseed[1] = temp[1];
+ xseed[2] = (unsigned short) accu;
+}
+
+long
+lrand48(void)
+{
+ _dorand48(_rand48_seed);
+ return ((long) _rand48_seed[2] << 15) + ((long) _rand48_seed[1] >1);
+}
+
+void
+srand48(long seed)
+{
+ _rand48_seed[0] = RAND48_SEED_0;
+ _rand48_seed[1] = (unsigned short) seed;
+ _rand48_seed[2] = (unsigned short) (seed >16);
+ _rand48_mult[0] = RAND48_MULT_0;
+ _rand48_mult[1] = RAND48_MULT_1;
+ _rand48_mult[2] = RAND48_MULT_2;
+ _rand48_add = RAND48_ADD;
+}