Correctly set max_fds in case of failure
authorHannes Reinecke <hare@suse.de>
Tue, 16 Jul 2013 07:13:08 +0000 (09:13 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Tue, 16 Jul 2013 19:50:42 +0000 (21:50 +0200)
If we fail to get the system limit for max_fds we should assume
a safe value of 4096.

Signed-off-by: Hannes Reinecke <hare@suse.de>
libmultipath/dict.c

index 6a58fa2..4b840de 100644 (file)
@@ -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);