Skip to contentSkip to conversation

Build fixes for Haiku

PATCH In review Peter Maydell 5 participants 23 messages Jul 3, 2020 – Jul 11, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover Build fixes for Haiku

This patchset is essentially a resend of David Carlier's build fixes for the Haiku platform. I've taken David's patches and put them together into a set of emails threaded in the way our CI tools expect, as the easiest way to get the patchew robot to run the build tests so we can check they didn't accidentally break one of the BSDs. I've also put in the patch from Gerd that fixes the drm.c issue. I've also expanded on the commit messages for all the patches so that we have a record of why we made the changes if we need to look back at it in future.

Assuming no issues turn up, I'll arrange to get these into master at some point before the 5.1 release.

Thanks for reporting these problems and providing the fixes, David.

-- PMM

David CARLIER (8):
build: Enable BSD symbols for Haiku util/qemu-openpty.c: Don't assume pty.h is glibc-only
build: Check that mlockall() exists
osdep.h: Always include <sys/signal.h> if it exists osdep.h: For Haiku, define SIGIO as equivalent to SIGPOLL bswap.h: Include <endian.h> on Haiku for bswap operations util/compatfd.c: Only include <sys/syscall.h> if CONFIG_SIGNALFD util/oslib-posix.c: Implement qemu_init_exec_dir() for Haiku

Gerd Hoffmann (1):
util/drm: make portable by avoiding struct dirent d_type

 configure                   | 36 ++++++++++++++++++++++++++++++++++--
 include/qemu/bswap.h        |  2 ++
 include/qemu/osdep.h        |  6 +++++-
 hw/xen/xen-legacy-backend.c |  1 -
 os-posix.c                  |  4 ++++
 util/compatfd.c             |  2 ++
 util/drm.c                  | 19 ++++++++++++++-----
 util/oslib-posix.c          | 20 +++++++++++++++++++-
 util/qemu-openpty.c         |  2 +-
 9 files changed, 81 insertions(+), 11 deletions(-)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/9 build: Enable BSD symbols for Haiku

From: David CARLIER <[email protected]>

Tell Haiku to provide various BSD functions by setting BSD_SOURCE and linking libbsd.

[PMM: expanded commit message]
---
 configure | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
configure +2 -2
index 8a65240d4a8..c9c135b70bc 100755
@@ -903,8 +903,8 @@ SunOS)
 ;;
 Haiku)
   haiku="yes"
-  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS $QEMU_CFLAGS"
-  LIBS="-lposix_error_mapper -lnetwork $LIBS"
+  QEMU_CFLAGS="-DB_USE_POSITIVE_POSIX_ERRORS -DBSD_SOURCE $QEMU_CFLAGS"
+  LIBS="-lposix_error_mapper -lnetwork -lbsd $LIBS"
 ;;
 Linux)
   audio_drv_list="try-pa oss"
Signature · 1 line
2.20.1
#2 lore raw

PATCH v3 2/9 util/qemu-openpty.c: Don't assume pty.h is glibc-only

In reply to Peter Maydell

From: David CARLIER <[email protected]>

Instead of using an OS-specific ifdef test to select the "openpty() is in pty.h" codepath, make configure check for the existence of the header and use the new CONFIG_PTY instead.

This is necessary to build on Haiku, which also provides openpty() via pty.h.

[PMM: Expanded commit message]
---
 configure           | 9 +++++++++
 util/qemu-openpty.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)
configure +9 -0
index c9c135b70bc..5455ae10d05 100755
@@ -2386,6 +2386,12 @@ else
   l2tpv3=no
 fi
 
+if check_include "pty.h" ; then
+  pty_h=yes
+else
+  pty_h=no
+fi
+
 #########################################
 # vhost interdependencies and host support
 
@@ -7856,6 +7862,9 @@ fi
 if test "$sheepdog" = "yes" ; then
   echo "CONFIG_SHEEPDOG=y" >> $config_host_mak
 fi
+if test "$pty_h" = "yes" ; then
+  echo "CONFIG_PTY=y" >> $config_host_mak
+fi
 if test "$fuzzing" = "yes" ; then
   if test "$have_fuzzer" = "yes"; then
     FUZZ_LDFLAGS=" -fsanitize=address,fuzzer"
