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
This commit is contained in:
aliguori 2008-09-27 20:58:43 +00:00
parent b8ae75538e
commit 27463101f1
3 changed files with 43 additions and 5 deletions

View File

@ -584,6 +584,10 @@ static int posix_aio_init(void)
s->first_aio = NULL; s->first_aio = NULL;
s->fd = qemu_signalfd(&mask); s->fd = qemu_signalfd(&mask);
if (s->fd == -1) {
fprintf(stderr, "failed to create signalfd\n");
return -errno;
}
fcntl(s->fd, F_SETFL, O_NONBLOCK); fcntl(s->fd, F_SETFL, O_NONBLOCK);

View File

@ -100,11 +100,11 @@ static int qemu_signalfd_compat(const sigset_t *mask)
int qemu_signalfd(const sigset_t *mask) int qemu_signalfd(const sigset_t *mask)
{ {
#if defined(SYS_signalfd) #if defined(CONFIG_signalfd)
int ret; int ret;
ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8); ret = syscall(SYS_signalfd, -1, mask, _NSIG / 8);
if (!(ret == -1 && errno == ENOSYS)) if (ret != -1)
return ret; return ret;
#endif #endif
@ -113,15 +113,14 @@ int qemu_signalfd(const sigset_t *mask)
int qemu_eventfd(int *fds) int qemu_eventfd(int *fds)
{ {
#if defined(SYS_eventfd) #if defined(CONFIG_eventfd)
int ret; int ret;
ret = syscall(SYS_eventfd, 0); ret = syscall(SYS_eventfd, 0);
if (ret >= 0) { if (ret >= 0) {
fds[0] = fds[1] = ret; fds[0] = fds[1] = ret;
return 0; return 0;
} else if (!(ret == -1 && errno == ENOSYS)) }
return ret;
#endif #endif
return pipe(fds); return pipe(fds);

35
configure vendored
View File

@ -110,6 +110,8 @@ curses="yes"
aio="yes" aio="yes"
nptl="yes" nptl="yes"
mixemu="no" mixemu="no"
signalfd="no"
eventfd="no"
# OS specific # OS specific
targetos=`uname -s` targetos=`uname -s`
@ -901,6 +903,33 @@ EOF
fi fi
fi fi
##########################################
# signalfd probe
cat > $TMPC << EOF
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
#include <signal.h>
int main(void) { return syscall(SYS_signalfd, -1, NULL, _NSIG / 8); }
EOF
if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
signalfd=yes
fi
##########################################
# eventfd probe
cat > $TMPC << EOF
#define _GNU_SOURCE
#include <unistd.h>
#include <sys/syscall.h>
int main(void) { return syscall(SYS_eventfd, 0); }
EOF
if $cc $ARCH_CFLAGS -o $TMPE $TMPC 2> /dev/null ; then
eventfd=yes
fi
# Check if tools are available to build documentation. # Check if tools are available to build documentation.
if [ -x "`which texi2html 2>/dev/null`" ] && \ if [ -x "`which texi2html 2>/dev/null`" ] && \
[ -x "`which pod2man 2>/dev/null`" ]; then [ -x "`which pod2man 2>/dev/null`" ]; then
@ -1229,6 +1258,12 @@ if test "$aio" = "yes" ; then
echo "#define CONFIG_AIO 1" >> $config_h echo "#define CONFIG_AIO 1" >> $config_h
echo "CONFIG_AIO=yes" >> $config_mak echo "CONFIG_AIO=yes" >> $config_mak
fi fi
if test "$signalfd" = "yes" ; then
echo "#define CONFIG_signalfd 1" >> $config_h
fi
if test "$eventfd" = "yes" ; then
echo "#define CONFIG_eventfd 1" >> $config_h
fi
# XXX: suppress that # XXX: suppress that
if [ "$bsd" = "yes" ] ; then if [ "$bsd" = "yes" ] ; then