From: Hannes Reinecke Subject: [PATCH 17/29] Correctly set max_fds in case of failure Date: Mon, 15 Jul 2013 15:00:18 +0200 Message-ID: <1373893230-26077-18-git-send-email-hare@suse.de> References: <1373893230-26077-1-git-send-email-hare@suse.de> Reply-To: device-mapper development Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1373893230-26077-1-git-send-email-hare@suse.de> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com To: Christophe Varoqui Cc: dm-devel@redhat.com List-Id: dm-devel.ids If we fail to get the system limit for max_fds we should assume a safe value of 4096. Signed-off-by: Hannes Reinecke --- libmultipath/dict.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libmultipath/dict.c b/libmultipath/dict.c index 6a58fa2..4b840de 100644 --- a/libmultipath/dict.c +++ b/libmultipath/dict.c @@ -290,18 +290,27 @@ static int max_fds_handler(vector strvec) { char * buff; - int r = 0; + int r = 0, max_fds; buff = set_value(strvec); if (!buff) return 1; + r = get_sys_max_fds(&max_fds); + if (r) { + /* Assume safe limit */ + max_fds = 4096; + } if (strlen(buff) == 3 && !strcmp(buff, "max")) - r = get_sys_max_fds(&conf->max_fds); + conf->max_fds = max_fds; else conf->max_fds = atoi(buff); + + if (conf->max_fds > max_fds) + conf->max_fds = max_fds; + FREE(buff); return r; @@ -2571,7 +2580,7 @@ snprint_max_fds (char * buff, int len, void * data) return 0; r = get_sys_max_fds(&max_fds); - if (!r && max_fds == conf->max_fds) + if (!r && conf->max_fds >= max_fds) return snprintf(buff, len, "\"max\""); else return snprintf(buff, len, "%d", conf->max_fds); -- 1.7.10.4