qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile).
@ 2007-03-23 23:10 Carlos O'Donell
  2007-03-25 17:58 ` Anthony Liguori
  2007-03-25 21:35 ` Thiemo Seufer
  0 siblings, 2 replies; 5+ messages in thread
From: Carlos O'Donell @ 2007-03-23 23:10 UTC (permalink / raw)
  To: qemu-devel


The following patch implements Win32 locking for vl.c (create_pidfile).
Builds for mingw32, and tested on a Windows Server 2003 host by running
two qemu's with the same -pidfile option.

When cross-compiling the use of --enable-mingw32 should effect AIOLIBS,
otherwise the build will use "-lrt" and this is not valid when compiling
with mingw32.

Patch attached for both. Built on linux and tested on Windows Server
2003.

Comments? Please include me in the CC.

Cheers,
Carlos.
-- 
Carlos O'Donell
CodeSourcery
carlos@codesourcery.com
(650) 331-3385 x716

2007-03-23  Carlos O'Donell  <carlos@codesourcery.com>

	* configure: Move determination of AIOLIBS until after
	all configure options have been handled.
	* vl.c (create_pidfile) [_WIN32]: Implement Win32 file
	locking for pid file.

Index: configure
===================================================================
RCS file: /sources/qemu/qemu/configure,v
retrieving revision 1.132
diff -u -p -r1.132 configure
--- configure	19 Mar 2007 12:22:40 -0000	1.132
+++ configure	23 Mar 2007 23:08:08 -0000
@@ -159,12 +159,6 @@ if [ "$bsd" = "yes" ] ; then
   fi
 fi
 
-if [ "$bsd" = "yes" -o "$darwin" = "yes" -o "$mingw32" = "yes" ] ; then
-    AIOLIBS=
-else
-    AIOLIBS="-lrt"
-fi
-
 # find source path
 source_path=`dirname "$0"`
 if [ -z "$source_path" ]; then
@@ -260,6 +254,12 @@ for opt do
   esac
 done
 
+if [ "$bsd" = "yes" -o "$darwin" = "yes" -o "$mingw32" = "yes" ] ; then
+    AIOLIBS=
+else
+    AIOLIBS="-lrt"
+fi
+
 # default flags for all hosts
 CFLAGS="$CFLAGS -Wall -O2 -g -fno-strict-aliasing"
 LDFLAGS="$LDFLAGS -g"
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.270
diff -u -p -r1.270 vl.c
--- vl.c	22 Mar 2007 12:36:53 -0000	1.270
+++ vl.c	23 Mar 2007 23:08:08 -0000
@@ -4397,24 +4397,48 @@ void usb_info(void)
 
 static int create_pidfile(const char *filename)
 {
-    int fd;
     char buffer[128];
     int len;
+#ifndef _WIN32
+    int fd;
 
     fd = open(filename, O_RDWR | O_CREAT, 0600);
     if (fd == -1)
         return -1;
 
-    /* XXX: No locking for Win32 implemented */
-#ifndef _WIN32
     if (lockf(fd, F_TLOCK, 0) == -1)
         return -1;
-#endif
 
     len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
     if (write(fd, buffer, len) != len)
         return -1;
+#else
+    HANDLE file;
+    DWORD flags;
+    OVERLAPPED overlap;
+    BOOL ret;
+
+    /* Open for writing with no sharing. */
+    file = CreateFile(filename, GENERIC_WRITE, 0, NULL, 
+		      OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
+
+    if (file == INVALID_HANDLE_VALUE)
+      return -1;
+
+    flags = LOCKFILE_EXCLUSIVE_LOCK | LOCKFILE_FAIL_IMMEDIATELY;
+    overlap.hEvent = 0;
+    /* Lock 1 byte. */
+    ret = LockFileEx(file, flags, 0, 0, 1, &overlap);
+    if (ret == 0)
+      return -1;
 
+    /* Write PID to file. */
+    len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
+    ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len, 
+		      &overlap, NULL);
+    if (ret == 0)
+      return -1;
+#endif
     return 0;
 }
 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile).
  2007-03-23 23:10 [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile) Carlos O'Donell
@ 2007-03-25 17:58 ` Anthony Liguori
  2007-03-25 21:35 ` Thiemo Seufer
  1 sibling, 0 replies; 5+ messages in thread
From: Anthony Liguori @ 2007-03-25 17:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: carlos

