1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-18 13:39:02 +00:00

Make maximize_fdlimit return rlim_t on appropriate platforms. Closes #2085. Fixes #2079

This commit is contained in:
dmiller
2020-07-19 05:00:13 +00:00
parent 3421d01d2e
commit 05763b620d
3 changed files with 22 additions and 12 deletions

View File

@@ -93,13 +93,14 @@ static int netutils_debugging = 0;
* process and return that maximum value (note -- you better not actually open
* this many -- stdin, stdout, other files opened by libraries you use, etc. all
* count toward this limit. Leave a little slack */
int maximize_fdlimit(void) {
rlim_t maximize_fdlimit(void) {
#ifndef WIN32
struct rlimit r;
static int maxfds = -1;
static int maxfds_set = 0;
static rlim_t maxfds = 0;
if (maxfds > 0)
if (maxfds_set)
return maxfds;
#ifndef RLIMIT_NOFILE
@@ -110,17 +111,17 @@ int maximize_fdlimit(void) {
#endif
#endif
if (!getrlimit(RLIMIT_NOFILE, &r)) {
maxfds = r.rlim_cur;
r.rlim_cur = r.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &r))
if (!setrlimit(RLIMIT_NOFILE, &r))
if (netutils_debugging)
perror("setrlimit RLIMIT_NOFILE failed");
if (!getrlimit(RLIMIT_NOFILE, &r)) {
maxfds = r.rlim_cur;
return maxfds;
} else {
return 0;
}
maxfds_set = 1;
return maxfds;
}
#endif /* !WIN32 */
return 0;