From: Jes.Sorensen@redhat.com
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 7/9] Separate qemu_pidfile() into OS specific versions
Date: Fri, 15 Oct 2010 16:05:51 +0200 [thread overview]
Message-ID: <1287151553-16894-8-git-send-email-Jes.Sorensen@redhat.com> (raw)
In-Reply-To: <1287151553-16894-1-git-send-email-Jes.Sorensen@redhat.com>
From: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
---
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 4b6b246..702c9d9 100644
--- a/osdep.c
+++ b/osdep.c
@@ -88,44 +88,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
--
1.7.2.3
next prev parent reply other threads:[~2010-10-15 14:21 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-15 14:05 [Qemu-devel] [PATCH 0/9] Re-factor osdep code + macro and brace fixes Jes.Sorensen
2010-10-15 14:05 ` [Qemu-devel] [PATCH 1/9] Move QEMU OS dependant library functions to OS specific files Jes.Sorensen
2010-10-15 20:07 ` Blue Swirl
2010-10-15 14:05 ` [Qemu-devel] [PATCH 2/9] Move osdep socket code to os-{posix, win32}-lib.c Jes.Sorensen
2010-10-15 14:05 ` [Qemu-devel] [PATCH 3/9] qemu_pipe() is used only by POSIX code, so move to os-posix-lib.c Jes.Sorensen
2010-10-15 14:05 ` [Qemu-devel] [PATCH 4/9] We only support eventfd under POSIX, move qemu_eventfd() to os-posix.c Jes.Sorensen
2010-10-15 14:05 ` [Qemu-devel] [PATCH 5/9] Move qemu_gettimeofday() to OS specific files Jes.Sorensen
2010-10-15 16:39 ` [Qemu-devel] " Paolo Bonzini
2010-10-16 14:27 ` Jes Sorensen
2010-10-15 14:05 ` [Qemu-devel] [PATCH 6/9] Do not redefine reserved key-words TRUE/FALSE Jes.Sorensen
2010-10-15 14:05 ` Jes.Sorensen [this message]
2010-10-15 14:05 ` [Qemu-devel] [PATCH 8/9] Consolidate oom_check() functions Jes.Sorensen
2010-10-15 14:05 ` [Qemu-devel] [PATCH 9/9] Remove unncessary includes Jes.Sorensen
2010-10-15 16:41 ` [Qemu-devel] Re: [PATCH 0/9] Re-factor osdep code + macro and brace fixes Paolo Bonzini
-- strict thread matches above, loose matches on Subject: below --
2010-10-16 16:04 [Qemu-devel] [PATCH v2 " Jes.Sorensen
2010-10-16 16:04 ` [Qemu-devel] [PATCH 7/9] Separate qemu_pidfile() into OS specific versions Jes.Sorensen
2010-10-18 8:15 [Qemu-devel] [PATCH v3 0/9] Re-factor osdep code + macro and brace fixes Jes.Sorensen
2010-10-18 8:15 ` [Qemu-devel] [PATCH 7/9] Separate qemu_pidfile() into OS specific versions Jes.Sorensen
2010-10-26 8:39 [Qemu-devel] [PATCH v4 0/9] Re-factor osdep code + macro and brace fixes Jes.Sorensen
2010-10-26 8:39 ` [Qemu-devel] [PATCH 7/9] Separate qemu_pidfile() into OS specific versions Jes.Sorensen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1287151553-16894-8-git-send-email-Jes.Sorensen@redhat.com \
--to=jes.sorensen@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).