util/qemu-openpty.c +1 -1
index 2e8b43bdf57..9d8ad6905e0 100644
@@ -35,7 +35,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-#if defined(__GLIBC__)
+#if defined CONFIG_PTY
 # include <pty.h>
 #elif defined CONFIG_BSD
 # include <termios.h>
Signature · 1 line
2.20.1
#3 lore raw

Re: [PATCH v3 2/9] util/qemu-openpty.c: Don't assume pty.h is glibc-only

Quoted 17 lines · Peter Maydell

From: David CARLIER <[email protected]>

Instead of using an OS-specific ifdef test to select the "openpty() is in pty.h" codepath, make configure check for the existence of the header and use the new CONFIG_PTY instead.

This is necessary to build on Haiku, which also provides openpty() via pty.h.

[PMM: Expanded commit message]
---
 configure           | 9 +++++++++
 util/qemu-openpty.c | 2 +-
 2 files changed, 10 insertions(+), 1 deletion(-)

[...]

util/qemu-openpty.c line 38

Quoted 10 lines
util/qemu-openpty.c +1 -1
index 2e8b43bdf57..9d8ad6905e0 100644
@@ -35,7 +35,7 @@
 #include "qemu/osdep.h"
 #include "qemu-common.h"
 
-#if defined(__GLIBC__)
+#if defined CONFIG_PTY

Shouldn't there be some parentheses around CONFIG_PTY here?

Thomas

#4 lore raw

Re: [PATCH v3 2/9] util/qemu-openpty.c: Don't assume pty.h is glibc-only

Quoted 10 lines · Thomas Huth

util/qemu-openpty.c line 38

Quoted 7 lines

+++ b/util/qemu-openpty.c

util/qemu-openpty.c +1 -1
@@ -35,7 +35,7 @@
  #include "qemu/osdep.h"
  #include "qemu-common.h"
 
-#if defined(__GLIBC__)
+#if defined CONFIG_PTY

Shouldn't there be some parentheses around CONFIG_PTY here?

No, they are optional, and omitting them is more consistent with the CONFIG_BSD just below.

Quoted 2 lines

#elif defined CONFIG_BSD

 # include <termios.h>
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw

Re: [PATCH v3 2/9] util/qemu-openpty.c: Don't assume pty.h is glibc-only

Quoted 12 lines · Eric Blake
Quoted 9 lines · Thomas Huth

util/qemu-openpty.c line 38

Quoted 6 lines

+++ b/util/qemu-openpty.c

util/qemu-openpty.c +1 -0
@@ -35,7 +35,7 @@
   #include "qemu/osdep.h"
   #include "qemu-common.h"
   -#if defined(__GLIBC__)
+#if defined CONFIG_PTY

Shouldn't there be some parentheses around CONFIG_PTY here?

Quoted 2 lines

No, they are optional, and omitting them is more consistent with the CONFIG_BSD just below.

Thanks, TIL - I'm doing so many years of C programming already, and until now I never noticed any code that does not use parentheses after "defined" ...

Thomas

#6 lore raw

PATCH v3 3/9 build: Check that mlockall() exists

In reply to Peter Maydell

From: David CARLIER <[email protected]>

Instead of assuming that all POSIX platforms provide mlockall(), test for it in configure. If the host doesn't provide this platform then os_mlock() will fail -ENOSYS, as it does already on Windows.

This is necessary for Haiku, which does not have mlockall().

[PMM: Expanded commit message]
---
 configure  | 15 +++++++++++++++
 os-posix.c |  4 ++++
 2 files changed, 19 insertions(+)
configure +15 -0
index 5455ae10d05..ddc53d873ef 100755
@@ -2392,6 +2392,18 @@ else
   pty_h=no
 fi
 
+cat > $TMPC <<EOF
+#include <sys/mman.h>
+int main(int argc, char *argv[]) {
+    return mlockall(MCL_FUTURE);
+}
+EOF
+if compile_prog "" "" ; then
+  have_mlockall=yes
+else
+  have_mlockall=no
+fi
+
 #########################################
 # vhost interdependencies and host support
 
