trace: Adapt trace file name for Haiku
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'
--- configure | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
configure +5 -1
@@ -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
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]>Signed-off-by Andreas Färber <[email protected]>--- configure | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)configure +5
-2@@ -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
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.
--- configure | 2 +- simpletrace.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
configure +1 -1
@@ -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
@@ -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
PATCH v2 1/1 trace: Adapt trace file name for Haiku
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.
---
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Blue Swirl
AppliedRe: [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 withpid_ttherefore results in a warning.Unfortunately POSIX:2008 does not define a PRId* string for
pid_t.In some places
pid_twas 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_twith %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]>Signed-off-by Andreas Färber <[email protected]>---
v2: Use %ld and long instead of %lu for Haiku forx86_64compatibility.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@@ -3037,7 +3037,7 @@ if test "$trace_backend" = "simple"; thenfi
# 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_makos-posix.c +1
-1@@ -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@@ -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@@ -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@@ -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