mirror of
https://github.com/moparisthebest/curl
synced 2024-08-13 17:03:50 -04:00
fix comments and renumber rlimit return codes
fix closing of fd's when limit is reached
This commit is contained in:
parent
426ecfd136
commit
1dee2cd55e
@ -169,8 +169,11 @@ static int rlimit(int keep_open)
|
|||||||
/*
|
/*
|
||||||
* test 537 is all about testing libcurl functionality
|
* test 537 is all about testing libcurl functionality
|
||||||
* when the system has nearly exhausted the number of
|
* when the system has nearly exhausted the number of
|
||||||
* free file descriptors. Test 537 will try to run with
|
* available file descriptors. Test 537 will try to run
|
||||||
* very few free file descriptors.
|
* with a very small number of file descriptors available.
|
||||||
|
* This implies that any file descriptor which is open
|
||||||
|
* when the test runs will have a number in the high range
|
||||||
|
* of whatever the system supports.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -191,7 +194,7 @@ static int rlimit(int keep_open)
|
|||||||
if (!memchunk) {
|
if (!memchunk) {
|
||||||
store_errmsg("memchunk, malloc() failed", our_errno());
|
store_errmsg("memchunk, malloc() failed", our_errno());
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
return -7;
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize it to fight lazy allocation */
|
/* initialize it to fight lazy allocation */
|
||||||
@ -210,7 +213,7 @@ static int rlimit(int keep_open)
|
|||||||
num_open.rlim_max = rl.rlim_cur - SAFETY_MARGIN;
|
num_open.rlim_max = rl.rlim_cur - SAFETY_MARGIN;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* biggest file descriptor array size */
|
/* a huge number of file descriptors */
|
||||||
num_open.rlim_max = INT_MAX / sizeof(*fd);
|
num_open.rlim_max = INT_MAX / sizeof(*fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,7 +226,7 @@ static int rlimit(int keep_open)
|
|||||||
store_errmsg(strbuff, 0);
|
store_errmsg(strbuff, 0);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
free(memchunk);
|
free(memchunk);
|
||||||
return -8;
|
return -5;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate array for file descriptors */
|
/* allocate array for file descriptors */
|
||||||
@ -241,7 +244,7 @@ static int rlimit(int keep_open)
|
|||||||
store_errmsg("fd, malloc() failed", our_errno());
|
store_errmsg("fd, malloc() failed", our_errno());
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
free(memchunk);
|
free(memchunk);
|
||||||
return -9;
|
return -6;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize it to fight lazy allocation */
|
/* initialize it to fight lazy allocation */
|
||||||
@ -264,7 +267,7 @@ static int rlimit(int keep_open)
|
|||||||
free(fd);
|
free(fd);
|
||||||
fd = NULL;
|
fd = NULL;
|
||||||
free(memchunk);
|
free(memchunk);
|
||||||
return -10;
|
return -7;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* create a bunch of file descriptors */
|
/* create a bunch of file descriptors */
|
||||||
@ -283,16 +286,15 @@ static int rlimit(int keep_open)
|
|||||||
sprintf(strbuff, "dup() attempt %s failed", strbuff1);
|
sprintf(strbuff, "dup() attempt %s failed", strbuff1);
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
|
||||||
sprintf(strbuff1, fmt, num_open.rlim_cur + 2);
|
sprintf(strbuff1, fmt, num_open.rlim_cur);
|
||||||
sprintf(strbuff, "system does not support opening "
|
sprintf(strbuff, "fd system limit seems close to %s", strbuff1);
|
||||||
"more than %s files" , strbuff1);
|
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
|
||||||
num_open.rlim_max = num_open.rlim_cur + 2 - SAFETY_MARGIN;
|
num_open.rlim_max = num_open.rlim_cur - SAFETY_MARGIN;
|
||||||
|
|
||||||
num_open.rlim_cur -= num_open.rlim_max;
|
num_open.rlim_cur -= num_open.rlim_max;
|
||||||
sprintf(strbuff1, fmt, num_open.rlim_cur);
|
sprintf(strbuff1, fmt, num_open.rlim_cur);
|
||||||
sprintf(strbuff, "closing %s files", strbuff1);
|
sprintf(strbuff, "closing %s file descriptors", strbuff1);
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
|
||||||
for (num_open.rlim_cur = num_open.rlim_max;
|
for (num_open.rlim_cur = num_open.rlim_max;
|
||||||
@ -305,17 +307,16 @@ static int rlimit(int keep_open)
|
|||||||
sprintf(strbuff, fmt, num_open.rlim_max);
|
sprintf(strbuff, fmt, num_open.rlim_max);
|
||||||
fprintf(stderr, "shrinking array for %s file descriptors\n", strbuff);
|
fprintf(stderr, "shrinking array for %s file descriptors\n", strbuff);
|
||||||
|
|
||||||
|
/* we don't care if we can't shrink it */
|
||||||
|
|
||||||
tmpfd = realloc(fd, sizeof(*fd) * (size_t)(num_open.rlim_max));
|
tmpfd = realloc(fd, sizeof(*fd) * (size_t)(num_open.rlim_max));
|
||||||
if (!tmpfd) {
|
if (tmpfd) {
|
||||||
sprintf(strbuff, "fd, realloc() failed, "
|
|
||||||
"errno %d, %s", our_errno(), strerror(our_errno()));
|
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
fd = tmpfd;
|
fd = tmpfd;
|
||||||
tmpfd = NULL;
|
tmpfd = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -329,6 +330,7 @@ static int rlimit(int keep_open)
|
|||||||
free(memchunk);
|
free(memchunk);
|
||||||
|
|
||||||
/* close file descriptors unless instructed to keep them */
|
/* close file descriptors unless instructed to keep them */
|
||||||
|
|
||||||
if (!keep_open) {
|
if (!keep_open) {
|
||||||
close_file_descriptors();
|
close_file_descriptors();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user