All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] trace: Adapt trace file name for Haiku
@ 2010-10-09 19:55 Andreas Färber
  2010-10-09 21:18 ` [Qemu-devel] Re: [HaikuPorts-devs] " Ingo Weinhold
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Färber @ 2010-10-09 19:55 UTC (permalink / raw)
  To: qemu-devel
  Cc: haikuports-devs, Blue Swirl, Andreas Färber, Stefan Hajnoczi

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 <stefanha@linux.vnet.ibm.com>
Cc: Blue Swirl <blauwirbel@gmail.com>
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 configure |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)

diff --git a/configure b/configure
index d303061..3e694a2 100755
--- a/configure
+++ b/configure
@@ -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
 
-- 
1.7.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] Re: [HaikuPorts-devs] [PATCH] trace: Adapt trace file name for Haiku
  2010-10-09 19:55 [Qemu-devel] [PATCH] trace: Adapt trace file name for Haiku Andreas Färber
@ 2010-10-09 21:18 ` Ingo Weinhold
  2010-10-10 11:45   ` [Qemu-devel] [PATCH v2] " Andreas Färber
  0 siblings, 1 reply; 6+ messages in thread
From: Ingo Weinhold @ 2010-10-09 21:18 UTC (permalink / raw)
  To: HaikuPorts developers discussion list
  Cc: Blue Swirl, Andreas Färber, Stefan Hajnoczi, qemu-devel


On 2010-10-09 at 21:55:17 [+0200], Andreas Färber <andreas.faerber@web.de> wrote:
> 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 <stefanha@linux.vnet.ibm.com>
> Cc: Blue Swirl <blauwirbel@gmail.com>
> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
> ---
>  configure |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/configure b/configure
> index d303061..3e694a2 100755
> --- a/configure
> +++ b/configure
> @@ -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
>  
> --
> 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v2] trace: Adapt trace file name for Haiku
  2010-10-09 21:18 ` [Qemu-devel] Re: [HaikuPorts-devs] " Ingo Weinhold
@ 2010-10-10 11:45   ` Andreas Färber
  2010-10-11  9:23     ` Stefan Hajnoczi
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Färber @ 2010-10-10 11:45 UTC (permalink / raw)
  To: qemu-devel
  Cc: haikuports-devs, Blue Swirl, Andreas Färber, Ingo Weinhold,
	Stefan Hajnoczi

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 <stefanha@linux.vnet.ibm.com>
Cc: Blue Swirl <blauwirbel@gmail.com>
Cc: Ingo Weinhold <ingo_weinhold@gmx.de>
Signed-off-by: Andreas Färber <andreas.faerber@web.de>
---
 configure     |    2 +-
 simpletrace.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index d303061..457d98c 100755
--- a/configure
+++ b/configure
@@ -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
 
diff --git a/simpletrace.c b/simpletrace.c
index f849e42..9ee5c3b 100644
--- a/simpletrace.c
+++ b/simpletrace.c
@@ -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;
         }
-- 
1.7.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v2] trace: Adapt trace file name for Haiku
  2010-10-10 11:45   ` [Qemu-devel] [PATCH v2] " Andreas Färber
@ 2010-10-11  9:23     ` Stefan Hajnoczi
  2011-06-02 17:58       ` [Qemu-devel] [PATCH v3] Introduce format string for pid_t Andreas Färber
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Hajnoczi @ 2010-10-11  9:23 UTC (permalink / raw)
  To: Andreas Färber
  Cc: haikuports-devs, Blue Swirl, Ingo Weinhold, qemu-devel

Acked-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v3] Introduce format string for pid_t
  2010-10-11  9:23     ` Stefan Hajnoczi
@ 2011-06-02 17:58       ` Andreas Färber
  2011-06-15 20:26         ` Blue Swirl
  0 siblings, 1 reply; 6+ messages in thread
From: Andreas Färber @ 2011-06-02 17:58 UTC (permalink / raw)
  To: qemu-devel
  Cc: haikuports-devs, Gleb Natapov, Stefan Hajnoczi, Blue Swirl,
	Andreas Färber, Ingo Weinhold

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

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v3] Introduce format string for pid_t
  2011-06-02 17:58       ` [Qemu-devel] [PATCH v3] Introduce format string for pid_t Andreas Färber
@ 2011-06-15 20:26         ` Blue Swirl
  0 siblings, 0 replies; 6+ messages in thread
From: Blue Swirl @ 2011-06-15 20:26 UTC (permalink / raw)
  To: Andreas Färber
  Cc: Stefan Hajnoczi, haikuports-devs, Ingo Weinhold, qemu-devel,
	Gleb Natapov

Thanks, applied.

On Thu, Jun 2, 2011 at 8:58 PM, Andreas Färber <andreas.faerber@web.de> wrote:
> 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
>
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2011-06-15 20:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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       ` [Qemu-devel] [PATCH v3] Introduce format string for pid_t Andreas Färber
2011-06-15 20:26         ` Blue Swirl

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.