@@ -7865,6 +7877,9 @@ fi
 if test "$pty_h" = "yes" ; then
   echo "CONFIG_PTY=y" >> $config_host_mak
 fi
+if test "$have_mlockall" = "yes" ; then
+  echo "CONFIG_MLOCKALL=y" >> $config_host_mak
+fi
 if test "$fuzzing" = "yes" ; then
   if test "$have_fuzzer" = "yes"; then
     FUZZ_LDFLAGS=" -fsanitize=address,fuzzer"
os-posix.c +4 -0
index 3cd52e1e700..e02b566940c 100644
@@ -337,6 +337,7 @@ bool is_daemonized(void)
 
 int os_mlock(void)
 {
+#if defined CONFIG_MLOCKALL
     int ret = 0;
 
     ret = mlockall(MCL_CURRENT | MCL_FUTURE);
@@ -345,4 +346,7 @@ int os_mlock(void)
     }
 
     return ret;
+#else
+    return -ENOSYS;
+#endif
 }
Signature · 1 line
2.20.1
#7 lore raw

Re: [PATCH v3 3/9] build: Check that mlockall() exists

Quoted 16 lines · Peter Maydell

From: David CARLIER <[email protected]>

Instead of assuming that all POSIX platforms provide mlockall(), test for it in configure. If the host doesn't provide this platform then os_mlock() will fail -ENOSYS, as it does already on Windows.

This is necessary for Haiku, which does not have mlockall().

[PMM: Expanded commit message]
---
 configure  | 15 +++++++++++++++
 os-posix.c |  4 ++++
 2 files changed, 19 insertions(+)

[...]

os-posix.c bool is_daemonized(void) · line 340

