Commit 27463101f15bee17d2f46642c48a7373bc6c595e

Authored by aliguori
1 parent b8ae7553

Make compatfd fallback more robust

Be more friendly when signalfd() fails, and also add configure checks to detect
that syscall(SYS_signalfd) actually works.  malc pointed out that some installs
do not have /usr/include/linux headers that are in sync with the glibc headers
so why SYS_signalfd is defined, it's #defined to _NR_signalfd which is not
defined in the /usr/include/linux header.

While this is a distro bug, it doesn't hurt to do a more thorough job in
detection.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5334 c046a42c-6fe2-441c-8c8c-71466251a162
block-raw-posix.c
@@ -584,6 +584,10 @@ static int posix_aio_init(void) @@ -584,6 +584,10 @@ static int posix_aio_init(void)
584 584
585 s->first_aio = NULL; 585 s->first_aio = NULL;
586 s->fd = qemu_signalfd(&mask); 586 s->fd = qemu_signalfd(&mask);
  587 + if (s->fd == -1) {
  588 + fprintf(stderr, "failed to create signalfd\n");
  589 + return -errno;
  590 + }
587 591
588 fcntl(s->fd, F_SETFL, O_NONBLOCK); 592 fcntl(s->fd, F_SETFL, O_NONBLOCK);
589 593
compatfd.c
@@ -100,11 +100,11 @@ static int qemu_signalfd_compat(const sigset_t *mask) @@ -100,11 +100,11 @@ static int qemu_signalfd_compat(const sigset_t *mask)
100 100
101 int qemu_signalfd(const sigset_t *mask) 101 int qemu_signalfd(const sigset_t *mask)
102 { 102 {
103 -#if defined(SYS_signalfd) 103 +#if defined(CONFIG_signalfd)
104 int ret; 104 int ret;
105 105
106 ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8); 106 ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8);
107 - if (!(ret == -1 && errno == ENOSYS)) 107 + if (ret != -1)
108 return ret; 108 return ret;
109 #endif 109 #endif
110 110
@@ -113,15 +113,14 @@ int qemu_signalfd(const sigset_t *mask) @@ -113,15 +113,14 @@ int qemu_signalfd(const sigset_t *mask)
113 113
114 int qemu_eventfd(int *fds) 114 int qemu_eventfd(int *fds)
115 { 115 {
116 -#if defined(SYS_eventfd) 116 +#if defined(CONFIG_eventfd)
117 int ret; 117 int ret;
118 118
119 ret = syscall(SYS_eventfd, 0); 119 ret = syscall(SYS_eventfd, 0);
120 if (ret >= 0) { 120 if (ret >= 0) {
121 fds[0] = fds[1] = ret; 121 fds[0] = fds[1] = ret;
122 return 0; 122 return 0;
123 - } else if (!(ret == -1 && errno == ENOSYS))  
124 - return ret; 123 + }
125 #endif 124 #endif
126 125
127 return pipe(fds); 126 return pipe(fds);
configure
@@ -110,6 +110,8 @@ curses=&quot;yes&quot; @@ -110,6 +110,8 @@ curses=&quot;yes&quot;
110 aio="yes" 110 aio="yes"
111 nptl="yes" 111 nptl="yes"
112 mixemu="no" 112 mixemu="no"
  113 +signalfd="no"
  114 +eventfd="no"
113 115
114 # OS specific 116 # OS specific
115 targetos=`uname -s` 117 targetos=`uname -s`
@@ -901,6 +903,33 @@ EOF @@ -901,6 +903,33 @@ EOF
901 fi 903 fi
902 fi 904 fi
903 905
  906 +##########################################
  907 +# signalfd probe
  908 +cat > $TMPC << EOF
  909 +#define _GNU_SOURCE
  910 +#include <unistd.h>
  911 +#include <sys/syscall.h>
  912 +#include <signal.h>
  913 +int main(void) { return syscall(SYS_signalfd, -1, NULL, _NSIG / 8); }
  914 +EOF
  915 +
  916 +if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
  917 + signalfd=yes
  918 +fi
  919 +
  920 +##########################################
  921 +# eventfd probe
  922 +cat > $TMPC << EOF
  923 +#define _GNU_SOURCE
  924 +#include <unistd.h>
  925 +#include <sys/syscall.h>
  926 +int main(void) { return syscall(SYS_eventfd, 0); }
  927 +EOF
  928 +
  929 +if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
  930 + eventfd=yes
  931 +fi
  932 +
904 # Check if tools are available to build documentation. 933 # Check if tools are available to build documentation.
905 if [ -x "`which texi2html 2>/dev/null`" ] && \ 934 if [ -x "`which texi2html 2>/dev/null`" ] && \
906 [ -x "`which pod2man 2>/dev/null`" ]; then 935 [ -x "`which pod2man 2>/dev/null`" ]; then
@@ -1229,6 +1258,12 @@ if test &quot;$aio&quot; = &quot;yes&quot; ; then @@ -1229,6 +1258,12 @@ if test &quot;$aio&quot; = &quot;yes&quot; ; then
1229 echo "#define CONFIG_AIO 1" >> $config_h 1258 echo "#define CONFIG_AIO 1" >> $config_h
1230 echo "CONFIG_AIO=yes" >> $config_mak 1259 echo "CONFIG_AIO=yes" >> $config_mak
1231 fi 1260 fi
  1261 +if test "$signalfd" = "yes" ; then
  1262 + echo "#define CONFIG_signalfd 1" >> $config_h
  1263 +fi
  1264 +if test "$eventfd" = "yes" ; then
  1265 + echo "#define CONFIG_eventfd 1" >> $config_h
  1266 +fi
1232 1267
1233 # XXX: suppress that 1268 # XXX: suppress that
1234 if [ "$bsd" = "yes" ] ; then 1269 if [ "$bsd" = "yes" ] ; then