From patchwork Thu Dec 3 13:56:03 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: riku.voipio@nokia.com X-Patchwork-Id: 40264 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CD1B0B7082 for ; Fri, 4 Dec 2009 09:21:30 +1100 (EST) Received: from localhost ([127.0.0.1]:48013 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGK3D-0003n4-SE for incoming@patchwork.ozlabs.org; Thu, 03 Dec 2009 17:21:27 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NGCB5-0001RU-6y for qemu-devel@nongnu.org; Thu, 03 Dec 2009 08:57:03 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NGCB0-0001Ny-FM for qemu-devel@nongnu.org; Thu, 03 Dec 2009 08:57:02 -0500 Received: from [199.232.76.173] (port=56420 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NGCAz-0001Nc-J3 for qemu-devel@nongnu.org; Thu, 03 Dec 2009 08:56:57 -0500 Received: from smtp.nokia.com ([192.100.122.230]:48077 helo=mgw-mx03.nokia.com) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NGCAy-0008Gc-V2 for qemu-devel@nongnu.org; Thu, 03 Dec 2009 08:56:57 -0500 Received: from esebh105.NOE.Nokia.com (esebh105.ntc.nokia.com [172.21.138.211]) by mgw-mx03.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id nB3DuoG2028026 for ; Thu, 3 Dec 2009 15:56:53 +0200 Received: from vaebh104.NOE.Nokia.com ([10.160.244.30]) by esebh105.NOE.Nokia.com with Microsoft SMTPSVC(6.0.3790.3959); Thu, 3 Dec 2009 15:56:42 +0200 Received: from mgw-da02.ext.nokia.com ([147.243.128.26]) by vaebh104.NOE.Nokia.com over TLS secured channel with Microsoft SMTPSVC(6.0.3790.3959); Thu, 3 Dec 2009 15:56:41 +0200 Received: from localhost.localdomain (esdhcp041213.research.nokia.com [172.21.41.213]) by mgw-da02.ext.nokia.com (Switch-3.3.3/Switch-3.3.3) with ESMTP id nB3DuZp5027643; Thu, 3 Dec 2009 15:56:38 +0200 From: riku.voipio@nokia.com To: qemu-devel@nongnu.org Date: Thu, 3 Dec 2009 15:56:03 +0200 Message-Id: <0f1be4f3b16009de424be7eb7f3d6d39acacc860.1259836046.git.riku.voipio@nokia.com> X-Mailer: git-send-email 1.6.3.3 In-Reply-To: References: In-Reply-To: References: MIME-Version: 1.0 X-OriginalArrivalTime: 03 Dec 2009 13:56:41.0406 (UTC) FILETIME=[70D1E5E0:01CA7420] X-Nokia-AV: Clean X-MIME-Autoconverted: from 8bit to quoted-printable by mgw-mx03.nokia.com id nB3DuoG2028026 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) X-Mailman-Approved-At: Thu, 03 Dec 2009 17:06:22 -0500 Cc: Riku Voipio , =?utf-8?q?Juha=20Riihim=C3=A4ki?= Subject: [Qemu-devel] [PATCH 2/7] fix pidfile option to work in WIN32 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Juha Riihimäki Excplicit read/write locking pidfile under WIN32 is bit extreme nobody get the chance to read the pidfile. Convert to a write-only lock. Also, creating pidfile was disabled along with daemonize under WIN32. Enable it, but do not enable daemon support which doesn't exist under WIN32 atm. From: Juha Riihimäki Signed-off-by: Juha Riihimäki Signed-off-by: Riku Voipio --- osdep.c | 13 ++----------- vl.c | 4 +++- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/osdep.c b/osdep.c index fd8bbd7..2ecffab 100644 --- a/osdep.c +++ b/osdep.c @@ -133,25 +133,16 @@ int qemu_create_pidfile(const char *filename) return -1; #else HANDLE file; - DWORD flags; OVERLAPPED overlap; BOOL ret; + memset(&overlap, 0, sizeof(overlap)); - /* Open for writing with no sharing. */ - file = CreateFile(filename, GENERIC_WRITE, 0, NULL, + file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, 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); diff --git a/vl.c b/vl.c index 44763af..11f6ad0 100644 --- a/vl.c +++ b/vl.c @@ -5471,16 +5471,18 @@ int main(int argc, char **argv, char **envp) signal(SIGTTOU, SIG_IGN); signal(SIGTTIN, SIG_IGN); } +#endif if (pid_file && qemu_create_pidfile(pid_file) != 0) { +#ifndef _WIN32 if (daemonize) { uint8_t status = 1; write(fds[1], &status, 1); } else +#endif fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno)); exit(1); } -#endif if (kvm_enabled()) { int ret;