Quoted 9 lines
os-posix.c +1 -0
index 3cd52e1e700..e02b566940c 100644
@@ -337,6 +337,7 @@ bool is_daemonized(void)
 
 int os_mlock(void)
 {
+#if defined CONFIG_MLOCKALL

Also missing the parentheses?

Thomas

#8 lore raw

PATCH v3 4/9 osdep.h: Always include <sys/signal.h> if it exists

In reply to Peter Maydell

From: David CARLIER <[email protected]>

Regularize our handling of <sys/signal.h>: currently we include it in osdep.h, but only for OpenBSD, and we include it without an ifdef guard in a couple of C files. This causes problems for Haiku, which doesn't have that header.

Instead, check in configure whether sys/signal.h exists, and if it does then always include it from osdep.h.

[PMM: Expanded commit message]
---
 configure                   | 8 ++++++++
 include/qemu/osdep.h        | 2 +-
 hw/xen/xen-legacy-backend.c | 1 -
 util/oslib-posix.c          | 1 -
 4 files changed, 9 insertions(+), 3 deletions(-)
configure +8 -0
index ddc53d873ef..d131f760d8f 100755
@@ -3212,6 +3212,11 @@ if ! check_include "ifaddrs.h" ; then
   have_ifaddrs_h=no
 fi
 
+have_sys_signal_h=no
+if check_include "sys/signal.h" ; then
+  have_sys_signal_h=yes
+fi
+
 ##########################################
 # VTE probe
 
@@ -7398,6 +7403,9 @@ fi
 if test "$have_broken_size_max" = "yes" ; then
     echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak
 fi
+if test "$have_sys_signal_h" = "yes" ; then
+    echo "CONFIG_SYS_SIGNAL=y" >> $config_host_mak
+fi
 
 # Work around a system header bug with some kernel/XFS header
 # versions where they both try to define 'struct fsxattr':
include/qemu/osdep.h +1 -1
index 0d26a1b9bd0..6e0cf9132d9 100644
@@ -104,7 +104,7 @@ extern int daemon(int, int);
 #include <setjmp.h>
 #include <signal.h>
 
-#ifdef __OpenBSD__
+#ifdef CONFIG_SYS_SIGNAL
 #include <sys/signal.h>
 #endif
 
hw/xen/xen-legacy-backend.c +0 -1
index 7d4b13351e0..965abe3ad34 100644
@@ -23,7 +23,6 @@
  */
 
 #include "qemu/osdep.h"
-#include <sys/signal.h>
 
 #include "hw/sysbus.h"
 #include "hw/boards.h"
util/oslib-posix.c +0 -1
index 39ddc77c85b..7ad9195c445 100644
@@ -38,7 +38,6 @@
 #include "qemu/sockets.h"
 #include "qemu/thread.h"
 #include <libgen.h>
-#include <sys/signal.h>
 #include "qemu/cutils.h"
 
 #ifdef CONFIG_LINUX
Signature · 1 line
2.20.1
Reviewed-by on v3 4/9
#9 lore raw

Re: [PATCH v3 4/9] osdep.h: Always include <sys/signal.h> if it exists

Quoted 38 lines · Peter Maydell

From: David CARLIER <[email protected]>

Regularize our handling of <sys/signal.h>: currently we include it in osdep.h, but only for OpenBSD, and we include it without an ifdef guard in a couple of C files. This causes problems for Haiku, which doesn't have that header.

Instead, check in configure whether sys/signal.h exists, and if it does then always include it from osdep.h.

[PMM: Expanded commit message]
---
 configure                   | 8 ++++++++
 include/qemu/osdep.h        | 2 +-
 hw/xen/xen-legacy-backend.c | 1 -
 util/oslib-posix.c          | 1 -
 4 files changed, 9 insertions(+), 3 deletions(-)
configure +5 -0
index ddc53d873ef..d131f760d8f 100755
@@ -3212,6 +3212,11 @@ if ! check_include "ifaddrs.h" ; then
   have_ifaddrs_h=no
 fi
 
+have_sys_signal_h=no
+if check_include "sys/signal.h" ; then
+  have_sys_signal_h=yes
+fi
+
 ##########################################
 # VTE probe
 

configure fi · line 7408

Quoted 6 lines
configure +3 -0
@@ -7398,6 +7403,9 @@ fi
 if test "$have_broken_size_max" = "yes" ; then
     echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak
 fi
+if test "$have_sys_signal_h" = "yes" ; then
+    echo "CONFIG_SYS_SIGNAL=y" >> $config_host_mak
+fi

I'd maybe rather name it HAVE_SYS_SIGNAL_H, but I guess that's just a matter of taste.

#10 lore raw

Re: [PATCH v3 4/9] osdep.h: Always include <sys/signal.h> if it exists

Quoted 38 lines · Thomas Huth
Quoted 37 lines · Peter Maydell

From: David CARLIER <[email protected]>

Regularize our handling of <sys/signal.h>: currently we include it in osdep.h, but only for OpenBSD, and we include it without an ifdef guard in a couple of C files. This causes problems for Haiku, which doesn't have that header.

Instead, check in configure whether sys/signal.h exists, and if it does then always include it from osdep.h.

[PMM: Expanded commit message]
---
 configure                   | 8 ++++++++
 include/qemu/osdep.h        | 2 +-
 hw/xen/xen-legacy-backend.c | 1 -
 util/oslib-posix.c          | 1 -
 4 files changed, 9 insertions(+), 3 deletions(-)
configure +5 -0
index ddc53d873ef..d131f760d8f 100755
@@ -3212,6 +3212,11 @@ if ! check_include "ifaddrs.h" ; then
   have_ifaddrs_h=no
 fi
 
+have_sys_signal_h=no
+if check_include "sys/signal.h" ; then
+  have_sys_signal_h=yes
+fi
+
 ##########################################
 # VTE probe
 
Quoted 10 lines

configure fi · line 7408

Quoted 7 lines
configure +3 -0
@@ -7398,6 +7403,9 @@ fi
 if test "$have_broken_size_max" = "yes" ; then
     echo "HAVE_BROKEN_SIZE_MAX=y" >> $config_host_mak
 fi
+if test "$have_sys_signal_h" = "yes" ; then
+    echo "CONFIG_SYS_SIGNAL=y" >> $config_host_mak
+fi

I'd maybe rather name it HAVE_SYS_SIGNAL_H, but I guess that's just a matter of taste.

Agreed, if possible.

Quoted 4 lines
#11 lore raw

PATCH v3 5/9 osdep.h: For Haiku, define SIGIO as equivalent to SIGPOLL

In reply to Peter Maydell

From: David CARLIER <[email protected]>

Haiku doesn't provide SIGIO; fix this up in osdep.h by defining it as equal to SIGPOLL.

[PMM: Expanded commit message]
---
 include/qemu/osdep.h | 4 ++++
 1 file changed, 4 insertions(+)
include/qemu/osdep.h +4 -0
index 6e0cf9132d9..e090ead8262 100644
@@ -425,6 +425,10 @@ void qemu_anon_ram_free(void *ptr, size_t size);
 #define HAVE_CHARDEV_PARPORT 1
 #endif
 
+#if defined(__HAIKU__)
+#define SIGIO SIGPOLL
+#endif
+
 #if defined(CONFIG_LINUX)
 #ifndef BUS_MCEERR_AR
 #define BUS_MCEERR_AR 4
Signature · 1 line
2.20.1
Reviewed-by on v3 5/9
#12 lore raw

Re: [PATCH v3 5/9] osdep.h: For Haiku, define SIGIO as equivalent to SIGPOLL

Quoted 18 lines · Peter Maydell

From: David CARLIER <[email protected]>

Haiku doesn't provide SIGIO; fix this up in osdep.h by defining it as equal to SIGPOLL.

[PMM: Expanded commit message]
---
 include/qemu/osdep.h | 4 ++++
 1 file changed, 4 insertions(+)
include/qemu/osdep.h +0 -0
index 6e0cf9132d9..e090ead8262 100644

include/qemu/osdep.h void qemu_anon_ram_free(void *ptr, size_t size); · line 434

Quoted 10 lines
include/qemu/osdep.h +4 -0
@@ -425,6 +425,10 @@ void qemu_anon_ram_free(void *ptr, size_t size);
 #define HAVE_CHARDEV_PARPORT 1
 #endif
 
+#if defined(__HAIKU__)
+#define SIGIO SIGPOLL
+#endif
+
 #if defined(CONFIG_LINUX)
 #ifndef BUS_MCEERR_AR
 #define BUS_MCEERR_AR 4

Sounds reasonable.

#13 lore raw

PATCH v3 6/9 bswap.h: Include <endian.h> on Haiku for bswap operations

In reply to Peter Maydell

From: David CARLIER <[email protected]>

Haiku puts the bswap* functions in <endian.h>; pull in that include file on that platform.

[PMM: Expanded commit message]
---
 include/qemu/bswap.h | 2 ++
 1 file changed, 2 insertions(+)
include/qemu/bswap.h +2 -0
index 2a9f3fe783e..1d3e4c24e41 100644
@@ -8,6 +8,8 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
+#elif defined(__HAIKU__)
+# include <endian.h>
 #elif defined(CONFIG_BYTESWAP_H)
 # include <byteswap.h>
 
Signature · 1 line
2.20.1
Reviewed-by on v3 6/9
#14 lore raw

Re: [PATCH v3 6/9] bswap.h: Include <endian.h> on Haiku for bswap operations

Quoted 18 lines · Peter Maydell

From: David CARLIER <[email protected]>

Haiku puts the bswap* functions in <endian.h>; pull in that include file on that platform.

[PMM: Expanded commit message]
---
 include/qemu/bswap.h | 2 ++
 1 file changed, 2 insertions(+)
include/qemu/bswap.h +0 -0
index 2a9f3fe783e..1d3e4c24e41 100644

include/qemu/bswap.h line 14

Quoted 7 lines
include/qemu/bswap.h +2 -0
@@ -8,6 +8,8 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
+#elif defined(__HAIKU__)
+# include <endian.h>
 #elif defined(CONFIG_BYTESWAP_H)
 # include <byteswap.h>
Reviewed-by on v3 6/9
#15 lore raw

Re: [PATCH v3 6/9] bswap.h: Include <endian.h> on Haiku for bswap operations

In reply to Peter Maydell
Quoted 19 lines · Peter Maydell

From: David CARLIER <[email protected]>

Haiku puts the bswap* functions in <endian.h>; pull in that include file on that platform.

[PMM: Expanded commit message]
---
 include/qemu/bswap.h | 2 ++
 1 file changed, 2 insertions(+)
include/qemu/bswap.h +0 -0
index 2a9f3fe783e..1d3e4c24e41 100644

include/qemu/bswap.h line 15

Quoted 8 lines
include/qemu/bswap.h +2 -0
@@ -8,6 +8,8 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
+#elif defined(__HAIKU__)
+# include <endian.h>
 #elif defined(CONFIG_BYTESWAP_H)
 # include <byteswap.h>
 
#16 lore raw

PATCH v3 7/9 util/compatfd.c: Only include <sys/syscall.h> if CONFIG_SIGNALFD

In reply to Peter Maydell

From: David CARLIER <[email protected]>

util/compatfd.c includes <sys/syscall.h> so that the CONFIG_SIGNALFD code can use SYS_signalfd. Guard the #include with CONFIG_SIGNALFD to avoid portability issues on hosts like Haiku which do not provide that header file.

[PMM: Expanded commit message]
---
 util/compatfd.c | 2 ++
 1 file changed, 2 insertions(+)
util/compatfd.c +2 -0
index c296f55d148..ee47dd80897 100644
@@ -16,7 +16,9 @@
 #include "qemu/osdep.h"
 #include "qemu/thread.h"
 
+#if defined(CONFIG_SIGNALFD)
 #include <sys/syscall.h>
+#endif
 
 struct sigfd_compat_info
 {
Signature · 1 line
2.20.1
Reviewed-by on v3 7/9
#17 lore raw

Re: [PATCH v3 7/9] util/compatfd.c: Only include <sys/syscall.h> if CONFIG_SIGNALFD

Quoted 20 lines · Peter Maydell

From: David CARLIER <[email protected]>

util/compatfd.c includes <sys/syscall.h> so that the CONFIG_SIGNALFD code can use SYS_signalfd. Guard the #include with CONFIG_SIGNALFD to avoid portability issues on hosts like Haiku which do not provide that header file.

[PMM: Expanded commit message]
---
 util/compatfd.c | 2 ++
 1 file changed, 2 insertions(+)
util/compatfd.c +0 -0
index c296f55d148..ee47dd80897 100644

util/compatfd.c line 24

Quoted 9 lines
util/compatfd.c +2 -0
@@ -16,7 +16,9 @@
 #include "qemu/osdep.h"
 #include "qemu/thread.h"
 
+#if defined(CONFIG_SIGNALFD)
 #include <sys/syscall.h>
+#endif
 
 struct sigfd_compat_info
 {
#18 lore raw

Re: [PATCH v3 7/9] util/compatfd.c: Only include <sys/syscall.h> if CONFIG_SIGNALFD

In reply to Peter Maydell
Quoted 20 lines · Peter Maydell

From: David CARLIER <[email protected]>

util/compatfd.c includes <sys/syscall.h> so that the CONFIG_SIGNALFD code can use SYS_signalfd. Guard the #include with CONFIG_SIGNALFD to avoid portability issues on hosts like Haiku which do not provide that header file.

[PMM: Expanded commit message]
---
 util/compatfd.c | 2 ++
 1 file changed, 2 insertions(+)
util/compatfd.c +0 -0
index c296f55d148..ee47dd80897 100644

util/compatfd.c line 19

Quoted 4 lines
util/compatfd.c +1 -0
@@ -16,7 +16,9 @@
 #include "qemu/osdep.h"
 #include "qemu/thread.h"
 
+#if defined(CONFIG_SIGNALFD)

Most of the code base guards <sys/syscall.h> with '#ifdef CONFIG_LINUX', bsd-user/strace.c is the BSD exception.

CONFIG_SIGNALFD guards SYS_signalfd.

Quoted 6 lines
util/compatfd.c +1 -0
 #include <sys/syscall.h>
+#endif
 
 struct sigfd_compat_info
 {
#19 lore raw

PATCH v3 8/9 util/oslib-posix.c: Implement qemu_init_exec_dir() for Haiku

In reply to Peter Maydell

From: David CARLIER <[email protected]>

The qemu_init_exec_dir() function is inherently non-portable; provide an implementation for Haiku hosts.

[PMM: Expanded commit message]
---
 util/oslib-posix.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
util/oslib-posix.c +19 -0
index 7ad9195c445..72907d4d7fe 100644
@@ -60,6 +60,10 @@
 #include <mach-o/dyld.h>
 #endif
 
+#ifdef __HAIKU__
+#include <kernel/image.h>
+#endif
+
 #include "qemu/mmap-alloc.h"
 
 #ifdef CONFIG_DEBUG_STACK_USAGE
@@ -389,6 +393,21 @@ void qemu_init_exec_dir(const char *argv0)
             }
         }
     }
+#elif defined(__HAIKU__)
+    {
+        image_info ii;
+        int32_t c = 0;
+
+        *buf = '\0';
+        while (get_next_image_info(0, &c, &ii) == B_OK) {
+            if (ii.type == B_APP_IMAGE) {
+                strncpy(buf, ii.name, sizeof(buf));
+                buf[sizeof(buf) - 1] = 0;
+                p = buf;
+                break;
+            }
+        }
+    }
 #endif
     /* If we don't have any way of figuring out the actual executable
        location then try argv[0].  */
Signature · 1 line
2.20.1
#20 lore raw

PATCH v3 9/9 util/drm: make portable by avoiding struct dirent d_type

In reply to Peter Maydell

From: Gerd Hoffmann <[email protected]>

Given this isn't perforance critical at all lets avoid the non-portable d_type and use fstat instead to check whenever the file is a chardev.

Message-id: [email protected]

[PMM: fixed comment style; tweaked subject line]
---
 util/drm.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)
