Adapt max_clients on EMFILE or ENFILE

This commit is contained in:
Christopher Wellons 2019-02-02 23:19:44 -05:00
parent 891584a361
commit 1f1ce4e26d

View File

@ -267,7 +267,7 @@ main(int argc, char **argv)
/* Wait for next event */ /* Wait for next event */
if (verbose >= 2) if (verbose >= 2)
logmsg("poll(%zu, %d)%s", pollvec->fill, timeout, logmsg("poll(%zu, %d)%s", pollvec->fill, timeout,
nclients == max_clients ? " (no accept)" : ""); nclients >= max_clients ? " (no accept)" : "");
int r = poll(pollvec->fds, pollvec->fill, timeout); int r = poll(pollvec->fds, pollvec->fill, timeout);
if (verbose >= 2) if (verbose >= 2)
logmsg("= %d", r); logmsg("= %d", r);
@ -291,15 +291,19 @@ main(int argc, char **argv)
if (fd == -1) { if (fd == -1) {
const char *msg = strerror(errno); const char *msg = strerror(errno);
switch (errno) { switch (errno) {
case ECONNABORTED:
case EINTR:
case EMFILE: case EMFILE:
case ENFILE: case ENFILE:
max_clients = nclients;
if (verbose >= 1)
logmsg("max clients reduced to %ld", nclients);
break;
case ECONNABORTED:
case EINTR:
case ENOBUFS: case ENOBUFS:
case ENOMEM: case ENOMEM:
case EPROTO: case EPROTO:
fprintf(stderr, "endlessh: warning: %s\n", msg); fprintf(stderr, "endlessh: warning: %s\n", msg);
continue; break;
default: default:
fprintf(stderr, "endlessh: fatal: %s\n", msg); fprintf(stderr, "endlessh: fatal: %s\n", msg);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);