Introduce format string for pid_t
authorAndreas Färber <andreas.faerber@web.de>
Thu, 2 Jun 2011 17:58:06 +0000 (19:58 +0200)
committerBlue Swirl <blauwirbel@gmail.com>
Wed, 15 Jun 2011 19:58:48 +0000 (19:58 +0000)
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>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
configure
os-posix.c
os-win32.c
osdep.h
vl.c

index 4c4aa92..44c092a 100755 (executable)
--- a/configure
+++ b/configure
@@ -3041,7 +3041,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
index 3204197..7dfb278 100644 (file)
@@ -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;
     }
index d6d54c6..b6652af 100644 (file)
@@ -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 6eb9a49..a817017 100644 (file)
--- a/osdep.h
+++ b/osdep.h
@@ -128,6 +128,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 7b83c43..dbdec71 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -1197,7 +1197,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;
     }