Skip to contentSkip to conversation

trace: Adapt trace file name for Haiku

PATCH Superseded Andreas Färber 4 participants 6 messages Oct 9, 2010 – Jun 15, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace: Adapt trace file name for Haiku

Resolves the following warning:

CC simpletrace.o
/Data/QEMU/qemu/simpletrace.c: In function 'st_set_trace_file':
/Data/QEMU/qemu/simpletrace.c:77: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'pid_t'

Cc Stefan Hajnoczi <[email protected]>
Cc Blue Swirl <[email protected]>
---
 configure |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
configure +5 -1
index d303061..3e694a2 100755
@@ -2609,7 +2609,11 @@ if test "$trace_backend" = "simple"; then
 fi
 # Set the appropriate trace file.
 if test "$trace_backend" = "simple"; then
-  trace_file="\"$trace_file-%u\""
+  if test "$haiku" = "yes"; then
+    trace_file="\"$trace_file-%lu\""
+  else
+    trace_file="\"$trace_file-%u\""
+  fi
 fi
 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 
Signature · 1 line
1.7.3
#1 lore raw
Quoted 32 lines · Andreas Färber

Resolves the following warning:

CC simpletrace.o
/Data/QEMU/qemu/simpletrace.c: In function 'st_set_trace_file':
/Data/QEMU/qemu/simpletrace.c:77: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'pid_t'

Cc Stefan Hajnoczi <[email protected]>
Cc Blue Swirl <[email protected]>
---
 configure |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
configure +5 -2
index d303061..3e694a2 100755
@@ -2609,7 +2609,11 @@ if test "$trace_backend" = "simple"; then
 fi
 # Set the appropriate trace file.
 if test "$trace_backend" = "simple"; then
-  trace_file="\"$trace_file-%u\""
+  if test "$haiku" = "yes"; then
+    trace_file="\"$trace_file-%lu\""
+  else
+    trace_file="\"$trace_file-%u\""
+  fi
 fi
 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 
--
Quoted 1 line

1.7.3

Please don't apply. The patch doesn't work for 64 bit Haiku.

According to POSIX:

"blksize_t, pid_t, and ssize_t shall be signed integer types."

and

"... the widths of blksize_t, pid_t, size_t, ssize_t, and suseconds_t are no greater
than the width of type long"

So a safe and portable solution would be to use "%ld" and cast the pid_t to long.

CU, Ingo

#2 lore raw

PATCH v2 1/1 trace: Adapt trace file name for Haiku

Cast the getpid() return value and adapt the format string. Avoids the following warning:

CC simpletrace.o
/Data/QEMU/qemu/simpletrace.c: In function 'st_set_trace_file':
/Data/QEMU/qemu/simpletrace.c:77: warning: format '%u' expects type 'unsigned int', but argument 3 has type 'pid_t'

v2:
* Don't use %lu for getpid() on Haiku since on x86_64 it returns an int. Always cast to long (largest allowed pid_t type) and use %ld instead. Suggested by Ingo Weinhold.

Cc Stefan Hajnoczi <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Ingo Weinhold <[email protected]>
---
 configure     |    2 +-
 simpletrace.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
configure +1 -1
index d303061..457d98c 100755
@@ -2609,7 +2609,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-%ld\""
 fi
 echo "CONFIG_TRACE_FILE=$trace_file" >> $config_host_mak
 
simpletrace.c +1 -1
index f849e42..9ee5c3b 100644
@@ -74,7 +74,7 @@ bool st_set_trace_file(const char *file)
     free(trace_file_name);
 
     if (!file) {
-        if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, getpid()) < 0) {
+        if (asprintf(&trace_file_name, CONFIG_TRACE_FILE, (long)getpid()) < 0) {
             trace_file_name = NULL;
             return false;
         }
Signature · 1 line
1.7.3
#4 lore raw

PATCH v3 1/1 Introduce format string for pid_t

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 <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Ingo Weinhold <[email protected]>
Cc Gleb Natapov <[email protected]>

---
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(-)
configure +1 -1
index a318d37..0f2b6bf 100755
@@ -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
os-posix.c +1 -1
index 3204197..7dfb278 100644
@@ -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;
     }
os-win32.c +1 -1
index d6d54c6..b6652af 100644
@@ -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) {
osdep.h +6 -0
index 970d767..97d167a 100644
@@ -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);
 
vl.c +1 -1
index b362871..b7b98f0 100644
@@ -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;
     }
Signature · 1 line
1.7.5.2.317.g391b14
Applied
#5 lore raw

Re: [Qemu-devel] [PATCH v3] Introduce format string for pid_t

Thanks, applied.

Quoted 100 lines · Andreas Färber

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 <[email protected]>
Cc Blue Swirl <[email protected]>
Cc Ingo Weinhold <[email protected]>
Cc Gleb Natapov <[email protected]>

---
 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(-)
configure +0 -0
index a318d37..0f2b6bf 100755
@@ -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

os-posix.c +1 -1
index 3204197..7dfb278 100644
@@ -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;
     }
os-win32.c +1 -1
index d6d54c6..b6652af 100644
@@ -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) {
osdep.h +6 -0
index 970d767..97d167a 100644
@@ -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);
 
vl.c +1 -2
index b362871..b7b98f0 100644
@@ -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