# FD_SETSIZE



## jetoblaster (Aug 17, 2016)

Hi, I am trying to deploy a large scale filtering system using FreeBSD 10.3 x64 and e2guardian.
Dansguardian and the limitation of 1024 maximum processes is just not cutting it anymore and causing child squid caches to suffer badly.

Now e2guardian can have up to 8192 processes and when building the port I selected 4096 which is more than enough, but the only problem is when trying to start e2guardian I am hit with the following error.


```
Starting e2guardian.
Compiled with --with-filedescriptors too high
You should upgrade your FD_SETSIZE=1024
E2guardian compiled with with-filedescriptors=4096
Or reduce --with-filedescriptors=4096 under 1024
```
There is not a whole lot of useful information out there but I have tried installing source and rebuilding world after editing the select.h file /usr/src/sys/sys/select.h

So instead of 1024U, I bumped it up to 8192U and then rebuilt world, but still the same error.

How does one actually change FD_SETSIZE=1024 to something more useful?


----------



## jetoblaster (Aug 18, 2016)

My mistake, hopefully this helps someone else someday.

All you need to do is raise the value in /usr/include/sys/select.h before you actually compile e2guardian.


----------



## SirDice (Aug 18, 2016)

jetoblaster said:


> All you need to do is raise the value in /usr/include/sys/select.h before you actually compile e2guardian.


It's probably a bad idea to do it this way. It might have unforseen consequences with everything else that's build afterwards.

If I read select(2) correctly this is the correct solution:

```
NOTES
     The default size of FD_SETSIZE is currently 1024.  In order to accommo-
     date programs which might potentially use a larger number of open files
     with select(), it is possible to increase this size by having the program
     define FD_SETSIZE before the inclusion of any header which includes
     <sys/types.h>.
```


----------



## Murph (Aug 18, 2016)

Yeah, I think it's quite a bad idea to make that a system wide change.  What is really needed is something along the lines of adding it to CFLAGS for just that port (the best method for doing that depends on the port).  It is wrapped in a `#ifndef` in the system include file, so it just needs the compiler to somehow be given a `-DFD_SETSIZE=4096U` arg during the build of just that port.

Looking at the post-extract: target in /usr/ports/www/e2guardian/Makefile, I'm a little puzzled why it is giving out what seems to be bad advice instead of just amending CFLAGS (which should be very easy inside the Makefile), or applying what should be a fairly simple patch to the port's build process (as the build's configuration stage is already being passed `--with-filedescriptors=[i]N[/i]`).


----------



## jetoblaster (Aug 19, 2016)

SirDice said:


> It's probably a bad idea to do it this way. It might have unforseen consequences with everything else that's build afterwards.



Thanks for the advice, unfortunately I did not write the software I just have the fun job of trying to make it work. I did not see any options to have the e2guardian define FD_SETSIZE Personally I think the software needs a little work as there were numerous issues just getting it close to good enough to work in production but beggars can't be choosers. The server is only every going to be running e2guardian and squid, changing the value back to 1024u in /usr/include/sys/select.h after the port is built makes no difference to e2guardian so I changed it back to be safe.

Thanks for the replies and opinions, this is an area I have not had much experience in even though I have been using FreeBSD for many years!


----------



## qsecofr (Aug 19, 2016)

If you're building from ports, had you tried editing the source in this port's "work"directory before installing?  Granted that might be more a theoretical than practical thought, not really knowing about this specific port's source.  But where there's a will, there's probably a way..

And on second thought, a scan through the source code might not be a bad idea to verify there are no other dependencies or limitations on FD_SETSIZE being redefined to a value other than was originally assumed.


----------



## jetoblaster (May 11, 2017)

Rather than start a new thread I thought I should continue here.

After getting e2guardian installed it is not working the way it should.

I have tired over a number of different FreeBSD servers/versions as well as multiple versions of e2guardian. I have used ports as well as source but the end result is always the same.

As a test I installed it on slackware and it works perfectly fine, but not on my much preferred OS.

Basically the issue is that it is writing to console and obviously /var/log/messages about how many freechildren etc... it has at the moment. On a server with lots of load this gets silly very quickly as it fills the log file with pointless information.

Example of /var/log/messages


```
May 10 13:00:48 b-freebsd e2guardian[1043]: freechildren 30 + busychildren 4 != numchildren 35
May 10 13:00:48 b-freebsd e2guardian[1043]: stats reset to freechildren 31  busychildren 4 numchildren 35
May 10 13:01:48 b-freebsd e2guardian[1043]: freechildren 29 + busychildren 5 != numchildren 35
May 10 13:01:48 b-freebsd e2guardian[1043]: stats reset to freechildren 30  busychildren 5 numchildren 35
May 10 13:02:03 b-freebsd e2guardian[1043]: freechildren 30 + busychildren 4 != numchildren 35
May 10 13:02:03 b-freebsd e2guardian[1043]: stats reset to freechildren 31  busychildren 4 numchildren 35
May 10 13:03:04 b-freebsd e2guardian[1043]: freechildren 29 + busychildren 5 != numchildren 35
May 10 13:03:04 b-freebsd e2guardian[1043]: stats reset to freechildren 30  busychildren 5 numchildren 35
May 10 13:04:09 b-freebsd e2guardian[1043]: freechildren 29 + busychildren 5 != numchildren 35
May 10 13:04:09 b-freebsd e2guardian[1043]: stats reset to freechildren 30  busychildren 5 numchildren 35
May 10 13:06:02 b-freebsd e2guardian[1043]: freechildren 30 + busychildren 4 != numchildren 35
May 10 13:06:02 b-freebsd e2guardian[1043]: stats reset to freechildren 31  busychildren 4 numchildren 35
May 10 13:07:04 b-freebsd e2guardian[1043]: freechildren 30 + busychildren 4 != numchildren 35
May 10 13:07:04 b-freebsd e2guardian[1043]: stats reset to freechildren 31  busychildren 4 numchildren 35
May 10 13:07:05 b-freebsd e2guardian[1043]: freechildren 29 + busychildren 5 != numchildren 35
May 10 13:07:05 b-freebsd e2guardian[1043]: stats reset to freechildren 30  busychildren 5 numchildren 35
May 10 13:07:49 b-freebsd e2guardian[1043]: freechildren 29 + busychildren 5 != numchildren 35
```

I have tried their support forum without too much luck just yet, would anyone here have any bright ideas?


----------