Carlos O'Donell wrote:
> The following patch implements Win32 locking for vl.c (create_pidfile).
> Builds for mingw32, and tested on a Windows Server 2003 host by running
> two qemu's with the same -pidfile option.
>
> When cross-compiling the use of --enable-mingw32 should effect AIOLIBS,
> otherwise the build will use "-lrt" and this is not valid when compiling
> with mingw32.
>   

Instead of using an #ifdef, I think it would be better to have a win32 
specific file and a unix specific file that compiles conditionally 
depending on the host.

Sort of like and osdep-posix.c and and osdep-win32.c.  Both would 
implement a create_pidfile() function.  I think this general approach 
would help clean up a lot of the win32 code.

Thoughts?

Regards,

Anthony Liguori

> Patch attached for both. Built on linux and tested on Windows Server
> 2003.
>
> Comments? Please include me in the CC.
>
> Cheers,
> Carlos.
>   

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile).
  2007-03-23 23:10 [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile) Carlos O'Donell
  2007-03-25 17:58 ` Anthony Liguori
@ 2007-03-25 21:35 ` Thiemo Seufer
  2007-03-25 23:30   ` Thiemo Seufer
  1 sibling, 1 reply; 5+ messages in thread
From: Thiemo Seufer @ 2007-03-25 21:35 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: qemu-devel

Carlos O'Donell wrote:
> 
> The following patch implements Win32 locking for vl.c (create_pidfile).
> Builds for mingw32, and tested on a Windows Server 2003 host by running
> two qemu's with the same -pidfile option.
> 
> When cross-compiling the use of --enable-mingw32 should effect AIOLIBS,
> otherwise the build will use "-lrt" and this is not valid when compiling
> with mingw32.
> 
> Patch attached for both. Built on linux and tested on Windows Server
> 2003.
> 
> Comments? Please include me in the CC.

I renamed it to qemu_create_pidfile and moved it to osdep.h. I hope
that has all necessary includes. Please test.


Thiemo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile).
  2007-03-25 21:35 ` Thiemo Seufer
@ 2007-03-25 23:30   ` Thiemo Seufer
  2007-03-27 13:22     ` Carlos O'Donell
  0 siblings, 1 reply; 5+ messages in thread
From: Thiemo Seufer @ 2007-03-25 23:30 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: qemu-devel

Thiemo Seufer wrote:
> Carlos O'Donell wrote:
> > 
> > The following patch implements Win32 locking for vl.c (create_pidfile).
> > Builds for mingw32, and tested on a Windows Server 2003 host by running
> > two qemu's with the same -pidfile option.
> > 
> > When cross-compiling the use of --enable-mingw32 should effect AIOLIBS,
> > otherwise the build will use "-lrt" and this is not valid when compiling
> > with mingw32.
> > 
> > Patch attached for both. Built on linux and tested on Windows Server
> > 2003.
> > 
> > Comments? Please include me in the CC.
> 
> I renamed it to qemu_create_pidfile and moved it to osdep.h. I hope
> that has all necessary includes. Please test.

osdep.c, that is, only a tiny bit was for osdep.h. :-)


Thiemo

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile).
  2007-03-25 23:30   ` Thiemo Seufer
@ 2007-03-27 13:22     ` Carlos O'Donell
  0 siblings, 0 replies; 5+ messages in thread
From: Carlos O'Donell @ 2007-03-27 13:22 UTC (permalink / raw)
  To: Thiemo Seufer; +Cc: qemu-devel

On Mon, Mar 26, 2007 at 12:30:13AM +0100, Thiemo Seufer wrote:
> > I renamed it to qemu_create_pidfile and moved it to osdep.h. I hope
> > that has all necessary includes. Please test.
> 
> osdep.c, that is, only a tiny bit was for osdep.h. :-)

Tested on Windows Server 2003, thanks for the quick response.

Cheers,
Carlos.
-- 
Carlos O'Donell
CodeSourcery
carlos@codesourcery.com
(650) 331-3385 x716

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-03-27 13:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-03-23 23:10 [Qemu-devel] [PATCH] Implement Win32 locking in vl.c (create_pidfile) Carlos O'Donell
2007-03-25 17:58 ` Anthony Liguori
2007-03-25 21:35 ` Thiemo Seufer
2007-03-25 23:30   ` Thiemo Seufer
2007-03-27 13:22     ` Carlos O'Donell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).