From patchwork Tue Oct 26 08:39:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jes Sorensen X-Patchwork-Id: 69193 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 14D84B70A5 for ; Tue, 26 Oct 2010 19:53:23 +1100 (EST) Received: from localhost ([127.0.0.1]:40471 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAfEM-0002jc-5Y for incoming@patchwork.ozlabs.org; Tue, 26 Oct 2010 04:50:06 -0400 Received: from [140.186.70.92] (port=39563 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PAf4N-00082F-Lu for qemu-devel@nongnu.org; Tue, 26 Oct 2010 04:39:49 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PAf4I-0004ww-0U for qemu-devel@nongnu.org; Tue, 26 Oct 2010 04:39:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44920) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PAf4H-0004wl-QX for qemu-devel@nongnu.org; Tue, 26 Oct 2010 04:39:41 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o9Q8ddWR011172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 26 Oct 2010 04:39:39 -0400 Received: from red-feather.redhat.com (ovpn-113-122.phx2.redhat.com [10.3.113.122]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o9Q8dS9X009703; Tue, 26 Oct 2010 04:39:38 -0400 From: Jes.Sorensen@redhat.com To: qemu-devel@nongnu.org Date: Tue, 26 Oct 2010 10:39:25 +0200 Message-Id: <1288082367-27944-8-git-send-email-Jes.Sorensen@redhat.com> In-Reply-To: <1288082367-27944-1-git-send-email-Jes.Sorensen@redhat.com> References: <1288082367-27944-1-git-send-email-Jes.Sorensen@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: blauwirbel@gmail.com Subject: [Qemu-devel] [PATCH 7/9] Separate qemu_pidfile() into OS specific versions 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: Jes Sorensen Signed-off-by: Jes Sorensen --- os-posix.c | 21 +++++++++++++++++++++ os-win32.c | 24 ++++++++++++++++++++++++ osdep.c | 38 -------------------------------------- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/os-posix.c b/os-posix.c index 612b641..38c29d1 100644 --- a/os-posix.c +++ b/os-posix.c @@ -361,3 +361,24 @@ int qemu_eventfd(int fds[2]) return qemu_pipe(fds); } + +int qemu_create_pidfile(const char *filename) +{ + char buffer[128]; + int len; + int fd; + + fd = qemu_open(filename, O_RDWR | O_CREAT, 0600); + if (fd == -1) { + return -1; + } + if (lockf(fd, F_TLOCK, 0) == -1) { + return -1; + } + len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid()); + if (write(fd, buffer, len) != len) { + return -1; + } + + return 0; +} diff --git a/os-win32.c b/os-win32.c index 3c6f50f..566d5e9 100644 --- a/os-win32.c +++ b/os-win32.c @@ -240,3 +240,27 @@ void os_pidfile_error(void) { fprintf(stderr, "Could not acquire pid file: %s\n", strerror(errno)); } + +int qemu_create_pidfile(const char *filename) +{ + char buffer[128]; + int len; + HANDLE file; + OVERLAPPED overlap; + BOOL ret; + memset(&overlap, 0, sizeof(overlap)); + + file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, + OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + + if (file == INVALID_HANDLE_VALUE) { + return -1; + } + len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid()); + ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len, + &overlap, NULL); + if (ret == 0) { + return -1; + } + return 0; +} diff --git a/osdep.c b/osdep.c index b1664ac..0d48561 100644 --- a/osdep.c +++ b/osdep.c @@ -73,44 +73,6 @@ int qemu_madvise(void *addr, size_t len, int advice) #endif } -int qemu_create_pidfile(const char *filename) -{ - char buffer[128]; - int len; -#ifndef _WIN32 - int fd; - - fd = qemu_open(filename, O_RDWR | O_CREAT, 0600); - if (fd == -1) - return -1; - - if (lockf(fd, F_TLOCK, 0) == -1) - return -1; - - len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid()); - if (write(fd, buffer, len) != len) - return -1; -#else - HANDLE file; - OVERLAPPED overlap; - BOOL ret; - memset(&overlap, 0, sizeof(overlap)); - - file = CreateFile(filename, GENERIC_WRITE, FILE_SHARE_READ, NULL, - OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - - if (file == INVALID_HANDLE_VALUE) - return -1; - - 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; -} - /* * Opens a file with FD_CLOEXEC set