On 2010/01/12 11:06, Stuart Henderson wrote: > this has been bugging me for ages; nut works fine if started from > a shell, but from rc.local upsd dies. I finally got annoyed with it > enough to track it down, turns out if sysconf reports a fewer number > of filehandles available than the setting of MAXCONN (which defaults > to FD_SETSIZE, 1024) it dies. > > we could get fancy and use setrlimit to bump the value, but I think > this simpler diff is enough; it just changes the default config file > to a value that works with our standard login.conf and adds a few > notes. ok?
ah, I see upstream fixed it in development code, but haven't made a release with it in yet. new diff to use it. Index: Makefile =================================================================== RCS file: /cvs/ports/sysutils/nut/Makefile,v retrieving revision 1.32 diff -u -p -r1.32 Makefile --- Makefile 15 Sep 2009 17:37:22 -0000 1.32 +++ Makefile 12 Jan 2010 12:31:18 -0000 @@ -5,7 +5,7 @@ COMMENT-cgi= CGIs for monitoring Nut-ba COMMENT-snmp= driver for monitoring UPSs via SNMP DISTNAME= nut-2.4.1 -PKGNAME-main= ${DISTNAME}p0 +PKGNAME-main= ${DISTNAME}p1 PKGNAME-cgi= ${DISTNAME:S/-/-cgi-/}p0 PKGNAME-snmp= ${DISTNAME:S/-/-snmp-/}p0 CATEGORIES= sysutils Index: patches/patch-conf_upsd_conf_sample =================================================================== RCS file: patches/patch-conf_upsd_conf_sample diff -N patches/patch-conf_upsd_conf_sample --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-conf_upsd_conf_sample 12 Jan 2010 12:31:18 -0000 @@ -0,0 +1,19 @@ +$OpenBSD$ + +from r1852 upstream; don't use an insane default for maxconn. + +--- conf/upsd.conf.sample.orig Tue Jan 12 12:24:50 2010 ++++ conf/upsd.conf.sample Tue Jan 12 12:28:42 2010 +@@ -34,8 +34,8 @@ + + # ======================================================================= + # MAXCONN <connections> +-# MAXCONN 1024 + # +-# This defaults to 1024 connections. Each UPS, each LISTEN address and each +-# client count as one connection. If the server runs out of connections, it +-# will no longer accept new incoming client connections. ++# This defaults to maximum number allowed on your system. Each UPS, each ++# LISTEN address and each client count as one connection. If the server ++# runs out of connections, it will no longer accept new incoming client ++# connections. Only set this if you know exactly what you're doing. Index: patches/patch-server_upsd_c =================================================================== RCS file: patches/patch-server_upsd_c diff -N patches/patch-server_upsd_c --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ patches/patch-server_upsd_c 12 Jan 2010 12:31:18 -0000 @@ -0,0 +1,41 @@ +$OpenBSD$ + +from r1852 upstream; don't use an insane default for maxconn, +change the error message to better indicate that it's an error +not a warning. + +--- server/upsd.c.orig Tue Jan 12 12:23:27 2010 ++++ server/upsd.c Tue Jan 12 12:24:45 2010 +@@ -52,8 +52,8 @@ int deny_severity = LOG_WARNING; + /* default 15 seconds before data is marked stale */ + int maxage = 15; + +- /* default FD_SETSIZE connections allowed */ +- int maxconn = FD_SETSIZE; ++ /* preloaded to {OPEN_MAX} in main, can be overridden via upsd.conf */ ++ int maxconn = 0; + + /* preloaded to STATEPATH in main, can be overridden via upsd.conf */ + char *statepath = NULL; +@@ -712,7 +712,10 @@ void poll_reload(void) + ret = sysconf(_SC_OPEN_MAX); + + if (ret < maxconn) { +- fatalx(EXIT_FAILURE, "Maximum number of connections limited to %d [requested %d]", ret, maxconn); ++ fatalx(EXIT_FAILURE, ++ "Your system limits the maximum number of connections to %d\n" ++ "but you requested %d. The server won't start until this\n" ++ "problem is resolved.\n", ret, maxconn); + } + + fds = xrealloc(fds, maxconn * sizeof(*fds)); +@@ -1036,6 +1039,9 @@ int main(int argc, char **argv) + if (chroot_path) { + chroot_start(chroot_path); + } ++ ++ /* default to system limit (may be overridden in upsd.conf */ ++ maxconn = sysconf(_SC_OPEN_MAX); + + /* handle upsd.conf */ + load_upsdconf(0); /* 0 = initial */