From 1a63155b0797c2b1963424e5c0f5d3a62f8cc7cc Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Fri, 17 Feb 2012 11:50:27 -0500 Subject: RESPONDERS: Allow increasing the file-descriptor limit This patch will increase the file descriptor limit to 8k or the limits.conf maximum, whichever is lesser. https://fedorahosted.org/sssd/ticket/1197 --- src/responder/common/responder_common.c | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/responder/common/responder_common.c') diff --git a/src/responder/common/responder_common.c b/src/responder/common/responder_common.c index a48ac556a..94a9fdb63 100644 --- a/src/responder/common/responder_common.c +++ b/src/responder/common/responder_common.c @@ -648,3 +648,39 @@ int responder_logrotate(DBusMessage *message, return monitor_common_pong(message, conn); } + +void responder_set_fd_limit(rlim_t fd_limit) +{ + struct rlimit current_limit, new_limit; + int limret; + + /* First determine the maximum hard limit */ + limret = getrlimit(RLIMIT_NOFILE, ¤t_limit); + if (limret == 0) { + DEBUG(SSSDBG_TRACE_INTERNAL, + ("Current fd limit: [%d]\n", + current_limit.rlim_cur)); + /* Choose the lesser of the requested and the hard limit */ + if (current_limit.rlim_max < fd_limit) { + new_limit.rlim_cur = current_limit.rlim_max; + } else { + new_limit.rlim_cur = fd_limit; + } + new_limit.rlim_max = current_limit.rlim_max; + + limret = setrlimit(RLIMIT_NOFILE, &new_limit); + if (limret == 0) { + DEBUG(SSSDBG_CONF_SETTINGS, + ("Maximum file descriptors set to [%d]\n", + new_limit.rlim_cur)); + } else { + DEBUG(SSSDBG_CRIT_FAILURE, + ("Could not set new fd limits. Proceeding with [%d]\n", + current_limit.rlim_cur)); + } + } else { + DEBUG(SSSDBG_CRIT_FAILURE, + ("Could not determine fd limits. " + "Proceeding with system values\n")); + } +} -- cgit