blablacio/watchman — pull request #1 by blablacio (2014-11-18 17:46:21+00:00)
Title: Adding proper handling for fd limits on OpenBSD

Adding proper handling of fd limits on OpenBSD: kern.maxfilesperproc is not available on OpenBSD and kern.maxfiles is the absolute maximum for the whole system.

A normal user can only increase the soft (openfiles-cur) limit up to the hard (openfiles-max) limit defined in /etc/login.conf, so there is no point in the sysctl call on OpenBSD:

> A resource limit is specified as a soft limit and a hard limit. When a soft limit is exceeded a process may receive a signal (for example, if the CPU time or file size is exceeded), but it will be allowed to continue execution until it reaches the hard limit (or modifies its resource limit). The rlimit structure is used to specify the hard and soft limits on a resource,
```
struct rlimit {
rlim_t	rlim_cur;	/* current (soft) limit */
rlim_t	rlim_max;	/* hard limit */
};
```
> Only the superuser may raise the maximum limits. Other users may only alter rlim_cur within the range from 0 to rlim_max or (irreversibly) lower rlim_max.

Not quite sure what is the case with NetBSD/FreeBSD.