Make duplicate display check work with Terminal Services.

This commit is contained in:
Harold L Hunt II 2004-03-02 05:11:57 +00:00
parent 597e804296
commit 7a7cda621d
2 changed files with 28 additions and 20 deletions

View file

@ -80,6 +80,7 @@ void OsVendorVErrorF (const char *pszFormat, va_list va_args);
#endif
void winInitializeDefaultScreens (void);
static Bool winCheckDisplayNumber (void);
@ -207,7 +208,6 @@ AbortDDX (void)
void
OsVendorInit (void)
{
if (serverGeneration == 1 && !winCheckDisplayNumber ())
{
FatalError ("Duplicate invocation of Cygwin/X");
@ -515,6 +515,7 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
#endif
}
/*
* winCheckDisplayNumber - Check if another instance of Cygwin/X is
* already running on the same display number. If no one exists,
@ -526,29 +527,37 @@ InitOutput (ScreenInfo *screenInfo, int argc, char *argv[])
static Bool
winCheckDisplayNumber ()
{
int disp;
HANDLE mutex;
char name[MAX_PATH]; /* can be shorter */
int n;
int nDisp;
HANDLE mutex;
char name[MAX_PATH];
char * pszPrefix = '\0';
OSVERSIONINFO osvi = {0};
disp = atoi (display);
if (disp < 0 || disp > 65535)
/* Check display range */
nDisp = atoi (display);
if (nDisp < 0 || nDisp > 65535)
{
ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", disp);
ErrorF ("winCheckDisplayNumber - Bad display number: %d\n", nDisp);
return FALSE;
}
n = snprintf (name, sizeof(name), "Cygwin/X server mutex on disp. %d", disp);
if (n >= sizeof(name))
/* Set first character of mutex name to null */
name[0] = '\0';
/* Get operating system version information */
osvi.dwOSVersionInfoSize = sizeof (osvi);
GetVersionEx (&osvi);
/* Want a mutex shared among all terminals on NT > 4.0 */
if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT
&& osvi.dwMajorVersion >= 5)
{
ErrorF ("winCheckDisplayNumber - Mutex name overflows\n");
return FALSE;
}
else if (n < 0)
{
Error ("winCheckDisplayNumber");
return FALSE;
pszPrefix = "Global\\";
}
/* Setup Cygwin/X specific part of name */
sprintf (name, "%sCYGWINX_DISPLAY:%d", pszPrefix, nDisp);
/* Windows automatically releases the mutex when this process exits */
mutex = CreateMutex (NULL, FALSE, name);
if (!mutex)
@ -574,7 +583,7 @@ winCheckDisplayNumber ()
{
ErrorF ("winCheckDisplayNumber - "
"Cygwin/X is already running on display %d\n",
disp);
nDisp);
return FALSE;
}

View file

@ -50,10 +50,9 @@ Bool
winClipboardDetectUnicodeSupport (void)
{
Bool fReturn = FALSE;
OSVERSIONINFO osvi;
OSVERSIONINFO osvi = {0};
/* Get operating system version information */
ZeroMemory (&osvi, sizeof (osvi));
osvi.dwOSVersionInfoSize = sizeof (osvi);
GetVersionEx (&osvi);