util/drm.c +14 -5
index a23ff245382..dae8ffebc81 100644
@@ -24,7 +24,8 @@ int qemu_drm_rendernode_open(const char *rendernode)
 {
     DIR *dir;
     struct dirent *e;
-    int r, fd;
+    struct stat st;
+    int r, fd, ret;
     char *p;
 
     if (rendernode) {
@@ -38,10 +39,6 @@ int qemu_drm_rendernode_open(const char *rendernode)
 
     fd = -1;
     while ((e = readdir(dir))) {
-        if (e->d_type != DT_CHR) {
-            continue;
-        }
-
         if (strncmp(e->d_name, "renderD", 7)) {
             continue;
         }
@@ -53,6 +50,18 @@ int qemu_drm_rendernode_open(const char *rendernode)
             g_free(p);
             continue;
         }
+
+        /*
+         * prefer fstat() over checking e->d_type == DT_CHR for
+         * portability reasons
+         */
+        ret = fstat(r, &st);
+        if (ret < 0 || (st.st_mode & S_IFMT) != S_IFCHR) {
+            close(r);
+            g_free(p);
+            continue;
+        }
+
         fd = r;
         g_free(p);
         break;
Signature · 1 line
2.20.1
#21 lore raw
In reply to Peter Maydell
Quoted 10 lines · Peter Maydell

This patchset is essentially a resend of David Carlier's build fixes for the Haiku platform. I've taken David's patches and put them together into a set of emails threaded in the way our CI tools expect, as the easiest way to get the patchew robot to run the build tests so we can check they didn't accidentally break one of the BSDs. I've also put in the patch from Gerd that fixes the drm.c issue. I've also expanded on the commit messages for all the patches so that we have a record of why we made the changes if we need to look back at it in future.

Quoted 2 lines

Assuming no issues turn up, I'll arrange to get these into master at some point before the 5.1 release.

I've made the minor renames from CONFIG_ to HAVE_ where suggested and will put these into the tree via a target-arm pullreq I'm planning for Monday.

thanks
-- PMM

#22 lore raw

Alright thanks for the assistance. Regards.

Quoted 22 lines · Peter Maydell
Quoted 10 lines · Peter Maydell

This patchset is essentially a resend of David Carlier's build fixes for the Haiku platform. I've taken David's patches and put them together into a set of emails threaded in the way our CI tools expect, as the easiest way to get the patchew robot to run the build tests so we can check they didn't accidentally break one of the BSDs. I've also put in the patch from Gerd that fixes the drm.c issue. I've also expanded on the commit messages for all the patches so that we have a record of why we made the changes if we need to look back at it in future.

Quoted 2 lines

Assuming no issues turn up, I'll arrange to get these into master at some point before the 5.1 release.

I've made the minor renames from CONFIG_ to HAVE_ where suggested and will put these into the tree via a target-arm pullreq I'm planning for Monday.

thanks
-- PMM