From: "Andreas Färber" <andreas.faerber@web.de>
To: qemu-devel@nongnu.org
Cc: haikuports-devs@lists.ports.haiku-files.org,
"Gleb Natapov" <gleb@redhat.com>,
"Stefan Hajnoczi" <stefanha@gmail.com>,
"Blue Swirl" <blauwirbel@gmail.com>,
"Andreas Färber" <andreas.faerber@web.de>,
"Ingo Weinhold" <ingo_weinhold@gmx.de>
Subject: [Qemu-devel] [PATCH v3] Introduce format string for pid_t
Date: Thu, 2 Jun 2011 19:58:06 +0200 [thread overview]
Message-ID: <1307037486-8209-1-git-send-email-andreas.faerber@web.de> (raw)
In-Reply-To: <20101011092342.GA3752@stefan-thinkpad.transitives.com>
BeOS and Haiku on i386 use long for 32-bit types, including pid_t.
Using %d with pid_t therefore results in a warning.
Unfortunately POSIX:2008 does not define a PRId* string for pid_t.
In some places pid_t was previously casted to long and %ld hardcoded.
The predecessor of this patch added another upcast for the simpletrace
filename but was not applied to date.
Since new uses of pid_t with %d keep creeping in, let's instead define
an OS-dependent format string and use that consistently.
Cc: Stefan Hajnoczi <stefanha@gmail.com>
Cc: Blue Swirl <blauwirbel@gmail.com>
Cc: Ingo Weinhold <ingo_weinhold@gmx.de>
Cc: Gleb Natapov <gleb@redhat.com>
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
v2: Use %ld and long instead of %lu for Haiku for x86_64 compatibility.
configure | 2 +-
os-posix.c | 2 +-
os-win32.c | 2 +-
osdep.h | 6 ++++++
vl.c | 2 +-
5 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/configure b/configure
index a318d37..0f2b6bf 100755
--- a/configure
+++ b/configure
@@ -3037,7 +3037,7 @@ if test "$trace_backend" = "simple"; then
fi
# Set the appropriate trace file.
if test "$trace_backend" = "simple"; then
- trace_file="\"$trace_file-%u\""
+ trace_file="\"$trace_file-\" FMT_pid"
fi
if test "$trace_backend" = "dtrace" -a "$trace_backend_stap" = "yes" ; then
echo "CONFIG_SYSTEMTAP_TRACE=y" >> $config_host_mak
diff --git a/os-posix.c b/os-posix.c
index 3204197..7dfb278 100644
--- a/os-posix.c
+++ b/os-posix.c
@@ -368,7 +368,7 @@ int qemu_create_pidfile(const char *filename)
if (lockf(fd, F_TLOCK, 0) == -1) {
return -1;
}
- len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
+ len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
if (write(fd, buffer, len) != len) {
return -1;
}
diff --git a/os-win32.c b/os-win32.c
index d6d54c6..b6652af 100644
--- a/os-win32.c
+++ b/os-win32.c
@@ -258,7 +258,7 @@ int qemu_create_pidfile(const char *filename)
if (file == INVALID_HANDLE_VALUE) {
return -1;
}
- len = snprintf(buffer, sizeof(buffer), "%ld\n", (long)getpid());
+ len = snprintf(buffer, sizeof(buffer), FMT_pid "\n", getpid());
ret = WriteFileEx(file, (LPCVOID)buffer, (DWORD)len,
&overlap, NULL);
if (ret == 0) {
diff --git a/osdep.h b/osdep.h
index 970d767..97d167a 100644
--- a/osdep.h
+++ b/osdep.h
@@ -127,6 +127,12 @@ void qemu_vfree(void *ptr);
int qemu_madvise(void *addr, size_t len, int advice);
+#if defined(__HAIKU__) && defined(__i386__)
+#define FMT_pid "%ld"
+#else
+#define FMT_pid "%d"
+#endif
+
int qemu_create_pidfile(const char *filename);
int qemu_get_thread_id(void);
diff --git a/vl.c b/vl.c
index b362871..b7b98f0 100644
--- a/vl.c
+++ b/vl.c
@@ -1191,7 +1191,7 @@ void qemu_kill_report(void)
*/
fputc('\n', stderr);
} else {
- fprintf(stderr, " from pid %d\n", shutdown_pid);
+ fprintf(stderr, " from pid " FMT_pid "\n", shutdown_pid);
}
shutdown_signal = -1;
}
--
1.7.5.2.317.g391b14
next prev parent reply other threads:[~2011-06-02 17:58 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-09 19:55 [Qemu-devel] [PATCH] trace: Adapt trace file name for Haiku Andreas Färber
2010-10-09 21:18 ` [Qemu-devel] Re: [HaikuPorts-devs] " Ingo Weinhold
2010-10-10 11:45 ` [Qemu-devel] [PATCH v2] " Andreas Färber
2010-10-11 9:23 ` Stefan Hajnoczi
2011-06-02 17:58 ` Andreas Färber [this message]
2011-06-15 20:26 ` [Qemu-devel] [PATCH v3] Introduce format string for pid_t Blue Swirl
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=1307037486-8209-1-git-send-email-andreas.faerber@web.de \
--to=andreas.faerber@web.de \
--cc=blauwirbel@gmail.com \
--cc=gleb@redhat.com \
--cc=haikuports-devs@lists.ports.haiku-files.org \
--cc=ingo_weinhold@gmx.de \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@gmail.com \
/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).