Add test-compile checks for epoll and eventfd

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11253 e03df62e-2008-0410-955e-edbf42e46eb7
This commit is contained in:
danieldg 2009-03-23 18:49:06 +00:00
parent 85a787b92b
commit 58eae4fc8a
4 changed files with 34 additions and 69 deletions

82
configure vendored
View File

@ -531,6 +531,15 @@ sub svnupdate
exit;
}
sub test_compile {
my $feature = shift;
my $fail = 0;
$fail ||= system "$config{CC} -o test_$feature make/check_$feature.cpp >/dev/null 2>&1";
$fail ||= system "./test_$feature";
unlink "test_$feature";
return !$fail;
}
print "Running non-interactive configure...\n" unless $interactive;
print "Checking for cache from previous configure... ";
print ((!getcache()) ? "not found\n" : "found\n");
@ -584,69 +593,13 @@ if (!$fail) {
print "yes\n" if $has_kqueue == 1;
print "no\n" if $has_kqueue == 0;
printf "Checking if epoll exists... ";
$has_epoll = 0;
$fail = 0;
open(EPOLL, "</usr/include/sys/epoll.h") or $fail = 1;
if (!$fail) {
$has_epoll = 1;
close(EPOLL);
}
if ($has_epoll) {
my $kernel = `uname -r`;
chomp($kernel);
if (($kernel =~ /^2\.0\./) || ($kernel =~ /^2\.2\./) || ($kernel =~ /^2\.4\./)) {
$has_epoll = 0;
}
else
{
# Suggestion from nenolod, weed out odd systems which have glibc built
# against 2.4 kernels (ick)
my $kernel_arch = `uname -p`;
chomp($kernel_arch);
my $libcv = 0.0;
my $kernelv = 0.0;
if ($kernel_arch =~ /x86_64/) {
open (FH,"/lib64/libc.so.6|") or $has_epoll = 0;
}
else {
open (FH,"/lib/libc.so.6|") or $has_epoll = 0;
}
if ($has_epoll)
{
while (defined(my $line = <FH>))
{
chomp($line);
if ($line =~ /GNU C Library .* version (.*?) /)
{
$libcv = $1;
$libcv =~ /(\d+\.\d+)/;
$libcv = $1;
}
elsif ($line =~ /Compiled on a Linux (.*?\..*?)\.* system/)
{
$kernelv = $1;
# Fix for some retarded libc builds, strip off >> and << etc.
$kernelv =~ /(\d+\.\d+)/;
$kernelv = $1;
}
}
close FH;
if ($libcv < 2.3)
{
$has_epoll = 0;
printf "libc too old: $libcv... ";
}
if ($kernelv < 2.6)
{
$has_epoll = 0;
printf "libc built against older kernel $kernelv... ";
}
}
}
}
print "yes\n" if $has_epoll == 1;
print "no\n" if $has_epoll == 0;
printf "Checking for epoll support... ";
$has_epoll = test_compile('epoll');
print $has_epoll ? "yes\n" : "no\n";
printf "Checking for eventfd support... ";
$config{HAS_EVENTFD} = test_compile('eventfd') ? 'true' : 'false';
print $config{HAS_EVENTFD} eq 'true' ? "yes\n" : "no\n";
printf "Checking if Solaris I/O completion ports are available... ";
$has_ports = 0;
@ -1230,6 +1183,9 @@ print FILEHANDLE "#define MAXBUF " . ($config{MAXBUF}+2) . "\n";
if ($config{SUPPORT_IP6LINKS} =~ /y/i) {
print FILEHANDLE "#define SUPPORT_IP6LINKS\n";
}
if ($config{HAS_EVENTFD}) {
print FILEHANDLE "#define HAS_EVENTFD\n";
}
my $use_hiperf = 0;
if (($has_kqueue) && ($config{USE_KQUEUE} eq "y")) {
print FILEHANDLE "#define USE_KQUEUE\n";

6
make/check_epoll.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <sys/epoll.h>
int main() {
int fd = epoll_create(1);
return (fd < 0);
}

6
make/check_eventfd.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <sys/eventfd.h>
int main() {
int fd = eventfd(0, 0);
return (fd < 0);
}

View File

@ -15,6 +15,7 @@
#include "threadengines/threadengine_pthread.h"
#include <pthread.h>
#include <signal.h>
#include <fcntl.h>
ThreadEngine::ThreadEngine(InspIRCd* Instance)
{
@ -57,11 +58,7 @@ void ThreadData::FreeThread(Thread* thread)
pthread_join(pthread_id, NULL);
}
#if 0
/* TODO this is a linux-specific syscall that allows signals to be
* sent using a single file descriptor, rather than 2 for a pipe.
* Requires glibc 2.8, kernel 2.6.22+
*/
#ifdef HAS_EVENTFD
#include <sys/eventfd.h>
class ThreadSignalSocket : public BufferedSocket
@ -92,7 +89,7 @@ class ThreadSignalSocket : public BufferedSocket
SocketThread::SocketThread(InspIRCd* SI)
{
int fd = eventfd(0, 0); // TODO nonblock
int fd = eventfd(0, O_NONBLOCK);
if (fd < 0)
throw new CoreException("Could not create pipe " + std::string(strerror(errno)));
signal.sock = new ThreadSignalSocket(this, SI, fd);