diff options
Diffstat (limited to 'xorg-server/os/utils.c')
-rw-r--r-- | xorg-server/os/utils.c | 49 |
1 files changed, 34 insertions, 15 deletions
diff --git a/xorg-server/os/utils.c b/xorg-server/os/utils.c index 7f556a912..a55ecf8f0 100644 --- a/xorg-server/os/utils.c +++ b/xorg-server/os/utils.c @@ -122,6 +122,10 @@ __stdcall unsigned long GetTickCount(void); #include "picture.h"
+#ifdef _MSC_VER
+#define strdup _strdup
+#endif
+
Bool noTestExtensions;
#ifdef COMPOSITE
Bool noCompositeExtension = FALSE;
@@ -210,6 +214,9 @@ static char *dev_tty_from_init = NULL; /* since we need to parse it anyway */ OsSigHandlerPtr
OsSignal(int sig, OsSigHandlerPtr handler)
{
+#ifdef X_NOT_POSIX
+ return signal(sig, handler);
+#else
struct sigaction act, oact;
sigemptyset(&act.sa_mask);
@@ -220,6 +227,7 @@ OsSignal(int sig, OsSigHandlerPtr handler) if (sigaction(sig, &act, &oact))
perror("sigaction");
return oact.sa_handler;
+#endif
}
/*
@@ -245,7 +253,7 @@ OsSignal(int sig, OsSigHandlerPtr handler) #endif
static Bool StillLocking = FALSE;
-static char LockFile[PATH_MAX];
+static char szLockFile[PATH_MAX];
static Bool nolock = FALSE;
/*
@@ -257,26 +265,34 @@ static Bool nolock = FALSE; void
LockServer(void)
{
+#if defined(WIN32) && !defined(__CYGWIN__)
+ char MutexName[100];
+ sprintf(MutexName, "Global\\VcXsrv_Mutex_%d\n", getpid());
+ if (!CreateMutex(NULL,TRUE,MutexName) || GetLastError()== ERROR_ALREADY_EXISTS)
+ {
+ FatalError("Server is already active for display %d\n", atoi(display));
+ }
+#else
+ char port[20];
char tmp[PATH_MAX], pid_str[12];
int lfd, i, haslock, l_pid, t;
char *tmppath = NULL;
int len;
- char port[20];
if (nolock) return;
/*
* Path names
*/
tmppath = LOCK_DIR;
-
sprintf(port, "%d", atoi(display));
+
len = strlen(LOCK_PREFIX) > strlen(LOCK_TMP_PREFIX) ? strlen(LOCK_PREFIX) :
strlen(LOCK_TMP_PREFIX);
len += strlen(tmppath) + strlen(port) + strlen(LOCK_SUFFIX) + 1;
- if (len > sizeof(LockFile))
+ if (len > sizeof(szLockFile))
FatalError("Display name `%s' is too long\n", port);
(void)sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, port);
- (void)sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port);
+ (void)sprintf(szLockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, port);
/*
* Create a temporary file containing our PID. Attempt three times
@@ -318,7 +334,7 @@ LockServer(void) i = 0;
haslock = 0;
while ((!haslock) && (i++ < 3)) {
- haslock = (link(tmp,LockFile) == 0);
+ haslock = (link(tmp,szLockFile) == 0);
if (haslock) {
/*
* We're done.
@@ -329,17 +345,17 @@ LockServer(void) /*
* Read the pid from the existing file
*/
- lfd = open(LockFile, O_RDONLY);
+ lfd = open(szLockFile, O_RDONLY);
if (lfd < 0) {
unlink(tmp);
- FatalError("Can't read lock file %s\n", LockFile);
+ FatalError("Can't read lock file %s\n", szLockFile);
}
pid_str[0] = '\0';
if (read(lfd, pid_str, 11) != 11) {
/*
* Bogus lock file.
*/
- unlink(LockFile);
+ unlink(szLockFile);
close(lfd);
continue;
}
@@ -356,7 +372,7 @@ LockServer(void) /*
* Stale lock file.
*/
- unlink(LockFile);
+ unlink(szLockFile);
continue;
}
else if (((t < 0) && (errno == EPERM)) || (t == 0)) {
@@ -366,14 +382,15 @@ LockServer(void) unlink(tmp);
FatalError("Server is already active for display %s\n%s %s\n%s\n",
port, "\tIf this server is no longer running, remove",
- LockFile, "\tand start again.");
+ szLockFile, "\tand start again.");
}
}
}
unlink(tmp);
if (!haslock)
- FatalError("Could not create server lock file: %s\n", LockFile);
+ FatalError("Could not create server lock file: %s\n", szLockFile);
StillLocking = FALSE;
+#endif
}
/*
@@ -387,7 +404,7 @@ UnlockServer(void) if (!StillLocking){
- (void) unlink(LockFile);
+ (void) unlink(szLockFile);
}
}
@@ -1120,7 +1137,7 @@ XNFstrdup(const char *s) }
-#ifdef SIGVTALRM
+#if defined(SIGVTALRM) && !defined(__CYGWIN__)
#define SMART_SCHEDULE_POSSIBLE
#endif
@@ -1572,6 +1589,7 @@ Fclose(pointer iop) */
/* Consider LD* variables insecure? */
+#ifndef _MSC_VER
#ifndef REMOVE_ENV_LD
#define REMOVE_ENV_LD 1
#endif
@@ -1580,6 +1598,7 @@ Fclose(pointer iop) #ifndef REMOVE_LONG_ENV
#define REMOVE_LONG_ENV 1
#endif
+#endif
/*
* Disallow stdout or stderr as pipes? It's possible to block the X server
@@ -1610,7 +1629,7 @@ Fclose(pointer iop) #endif
#define MAX_ARG_LENGTH 128
-#define MAX_ENV_LENGTH 256
+#define MAX_ENV_LENGTH 2048
#define MAX_ENV_PATH_LENGTH 2048 /* Limit for *PATH and TERMCAP */
#if USE_ISPRINT
|