diff options
author | Yaakov Selkowitz <yselkowitz@users.sourceforge.net> | 2012-10-15 00:03:26 -0500 |
---|---|---|
committer | Yaakov Selkowitz <yselkowitz@users.sourceforge.net> | 2012-10-15 00:21:19 -0500 |
commit | 93c5596aac6fa7dc6d83bd6f857503ebf8118423 (patch) | |
tree | 4790814daa5ba8094bb05853336a87aa5d92ebd8 | |
parent | ac68f541fcc22d048420e85f5593a292fd223e1b (diff) |
os: port signal-dependent code to MinGWmingw-patches-for-1.13
Signed-off-by: Ryan Pavlik <rpavlik@iastate.edu>
Signed-off-by: Yaakov Selkowitz <yselkowitz@users.sourceforge.net>
-rw-r--r-- | os/osinit.c | 6 | ||||
-rw-r--r-- | os/utils.c | 65 |
2 files changed, 66 insertions, 5 deletions
diff --git a/os/osinit.c b/os/osinit.c index 005c6efbe..f92ca351b 100644 --- a/os/osinit.c +++ b/os/osinit.c @@ -154,6 +154,7 @@ OsInit(void) char fname[PATH_MAX]; if (!been_here) { +#if !defined(WIN32) || defined(__CYGWIN__) if (install_os_signal_handler) { struct sigaction act, oact; int i; @@ -212,6 +213,7 @@ OsInit(void) if (getpgrp() == 0) setpgid(0, 0); +#endif /* !_WIN32 || __CYGWIN__ */ #ifdef RLIMIT_DATA if (limitDataSpace >= 0) { @@ -252,7 +254,9 @@ OsInit(void) } } #endif +#if !defined(WIN32) || defined(__CYGWIN__) LockServer(); +#endif been_here = TRUE; } TimerInit(); @@ -270,6 +274,8 @@ void OsCleanup(Bool terminating) { if (terminating) { +#if !defined(WIN32) || defined(__CYGWIN__) UnlockServer(); +#endif } } diff --git a/os/utils.c b/os/utils.c index 7d81d6945..c5db08a18 100644 --- a/os/utils.c +++ b/os/utils.c @@ -62,13 +62,14 @@ OR PERFORMANCE OF THIS SOFTWARE. __stdcall unsigned long GetTickCount(void); #endif -#if defined(WIN32) && !defined(__CYGWIN__) -#include <X11/Xwinsock.h> -#endif #include <X11/Xos.h> #include <stdio.h> #include <time.h> -#if !defined(WIN32) || !defined(__MINGW32__) +#if defined(WIN32) && !defined(__CYGWIN__) +#define _WIN32_WINNT 0x0501 +#include <X11/Xwindows.h> +#include <ws2tcpip.h> +#else #include <sys/time.h> #include <sys/resource.h> #endif @@ -207,6 +208,12 @@ char *SeatId = NULL; sig_atomic_t inSignalContext = FALSE; +#ifdef __MINGW32__ +static HANDLE s_hSmartScheduleTimer = NULL; +static HANDLE s_hSmartScheduleTimerQueue = NULL; +static VOID CALLBACK SmartScheduleTimer(PVOID lpParameter, BOOLEAN TimerOrWaitFired); +#endif + #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED) #define HAS_SAVED_IDS_AND_SETEUID #endif @@ -214,6 +221,9 @@ sig_atomic_t inSignalContext = FALSE; OsSigHandlerPtr OsSignal(int sig, OsSigHandlerPtr handler) { +#if defined(WIN32) && !defined(__CYGWIN__) + return signal(sig, handler); +#else struct sigaction act, oact; sigemptyset(&act.sa_mask); @@ -224,6 +234,7 @@ OsSignal(int sig, OsSigHandlerPtr handler) if (sigaction(sig, &act, &oact)) perror("sigaction"); return oact.sa_handler; +#endif } /* @@ -237,6 +248,9 @@ OsSignal(int sig, OsSigHandlerPtr handler) #define LOCK_PREFIX "/.X" #define LOCK_SUFFIX "-lock" +#if defined(WIN32) && !defined(__CYGWIN__) +static Bool nolock = FALSE; +#else static Bool StillLocking = FALSE; static char LockFile[PATH_MAX]; Bool nolock = FALSE; @@ -321,7 +335,11 @@ LockServer(void) /* * Read the pid from the existing file */ +#ifdef O_NOFOLLOW lfd = open(LockFile, O_RDONLY | O_NOFOLLOW); +#else + lfd = open(LockFile, O_RDONLY); +#endif if (lfd < 0) { unlink(tmp); FatalError("Can't read lock file %s\n", LockFile); @@ -384,6 +402,7 @@ UnlockServer(void) (void) unlink(LockFile); } } +#endif /* Force connections to close on SIGHUP from init */ @@ -1111,6 +1130,12 @@ XNFstrdup(const char *s) void SmartScheduleStopTimer(void) { +#if defined(WIN32) && !defined(__CYGWIN__) + if (SmartScheduleDisable) + return; + DeleteTimerQueueTimer(s_hSmartScheduleTimerQueue, s_hSmartScheduleTimer, NULL); + s_hSmartScheduleTimer = NULL; +#else struct itimerval timer; if (SmartScheduleDisable) @@ -1120,11 +1145,24 @@ SmartScheduleStopTimer(void) timer.it_value.tv_sec = 0; timer.it_value.tv_usec = 0; (void) setitimer(ITIMER_REAL, &timer, 0); +#endif } void SmartScheduleStartTimer(void) { +#if defined(WIN32) && !defined(__CYGWIN__) + if (SmartScheduleDisable) + return; + if (!CreateTimerQueueTimer(&s_hSmartScheduleTimer, s_hSmartScheduleTimerQueue, SmartScheduleTimer, NULL, + SmartScheduleInterval, SmartScheduleInterval, WT_EXECUTEINPERSISTENTTHREAD)) + { + ErrorF("SmartScheduleStartTimer - CreateTimerQueueTimer() failed, smart scheduling disabled: %08x\n", (unsigned int)GetLastError()); + CloseHandle(s_hSmartScheduleTimer); + SmartScheduleDisable = TRUE; + return; + } +#else struct itimerval timer; if (SmartScheduleDisable) @@ -1134,10 +1172,16 @@ SmartScheduleStartTimer(void) timer.it_value.tv_sec = 0; timer.it_value.tv_usec = SmartScheduleInterval * 1000; setitimer(ITIMER_REAL, &timer, 0); +#endif } +#if defined(WIN32) && !defined(__CYGWIN__) +static VOID CALLBACK +SmartScheduleTimer(PVOID lpParameter, BOOLEAN TimerOrWaitFired) +#else static void SmartScheduleTimer(int sig) +#endif { SmartScheduleTime += SmartScheduleInterval; } @@ -1145,6 +1189,16 @@ SmartScheduleTimer(int sig) void SmartScheduleInit(void) { +#if defined(WIN32) && !defined(__CYGWIN__) + if (SmartScheduleDisable) + return; + s_hSmartScheduleTimerQueue = CreateTimerQueue(); + if (!s_hSmartScheduleTimerQueue) + { + ErrorF("SmartScheduleInit - CreateTimerQueue() failed, smart scheduling disabled: %08x\n", (unsigned int)GetLastError()); + SmartScheduleDisable = TRUE; + } +#else struct sigaction act; if (SmartScheduleDisable) @@ -1160,6 +1214,7 @@ SmartScheduleInit(void) perror("sigaction for smart scheduler"); SmartScheduleDisable = TRUE; } +#endif } #ifdef SIG_BLOCK @@ -1216,9 +1271,9 @@ OsBlockSIGIO(void) ret = sigismember(&PreviousSigIOMask, SIGIO); return ret; } else - return 1; #endif #endif + return 1; } void |