Skip to contentSkip to conversation

configure: improve usbfs check

PATCH Applied Thomas Petazzoni 3 participants 3 messages Feb 13, 2019 – Feb 14, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 configure: improve usbfs check

The current check to test if usbfs support should be compiled or not solely relies on the presence of <linux/usbdevice_fs.h>, without actually checking that all definition used by Qemu are provided by this header file.

With sufficiently old kernel headers, <linux/usbdevice_fs.h> may be present, but some of the definitions needed by Qemu may not be available.

This commit improves the check by building a small program that actually tests whether the necessary definitions are available.

In addition, it fixes a bug where have_usbfs was set to "yes" regardless of the result of the test.

---
 configure | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
configure +17 -2
index 3d89870d99..799c8e3b08 100755
@@ -4266,10 +4266,25 @@ fi
 # check for usbfs
 have_usbfs=no
 if test "$linux_user" = "yes"; then
-  if check_include linux/usbdevice_fs.h; then
+  cat > $TMPC << EOF
+#include <linux/usbdevice_fs.h>
+
+#ifndef USBDEVFS_GET_CAPABILITIES
+#error "USBDEVFS_GET_CAPABILITIES undefined"
+#endif
+
+#ifndef USBDEVFS_DISCONNECT_CLAIM
+#error "USBDEVFS_DISCONNECT_CLAIM undefined"
+#endif
+
+int main(void)
+{
+    return 0;
+}
+EOF
+  if compile_prog "" ""; then
     have_usbfs=yes
   fi
-  have_usbfs=yes
 fi
 
 # check for fallocate
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 42 lines · Thomas Petazzoni

The current check to test if usbfs support should be compiled or not solely relies on the presence of <linux/usbdevice_fs.h>, without actually checking that all definition used by Qemu are provided by this header file.

With sufficiently old kernel headers, <linux/usbdevice_fs.h> may be present, but some of the definitions needed by Qemu may not be available.

This commit improves the check by building a small program that actually tests whether the necessary definitions are available.

In addition, it fixes a bug where have_usbfs was set to "yes" regardless of the result of the test.

---
 configure | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
configure +13 -1
index 3d89870d99..799c8e3b08 100755
@@ -4266,10 +4266,25 @@ fi
 # check for usbfs
 have_usbfs=no
 if test "$linux_user" = "yes"; then
-  if check_include linux/usbdevice_fs.h; then
+  cat > $TMPC << EOF
+#include <linux/usbdevice_fs.h>
+
+#ifndef USBDEVFS_GET_CAPABILITIES
+#error "USBDEVFS_GET_CAPABILITIES undefined"
+#endif
+
+#ifndef USBDEVFS_DISCONNECT_CLAIM
+#error "USBDEVFS_DISCONNECT_CLAIM undefined"
+#endif
+
+int main(void)
+{

configure fi · line 4290

Quoted 10 lines
configure +4 -1
+    return 0;
+}
+EOF
+  if compile_prog "" ""; then
     have_usbfs=yes
   fi
-  have_usbfs=yes
 fi
 
 # check for fallocate
#2 lore raw
Quoted 52 lines · Thomas Huth
Quoted 51 lines · Thomas Petazzoni

The current check to test if usbfs support should be compiled or not solely relies on the presence of <linux/usbdevice_fs.h>, without actually checking that all definition used by Qemu are provided by this header file.

With sufficiently old kernel headers, <linux/usbdevice_fs.h> may be present, but some of the definitions needed by Qemu may not be available.

This commit improves the check by building a small program that actually tests whether the necessary definitions are available.

In addition, it fixes a bug where have_usbfs was set to "yes" regardless of the result of the test.

---
 configure | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
configure +17 -2
index 3d89870d99..799c8e3b08 100755
@@ -4266,10 +4266,25 @@ fi
 # check for usbfs
 have_usbfs=no
 if test "$linux_user" = "yes"; then
-  if check_include linux/usbdevice_fs.h; then
+  cat > $TMPC << EOF
+#include <linux/usbdevice_fs.h>
+
+#ifndef USBDEVFS_GET_CAPABILITIES
+#error "USBDEVFS_GET_CAPABILITIES undefined"
+#endif
+
+#ifndef USBDEVFS_DISCONNECT_CLAIM
+#error "USBDEVFS_DISCONNECT_CLAIM undefined"
+#endif
+
+int main(void)
+{
+    return 0;
+}
+EOF
+  if compile_prog "" ""; then
     have_usbfs=yes
   fi
-  have_usbfs=yes
 fi
 
Quoted 4 lines

configure fi · line 4290

Quoted 1 line
configure +0 -0
 # check for fallocate

Applied to my trivial-patches branch.

Thanks,
Laurent