Date: Wed, 17 Dec 1997 08:50:01 -0800 (PST) From: Christopher Masto <chris@netmonger.net> To: freebsd-bugs Subject: Re: bin/5306: gethostbyname() returns herror "Unknown host" on well known hosts Message-ID: <199712171650.IAA23698@hub.freebsd.org>
index | next in thread | raw e-mail
The following reply was made to PR bin/5306; it has been noted by GNATS.
From: Christopher Masto <chris@netmonger.net>
To: freebsd-gnats-submit@freebsd.org, bde@zeta.org.au, robert@superior.net
Cc: Subject: Re: bin/5306: gethostbyname() returns herror "Unknown host" on well known hosts
Date: Wed, 17 Dec 1997 11:45:10 -0500
> At least for the test program in PR 3622, the fix is to configure enough
> fd's using /etc/login.conf. In 2.2.5, the default openfiles limits for
> class daemon are 1024 (hard) and OPEN_MAX (soft). These should be set
> as large as necessary (but no larger) for each class of user.
>
> There is also an evil sysctl limit `kern.maxfilesperproc' with the
> default value of 2*NPROC. This interferes with correct operation of
> login.conf. If it is too small, then the easiest way to fix it is to
> edit /sys/conf/param.c and build a new kernel. There is also a good
> sysctl limit `kern.maxfiles' with the default value of 2*NPROC. This
> is easy to change at runtime using `sysctl -w kern.maxfiles=...'.
> (Changing kern.maxfilesperproc at runtime doesn't work well because
> it can't increase the openfiles limits in the process tree. It can
> only decrease them.)
I don't know whether the gethostbyname() problem Robert is having is
related to PR 3622, but I think there is a problem with the default
login.conf.
I had to lower openfiles settings to 256 because having it larger
breaks select(). It's been a while, so I'm a bit fuzzy on the details,
but I do remember that it was causing rxvt to fail.. a quick perusal
of the rxvt source indicates that it does:
#ifdef _POSIX_VERSION
num_fds = sysconf(_SC_OPEN_MAX);
#else
num_fds = getdtablesize();
#endif
I believe that it ends up obtaining the 1024 that was defined in login.conf,
but the FD_SETSIZE in sys/types.h is defined as 256. IIRC, select() bombs
out when nfds is > 256.
I suppose I should test this rather than just make the claim. Try this:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/select.h>
void testselect(int num)
{
fd_set fds;
struct timeval tv = {0, 0};
printf("testing select(%d,...)\n", num);
FD_ZERO(&fds);
if (select(num, &fds, &fds, &fds, &tv) < 0) {
perror("select()");
}
else {
printf("select() successful\n");
}
}
int main(int argc, char *argv[])
{
int dtsize;
int open_max;
printf("FD_SETSIZE = %d\n", FD_SETSIZE);
dtsize=getdtablesize();
printf("getdtablesize() = %d\n", dtsize);
open_max=(int)sysconf(_SC_OPEN_MAX);
printf("open_max = %d\n", open_max);
testselect(FD_SETSIZE);
testselect(dtsize);
}
- - -
chris@cheddar:/tmp$ ulimit -n
1024
chris@cheddar:/tmp$ ./seltest
FD_SETSIZE = 256
getdtablesize() = 1024
open_max = 1024
testing select(256,...)
select() successful
testing select(1024,...)
select(): Bad file descriptor
I hope that was clear.
--
= Christopher Masto = chris@netmonger.net = http://www.netmonger.net/ =
= NetMonger Communications = finger for PGP key = $19.95/mo unlimited access =
= Director of Operations = (516) 221-6664 = mailto:info@netmonger.net =
"... who'd want a lossy TIFF?" -- Kibo
help
Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199712171650.IAA23698>
