diff options
author | Bruce Momjian | 2004-04-19 17:42:59 +0000 |
---|---|---|
committer | Bruce Momjian | 2004-04-19 17:42:59 +0000 |
commit | 4f93b20748c6b8527e73ad305d78726968e4696a (patch) | |
tree | 2ee618f32df3cd570e43c847225d325d5a7f2a7d | |
parent | 6994b2dac0124e609c96bc54b4f3ced8210ad920 (diff) |
* Most changes are to fix warnings issued when compiling win32
* removed a few redundant defines
* get_user_name safe under win32
* rationalized pipe read EOF for win32 (UPDATED PATCH USED)
* changed all backend instances of sleep() to pg_usleep
- except for the SLEEP_ON_ASSERT in assert.c, as it would exceed a
32-bit long [Note to patcher: If a SLEEP_ON_ASSERT of 2000 seconds is
acceptable, please replace with pg_usleep(2000000000L)]
I added a comment to that part of the code:
/*
* It would be nice to use pg_usleep() here, but only does 2000 sec
* or 33 minutes, which seems too short.
*/
sleep(1000000);
Claudio Natoli
29 files changed, 72 insertions, 65 deletions
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c index b27a51f6a1..022dbb62d0 100644 --- a/src/backend/access/transam/xlog.c +++ b/src/backend/access/transam/xlog.c @@ -2830,7 +2830,7 @@ StartupXLOG(void) /* This is just to allow attaching to startup process with a debugger */ #ifdef XLOG_REPLAY_DELAY if (ControlFile->state != DB_SHUTDOWNED) - sleep(60); + pg_usleep(60000000L); #endif /* @@ -3360,7 +3360,7 @@ CreateCheckPoint(bool shutdown, bool force) while (!LWLockConditionalAcquire(CheckpointLock, LW_EXCLUSIVE)) { CHECK_FOR_INTERRUPTS(); - sleep(1); + pg_usleep(1000000L); } /* diff --git a/src/backend/commands/dbcommands.c b/src/backend/commands/dbcommands.c index 9a1897cf51..0505bdf4d1 100644 --- a/src/backend/commands/dbcommands.c +++ b/src/backend/commands/dbcommands.c @@ -64,7 +64,9 @@ createdb(const CreatedbStmt *stmt) char *alt_loc; char *target_dir; char src_loc[MAXPGPATH]; +#ifndef WIN32 char buf[2 * MAXPGPATH + 100]; +#endif Oid src_dboid; AclId src_owner; int src_encoding; diff --git a/src/backend/libpq/md5.c b/src/backend/libpq/md5.c index c9f6b1f83e..011047bd22 100644 --- a/src/backend/libpq/md5.c +++ b/src/backend/libpq/md5.c @@ -33,9 +33,7 @@ #ifdef FRONTEND #include "postgres_fe.h" -#ifndef WIN32 #include "libpq/crypt.h" -#endif /* WIN32 */ #endif /* FRONTEND */ #ifdef MD5_ODBC diff --git a/src/backend/main/main.c b/src/backend/main/main.c index 7e389a4c8e..8556a9a77e 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -50,7 +50,9 @@ int main(int argc, char *argv[]) { int len; +#ifndef WIN32 struct passwd *pw; +#endif char *pw_name_persist; /* diff --git a/src/backend/port/sysv_shmem.c b/src/backend/port/sysv_shmem.c index 266f8f4768..af05cc9574 100644 --- a/src/backend/port/sysv_shmem.c +++ b/src/backend/port/sysv_shmem.c @@ -259,7 +259,7 @@ PGSharedMemoryCreate(uint32 size, bool makePrivate, int port) PGSharedMemoryDetach(); UsedShmemSegAddr = origUsedShmemSegAddr; #endif - elog(DEBUG3,"Attaching to %x",UsedShmemSegAddr); + elog(DEBUG3,"Attaching to %p",UsedShmemSegAddr); hdr = PGSharedMemoryAttach((IpcMemoryKey) UsedShmemSegID, &shmid); if (hdr == NULL) elog(FATAL, "could not attach to proper memory at fixed address: shmget(key=%d, addr=%p) failed: %m", diff --git a/src/backend/port/win32/shmem.c b/src/backend/port/win32/shmem.c index 4492d23c65..ec4fd5a7a9 100644 --- a/src/backend/port/win32/shmem.c +++ b/src/backend/port/win32/shmem.c @@ -22,7 +22,7 @@ static DWORD s_segsize = 0; int shmdt(const void *shmaddr) { - if (UnmapViewOfFile(shmaddr)) + if (UnmapViewOfFile((LPCVOID*)shmaddr)) return 0; else return -1; diff --git a/src/backend/port/win32/timer.c b/src/backend/port/win32/timer.c index 41fdb88879..47050fc61a 100644 --- a/src/backend/port/win32/timer.c +++ b/src/backend/port/win32/timer.c @@ -43,9 +43,9 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue timerHandle = CreateWaitableTimer(NULL, TRUE, NULL); if (timerHandle == NULL) ereport(FATAL, - (errmsg_internal("failed to create waitable timer: %i",GetLastError()))); + (errmsg_internal("failed to create waitable timer: %i",(int)GetLastError()))); } - + if (value->it_value.tv_sec == 0 && value->it_value.tv_usec == 0) { /* Turn timer off */ @@ -55,11 +55,11 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue /* Negative time to SetWaitableTimer means relative time */ dueTime.QuadPart = -(value->it_value.tv_usec*10 + value->it_value.tv_sec*10000000L); - + /* Turn timer on, or change timer */ - if (!SetWaitableTimer(timerHandle, &dueTime, 0, timer_completion, NULL, FALSE)) + if (!SetWaitableTimer(timerHandle, &dueTime, 0, timer_completion, NULL, FALSE)) ereport(FATAL, - (errmsg_internal("failed to set waitable timer: %i",GetLastError()))); + (errmsg_internal("failed to set waitable timer: %i",(int)GetLastError()))); return 0; } diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c index 6a66b4a3e6..2eb0f17637 100644 --- a/src/backend/postmaster/pgstat.c +++ b/src/backend/postmaster/pgstat.c @@ -1730,13 +1730,6 @@ pgstat_mainChild(PGSTAT_FORK_ARGS) { if (errno == EINTR) continue; -#ifdef WIN32 - if (WSAGetLastError() == WSAECONNRESET) /* EOF on the pipe! (win32 socket based implementation) */ - { - pipeEOF = true; - break; - } -#endif ereport(LOG, (errcode_for_socket_access(), errmsg("could not read from statistics collector pipe: %m"))); diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index 344a6ca935..d396148a89 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -314,8 +314,6 @@ static unsigned long tmpBackendFileNum = 0; void read_backend_variables(unsigned long id, Port *port); static bool write_backend_variables(Port *port); -size_t ShmemBackendArraySize(void); -void ShmemBackendArrayAllocation(void); static void ShmemBackendArrayAdd(Backend *bn); static void ShmemBackendArrayRemove(pid_t pid); #endif @@ -2561,7 +2559,7 @@ BackendRun(Port *port) * PGOPTIONS, but it is not honored until after authentication.) */ if (PreAuthDelay > 0) - sleep(PreAuthDelay); + pg_usleep(PreAuthDelay*1000000L); /* Will exit on failure */ BackendInit(port); @@ -3455,8 +3453,8 @@ static void ShmemBackendArrayAdd(Backend *bn) } } - /* FIXME: [fork/exec] some sort of error */ - abort(); + ereport(FATAL, + (errmsg_internal("unable to add backend entry"))); } static void ShmemBackendArrayRemove(pid_t pid) @@ -3472,7 +3470,6 @@ static void ShmemBackendArrayRemove(pid_t pid) } } - /* Something stronger than WARNING here? */ ereport(WARNING, (errmsg_internal("unable to find backend entry with pid %d", pid))); @@ -3565,8 +3562,9 @@ static void win32_AddChild(pid_t pid, HANDLE handle) ++win32_numChildren; } else - /* FIXME: [fork/exec] some sort of error */ - abort(); + ereport(FATAL, + (errmsg_internal("unable to add child entry with pid %lu", + pid))); } static void win32_RemoveChild(pid_t pid) @@ -3588,7 +3586,6 @@ static void win32_RemoveChild(pid_t pid) } } - /* Something stronger than WARNING here? */ ereport(WARNING, (errmsg_internal("unable to find child entry with pid %lu", pid))); diff --git a/src/backend/storage/smgr/md.c b/src/backend/storage/smgr/md.c index 1c52914d84..2c54e61742 100644 --- a/src/backend/storage/smgr/md.c +++ b/src/backend/storage/smgr/md.c @@ -607,7 +607,7 @@ mdsync(void) { sync(); if (IsUnderPostmaster) - sleep(2); + pg_usleep(2000000L); sync(); return true; } diff --git a/src/backend/tcop/postgres.c b/src/backend/tcop/postgres.c index f196672fd8..85585741c7 100644 --- a/src/backend/tcop/postgres.c +++ b/src/backend/tcop/postgres.c @@ -2456,7 +2456,7 @@ PostgresMain(int argc, char *argv[], const char *username) /* * wait N seconds to allow attach from a debugger */ - sleep(atoi(optarg)); + pg_usleep(atoi(optarg)*1000000L); break; case 'x': diff --git a/src/backend/utils/error/assert.c b/src/backend/utils/error/assert.c index 5383850165..3568d96b22 100644 --- a/src/backend/utils/error/assert.c +++ b/src/backend/utils/error/assert.c @@ -40,7 +40,11 @@ ExceptionalCondition(char *conditionName, } #ifdef SLEEP_ON_ASSERT - sleep(1000000); + /* + * It would be nice to use pg_usleep() here, but only does 2000 sec + * or 33 minutes, which seems too short. + */ + sleep(1000000); #endif abort(); diff --git a/src/backend/utils/hash/dynahash.c b/src/backend/utils/hash/dynahash.c index 1c6cbe83e7..7a2d6ce90a 100644 --- a/src/backend/utils/hash/dynahash.c +++ b/src/backend/utils/hash/dynahash.c @@ -85,6 +85,7 @@ DynaHashAlloc(Size size) } #define MEM_ALLOC DynaHashAlloc +#undef MEM_FREE /* already in windows header files */ #define MEM_FREE pfree diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c index e13e923d65..d36e73d4e8 100644 --- a/src/backend/utils/init/miscinit.c +++ b/src/backend/utils/init/miscinit.c @@ -213,11 +213,11 @@ SetDataDir(const char *dir) * generating funny-looking paths to individual files. */ newlen = strlen(new); - if (newlen > 1 && new[newlen - 1] == '/' + if (newlen > 1 && (new[newlen - 1] == '/' #ifdef WIN32 || new[newlen - 1] == '\\' #endif - ) + )) new[newlen - 1] = '\0'; if (DataDir) diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h index 12690e2758..05d868bf69 100644 --- a/src/bin/psql/common.h +++ b/src/bin/psql/common.h @@ -60,12 +60,6 @@ extern const char *session_username(void); */ extern char parse_char(char **buf); -/* Used for all Win32 popen/pclose calls */ -#ifdef WIN32 -#define popen(x,y) _popen(x,y) -#define pclose(x) _pclose(x) -#endif - extern char *expand_tilde(char **filename); #endif /* COMMON_H */ diff --git a/src/bin/psql/copy.c b/src/bin/psql/copy.c index f1ae831530..da7532eea1 100644 --- a/src/bin/psql/copy.c +++ b/src/bin/psql/copy.c @@ -26,7 +26,7 @@ #include "prompt.h" #include "stringutils.h" -#ifdef WIN32 +#if defined(WIN32) && (!defined(__MINGW32__)) #define strcasecmp(x,y) stricmp(x,y) #define __S_ISTYPE(mode, mask) (((mode) & S_IFMT) == (mask)) #define S_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR) diff --git a/src/bin/psql/startup.c b/src/bin/psql/startup.c index 5a6f512e96..b92bb49032 100644 --- a/src/bin/psql/startup.c +++ b/src/bin/psql/startup.c @@ -573,8 +573,8 @@ process_psqlrc(void) char *psqlrc; char *home; -#ifdef WIN32 -#define R_OK 0 +#if defined(WIN32) && (!defined(__MINGW32__)) +#define R_OK 4 #endif /* Look for one in the home dir */ diff --git a/src/bin/scripts/common.c b/src/bin/scripts/common.c index 46b96d1399..16ba673575 100644 --- a/src/bin/scripts/common.c +++ b/src/bin/scripts/common.c @@ -35,10 +35,15 @@ get_user_name(const char *progname) return pw->pw_name; #else static char username[128]; /* remains after function exit */ + DWORD len = sizeof(username)-1; - GetUserName(username, sizeof(username)-1); + if (!GetUserName(username, &len)) + { + perror(progname); + exit(1); + } return username; -#endif +#endif } diff --git a/src/include/port.h b/src/include/port.h index ac5cce70de..fa9a9c76ca 100644 --- a/src/include/port.h +++ b/src/include/port.h @@ -48,7 +48,7 @@ extern off_t ftello(FILE *stream); #define pipewrite(a,b,c) write(a,b,c) #else extern int pgpipe(int handles[2]); -#define piperead(a,b,c) recv(a,b,c,0) +extern int piperead(int s, char* buf, int len); #define pipewrite(a,b,c) send(a,b,c,0) #endif @@ -70,6 +70,11 @@ extern int win32_open(const char*,int,...); #define open(a,b,...) win32_open(a,b,##__VA_ARGS__) #endif +#ifndef __BORLANDC__ +#define popen(a,b) _popen(a,b) +#define pclose(a) _pclose(a) +#endif + extern int copydir(char *fromdir, char *todir); /* Missing rand functions */ diff --git a/src/include/port/win32.h b/src/include/port/win32.h index 6b548f9276..cab1fd6d01 100644 --- a/src/include/port/win32.h +++ b/src/include/port/win32.h @@ -6,6 +6,7 @@ #undef ERROR #include <windows.h> #include <winsock.h> +#include <process.h> #undef near /* Must be here to avoid conflicting with prototype in windows.h */ @@ -192,14 +193,6 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue */ #define lstat slat -#define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -#define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) - -#define S_IRUSR _S_IREAD -#define S_IWUSR _S_IWRITE -#define S_IXUSR _S_IEXEC -#define S_IRWXU (_S_IREAD | _S_IWRITE | _S_IEXEC) - /* * Supplement to <errno.h>. */ diff --git a/src/include/storage/ipc.h b/src/include/storage/ipc.h index 0bd400d2ca..12940e4a3a 100644 --- a/src/include/storage/ipc.h +++ b/src/include/storage/ipc.h @@ -32,4 +32,11 @@ extern void on_exit_reset(void); extern void CreateSharedMemoryAndSemaphores(bool makePrivate, int maxBackends, int port); + +#ifdef EXEC_BACKEND +/* postmaster.c */ +extern size_t ShmemBackendArraySize(void); +extern void ShmemBackendArrayAllocation(void); +#endif + #endif /* IPC_H */ diff --git a/src/interfaces/libpq/Makefile b/src/interfaces/libpq/Makefile index 52084ed883..8ce2a25805 100644 --- a/src/interfaces/libpq/Makefile +++ b/src/interfaces/libpq/Makefile @@ -78,4 +78,4 @@ uninstall: uninstall-lib rm -f $(DESTDIR)$(includedir)/libpq-fe.h $(DESTDIR)$(includedir_internal)/libpq-int.h $(DESTDIR)$(includedir_internal)/pqexpbuffer.h clean distclean maintainer-clean: clean-lib - rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c noblock.c snprintf.c strerror.c path.c thread.c dllist.c md5.c ip.c encnames.c wchar.c + rm -f $(OBJS) crypt.c getaddrinfo.c inet_aton.c noblock.c snprintf.c strerror.c open.c path.c thread.c dllist.c md5.c ip.c encnames.c wchar.c diff --git a/src/interfaces/libpq/fe-print.c b/src/interfaces/libpq/fe-print.c index 003fd039a3..98f4f07468 100644 --- a/src/interfaces/libpq/fe-print.c +++ b/src/interfaces/libpq/fe-print.c @@ -183,11 +183,7 @@ PQprint(FILE *fout, - (po->header != 0) * 2 /* row count and newline */ ))) { -#ifdef WIN32 - fout = _popen(pagerenv, "w"); -#else fout = popen(pagerenv, "w"); -#endif if (fout) { usePipe = 1; diff --git a/src/interfaces/libpq/win32.c b/src/interfaces/libpq/win32.c index 96097bca59..c0bdf58ffd 100644 --- a/src/interfaces/libpq/win32.c +++ b/src/interfaces/libpq/win32.c @@ -309,14 +309,14 @@ winsock_strerror(int err, char *strerrbuf, size_t buflen) } if (!success) - sprintf(strerrbuf, "Unknown socket error (0x%08X/%lu)", err, err); + sprintf(strerrbuf, "Unknown socket error (0x%08X/%i)", err, err); else { strerrbuf[buflen - 1] = '\0'; offs = strlen(strerrbuf); if (offs > (int)buflen - 64) offs = buflen - 64; - sprintf(strerrbuf + offs, " (0x%08X/%lu)", err, err); + sprintf(strerrbuf + offs, " (0x%08X/%i)", err, err); } return strerrbuf; } diff --git a/src/interfaces/libpq/win32.h b/src/interfaces/libpq/win32.h index 9d4557fc0d..350b350b48 100644 --- a/src/interfaces/libpq/win32.h +++ b/src/interfaces/libpq/win32.h @@ -22,8 +22,6 @@ #define write(a,b,c) _write(a,b,c) #endif -#define popen(a,b) _popen(a,b) -#define pclose(a) _pclose(a) #define vsnprintf(a,b,c,d) _vsnprintf(a,b,c,d) #define snprintf _snprintf diff --git a/src/port/open.c b/src/port/open.c index 9af15cc56c..9ea2581058 100644 --- a/src/port/open.c +++ b/src/port/open.c @@ -18,7 +18,8 @@ #include <errno.h> #include <assert.h> -int openFlagsToCreateFileFlags(int openFlags) +static int +openFlagsToCreateFileFlags(int openFlags) { switch (openFlags & (O_CREAT|O_TRUNC|O_EXCL)) { diff --git a/src/port/pipe.c b/src/port/pipe.c index 3c96324d6f..d273286798 100644 --- a/src/port/pipe.c +++ b/src/port/pipe.c @@ -53,3 +53,13 @@ pgpipe(int handles[2]) closesocket(s); return 0; } + + +int piperead(int s, char* buf, int len) +{ + int ret = recv(s,buf,len,0); + if (ret < 0 && WSAGetLastError() == WSAECONNRESET) + /* EOF on the pipe! (win32 socket based implementation) */ + ret = 0; + return ret; +} diff --git a/src/port/rand.c b/src/port/rand.c index faeec88b28..7fc3094dec 100644 --- a/src/port/rand.c +++ b/src/port/rand.c @@ -5,6 +5,7 @@ * *------------------------------------------------------------------------- */ +#include "c.h" /* * Copyright (c) 1993 Martin Birgmeier @@ -38,7 +39,7 @@ unsigned short _rand48_mult[3] = { }; unsigned short _rand48_add = RAND48_ADD; -void +static void _dorand48(unsigned short xseed[3]) { unsigned long accu; diff --git a/src/port/sprompt.c b/src/port/sprompt.c index 052014022c..accaebe143 100644 --- a/src/port/sprompt.c +++ b/src/port/sprompt.c @@ -54,8 +54,8 @@ simple_prompt(const char *prompt, int maxlen, bool echo) #else #ifdef WIN32 - HANDLE t; - LPDWORD t_orig; + HANDLE t = NULL; + LPDWORD t_orig = NULL; #endif #endif |