You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Mladen Turk <ml...@mail.inet.hr> on 2001/10/16 20:13:11 UTC

[PATCH] win32/locks.c - Terminal Services on WIN2K

Hi,

Here is the patch that deals with the strange things that took me almost a
week to solve.
I've build a service that created a lock an everything worked fine until I
run it using terminal services on WIN2K, (thanks to MSDN here is the
solution).
Don't see any reason why someone would use 'Local' namespace, (at least the
additional enum to apr_lock_create type param).

MT.


Index: locks.c
===================================================================
RCS file: /home/cvspublic/apr/locks/win32/locks.c,v
retrieving revision 1.45
diff -u -r1.45 locks.c
--- locks.c	2001/07/19 00:11:57	1.45
+++ locks.c	2001/10/16 17:41:11
@@ -58,6 +58,7 @@
 #include "apr_strings.h"
 #include "win32/locks.h"
 #include "apr_portable.h"
+#include "misc.h"

 static apr_status_t lock_cleanup(void *lock_)
 {
@@ -100,7 +101,6 @@
     /* ToDo:  How to handle the case when no pool is available?
     *         How to cleanup the storage properly?
     */
-    newlock->fname = apr_pstrdup(pool, fname);
     newlock->type = type;
     newlock->scope = scope;
     sec.nLength = sizeof(SECURITY_ATTRIBUTES);
@@ -114,9 +114,20 @@
     }

     if (scope == APR_INTRAPROCESS) {
+        newlock->fname = apr_pstrdup(pool, fname);
         InitializeCriticalSection(&newlock->section);
     } else {
-        newlock->mutex = CreateMutex(&sec, FALSE, fname);
+        apr_oslevel_e os_level;
+        if (!apr_get_oslevel(pool, &os_level) && os_level >= APR_WIN_2000)
+            newlock->fname = apr_pstrcat(pool, "Global\\", fname, NULL);
+        else
+            newlock->fname = apr_pstrdup(pool, fname);
+
+        newlock->mutex = CreateMutex(&sec, TRUE, newlock->fname);
+        if (GetLastError() == ERROR_ALREADY_EXISTS)
+            newlock->owner = 0;
+        else
+            newlock->owner = 1;
     }
     *lock = newlock;
     apr_pool_cleanup_register(newlock->pool, newlock, lock_cleanup,


RE: [PATCH] win32/locks.c - Terminal Services on WIN2K

Posted by Mladen Turk <mt...@mappingsoft.com>.

> -----Original Message-----
> Mladen, we try to cite KB article numbers on items like this.  Do
> you have a
> reference for the comments???
>

>From MSDN April 2001.
Platform SDK: DLL, Processes, and Threads
CreateMutex
	The CreateMutex function creates or opens a named or unnamed mutex object.
...

Terminal Services: The name can have a "Global\" or "Local\" prefix to
explicitly create the object in the global or session name space. The
remainder of the name can contain any character except the backslash
character (\). For more information, see Kernel Object Name Spaces.

Windows 2000 or later: If Terminal Services is not running, the "Global\"
and "Local\" prefixes are ignored. The remainder of the name can contain any
character except the backslash character.

Windows NT 4.0 and earlier: The name can contain any character except the
backslash character.

Windows 95/98/Me: The name can contain any character except the backslash
character. The empty string ("") is a valid object name.


MT.


Re: [PATCH] win32/locks.c - Terminal Services on WIN2K

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
From: "Mladen Turk" <ml...@mail.inet.hr>
Sent: Tuesday, October 16, 2001 1:13 PM


> Hi,
> 
> Here is the patch that deals with the strange things that took me almost a
> week to solve.
> I've build a service that created a lock an everything worked fine until I
> run it using terminal services on WIN2K, (thanks to MSDN here is the
> solution).
> Don't see any reason why someone would use 'Local' namespace, (at least the
> additional enum to apr_lock_create type param).

Mladen, we try to cite KB article numbers on items like this.  Do you have a
reference for the comments???