You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Mladen Turk <mt...@mappingsoft.com> on 2001/10/16 20:25:46 UTC

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

-----Original Message-----
From: Mladen Turk [mailto:mladen.turk@mail.inet.hr]
Sent: Tuesday, October 16, 2001 8:13 PM
To: APR Dev List
Cc: William A. Rowe Jr.
Subject: [PATCH] win32/locks.c - Terminal Services on WIN2K

Sorry... pushed the wrong button :o)

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 "William A. Rowe, Jr." <wr...@rowe-clan.net>.
From: "Mladen Turk" <mt...@mappingsoft.com>
Sent: Tuesday, October 16, 2001 1:52 PM


> I forgot to send a small thing with the patch...
> That is the owner flag. With the latest lock patch I've done two things at
> once (I know... shoot me :).
> The first is the solving locks on WIN2K running terminal services, and the
> other is using TRUE for initialowner. The reason for that was that I
> couldn't use apr_lock for my win32/shmem proposal, because I have no way to
> determine if the mutex was allready created by me or other proccess.

The change of initial ownership appeared very problematic, and I'm not about
to do so without others' input [we currently do not grab that mutex on creation,
and I presume that behavior is consistent with other platforms.]  Your patch
changed the mutex to owned, yet you didn't unlock it immediately, which I see
as a problem.

As far as the owner flag, I don't care to have other parts of apr quite so 
intimately aware of the internals of other parts, it makes the entire codebase 
more fragile.

Bill



> Index: locks.h
> ===================================================================
> RCS file: /home/cvspublic/apr/include/arch/win32/locks.h,v
> retrieving revision 1.12
> diff -u -r1.12 locks.h
> --- locks.h 2001/06/06 18:11:34 1.12
> +++ locks.h 2001/10/16 19:36:27
> @@ -64,6 +64,7 @@
>      HANDLE mutex;
>      CRITICAL_SECTION section;
>      char *fname;
> +    int   owner;
>  };
> 
>  #endif  /* LOCKS_H */
> 
> 


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

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

> -----Original Message-----
> From: Mladen Turk [mailto:mturk@mappingsoft.com]
> Sent: Tuesday, October 16, 2001 8:26 PM
> To: Apache Dev
> Subject: FW: [PATCH] win32/locks.c - Terminal Services on WIN2K
>

I forgot to send a small thing with the patch...
That is the owner flag. With the latest lock patch I've done two things at
once (I know... shoot me :).
The first is the solving locks on WIN2K running terminal services, and the
other is using TRUE for initialowner. The reason for that was that I
couldn't use apr_lock for my win32/shmem proposal, because I have no way to
determine if the mutex was allready created by me or other proccess.

MT.


cvs server: Diffing .
Index: locks.h
===================================================================
RCS file: /home/cvspublic/apr/include/arch/win32/locks.h,v
retrieving revision 1.12
diff -u -r1.12 locks.h
--- locks.h	2001/06/06 18:11:34	1.12
+++ locks.h	2001/10/16 19:36:27
@@ -64,6 +64,7 @@
     HANDLE mutex;
     CRITICAL_SECTION section;
     char *fname;
+    int   owner;
 };

 #endif  /* LOCKS_H */