mirror of
https://github.com/curl/curl.git
synced 2025-09-14 08:02:44 +03:00
build: delete/replace 3 more clang warning pragmas
- tool_msgs: delete redundant `-Wformat-nonliteral` suppression pragma. - whitespace formatting in `mprintf.h`, lib518, lib537. - lib518: fix wrong variable in `sizeof()`. - lib518: bump variables to `rlim_t`. Follow-up toe2b394106d
#1469 - lib518: sync error message with lib537 Follow-up to365322b8bc
- lib518, lib537: replace `-Wformat-nonliteral` suppression pragmas by reworking test code. Follow-up to5b286c2508
#12812 Follow-up toaee4ebe591
#12803 Follow-up to0923012758
#12540 Follow-up to3829759bd0
#12489 Reviewed-by: Daniel Stenberg Closes #12814
This commit is contained in:
parent
0f4c19b66a
commit
cb343182b7
|
@ -46,13 +46,15 @@ extern "C" {
|
||||||
#define CURL_TEMP_PRINTF(fmt, arg)
|
#define CURL_TEMP_PRINTF(fmt, arg)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
CURL_EXTERN int curl_mprintf(const char *format, ...) CURL_TEMP_PRINTF(1, 2);
|
CURL_EXTERN int curl_mprintf(const char *format, ...)
|
||||||
|
CURL_TEMP_PRINTF(1, 2);
|
||||||
CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...)
|
CURL_EXTERN int curl_mfprintf(FILE *fd, const char *format, ...)
|
||||||
CURL_TEMP_PRINTF(2, 3);
|
CURL_TEMP_PRINTF(2, 3);
|
||||||
CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...)
|
CURL_EXTERN int curl_msprintf(char *buffer, const char *format, ...)
|
||||||
CURL_TEMP_PRINTF(2, 3);
|
CURL_TEMP_PRINTF(2, 3);
|
||||||
CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength,
|
CURL_EXTERN int curl_msnprintf(char *buffer, size_t maxlength,
|
||||||
const char *format, ...) CURL_TEMP_PRINTF(3, 4);
|
const char *format, ...)
|
||||||
|
CURL_TEMP_PRINTF(3, 4);
|
||||||
CURL_EXTERN int curl_mvprintf(const char *format, va_list args)
|
CURL_EXTERN int curl_mvprintf(const char *format, va_list args)
|
||||||
CURL_TEMP_PRINTF(1, 0);
|
CURL_TEMP_PRINTF(1, 0);
|
||||||
CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args)
|
CURL_EXTERN int curl_mvfprintf(FILE *fd, const char *format, va_list args)
|
||||||
|
|
|
@ -124,14 +124,7 @@ void helpf(FILE *errors, const char *fmt, ...)
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
DEBUGASSERT(!strchr(fmt, '\n'));
|
DEBUGASSERT(!strchr(fmt, '\n'));
|
||||||
fputs("curl: ", errors); /* prefix it */
|
fputs("curl: ", errors); /* prefix it */
|
||||||
#ifdef __clang__
|
|
||||||
#pragma clang diagnostic push
|
|
||||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
|
||||||
#endif
|
|
||||||
vfprintf(errors, fmt, ap);
|
vfprintf(errors, fmt, ap);
|
||||||
#ifdef __clang__
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
fputs("\n", errors); /* newline it */
|
fputs("\n", errors); /* newline it */
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,30 +99,35 @@ static int fopen_works(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
static void rlim2str(char *buf, size_t len, rlim_t val)
|
||||||
#pragma clang diagnostic push
|
{
|
||||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
#ifdef RLIM_INFINITY
|
||||||
|
if(val == RLIM_INFINITY) {
|
||||||
|
msnprintf(buf, len, "INFINITY");
|
||||||
|
return;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_LONGLONG
|
||||||
|
if(sizeof(rlim_t) > sizeof(long))
|
||||||
|
msnprintf(buf, len, "%llu", (unsigned long long)val);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if(sizeof(rlim_t) < sizeof(long))
|
||||||
|
msnprintf(buf, len, "%u", (unsigned int)val);
|
||||||
|
else
|
||||||
|
msnprintf(buf, len, "%lu", (unsigned long)val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int rlimit(int keep_open)
|
static int rlimit(int keep_open)
|
||||||
{
|
{
|
||||||
int nitems, i;
|
rlim_t nitems, i;
|
||||||
int *memchunk = NULL;
|
int *memchunk = NULL;
|
||||||
char *fmt;
|
|
||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
char strbuff[256];
|
char strbuff[256];
|
||||||
char strbuff1[81];
|
char strbuff1[81];
|
||||||
char strbuff2[81];
|
char strbuff2[81];
|
||||||
char fmt_u[] = "%u";
|
|
||||||
char fmt_lu[] = "%lu";
|
|
||||||
#ifdef HAVE_LONGLONG
|
|
||||||
char fmt_llu[] = "%llu";
|
|
||||||
|
|
||||||
if(sizeof(rl.rlim_max) > sizeof(long))
|
|
||||||
fmt = fmt_llu;
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
fmt = (sizeof(rl.rlim_max) < sizeof(long))?fmt_u:fmt_lu;
|
|
||||||
|
|
||||||
/* get initial open file limits */
|
/* get initial open file limits */
|
||||||
|
|
||||||
|
@ -134,20 +139,10 @@ static int rlimit(int keep_open)
|
||||||
|
|
||||||
/* show initial open file limits */
|
/* show initial open file limits */
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_cur);
|
||||||
if(rl.rlim_cur == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
|
|
||||||
fprintf(stderr, "initial soft limit: %s\n", strbuff);
|
fprintf(stderr, "initial soft limit: %s\n", strbuff);
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_max);
|
||||||
if(rl.rlim_max == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
|
|
||||||
fprintf(stderr, "initial hard limit: %s\n", strbuff);
|
fprintf(stderr, "initial hard limit: %s\n", strbuff);
|
||||||
|
|
||||||
/* show our constants */
|
/* show our constants */
|
||||||
|
@ -200,20 +195,10 @@ static int rlimit(int keep_open)
|
||||||
|
|
||||||
/* show current open file limits */
|
/* show current open file limits */
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_cur);
|
||||||
if(rl.rlim_cur == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
|
|
||||||
fprintf(stderr, "current soft limit: %s\n", strbuff);
|
fprintf(stderr, "current soft limit: %s\n", strbuff);
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_max);
|
||||||
if(rl.rlim_max == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
|
|
||||||
fprintf(stderr, "current hard limit: %s\n", strbuff);
|
fprintf(stderr, "current hard limit: %s\n", strbuff);
|
||||||
|
|
||||||
} /* (rl.rlim_cur != rl.rlim_max) */
|
} /* (rl.rlim_cur != rl.rlim_max) */
|
||||||
|
@ -240,8 +225,8 @@ static int rlimit(int keep_open)
|
||||||
(rl.rlim_cur != RLIM_INFINITY) &&
|
(rl.rlim_cur != RLIM_INFINITY) &&
|
||||||
#endif
|
#endif
|
||||||
(rl.rlim_cur <= num_open.rlim_cur)) {
|
(rl.rlim_cur <= num_open.rlim_cur)) {
|
||||||
msnprintf(strbuff2, sizeof(strbuff2), fmt, rl.rlim_cur);
|
rlim2str(strbuff2, sizeof(strbuff2), rl.rlim_cur);
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s",
|
msnprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s",
|
||||||
strbuff1, strbuff2);
|
strbuff1, strbuff2);
|
||||||
store_errmsg(strbuff, 0);
|
store_errmsg(strbuff, 0);
|
||||||
|
@ -263,8 +248,8 @@ static int rlimit(int keep_open)
|
||||||
if(nitems > 0x7fff)
|
if(nitems > 0x7fff)
|
||||||
nitems = 0x40000;
|
nitems = 0x40000;
|
||||||
do {
|
do {
|
||||||
num_open.rlim_max = sizeof(*memchunk) * (size_t)nitems;
|
num_open.rlim_max = sizeof(*memchunk) * nitems;
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
fprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
|
fprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
|
||||||
memchunk = malloc(sizeof(*memchunk) * (size_t)nitems);
|
memchunk = malloc(sizeof(*memchunk) * (size_t)nitems);
|
||||||
if(!memchunk) {
|
if(!memchunk) {
|
||||||
|
@ -292,7 +277,7 @@ static int rlimit(int keep_open)
|
||||||
/* verify that we won't overflow size_t in malloc() */
|
/* verify that we won't overflow size_t in malloc() */
|
||||||
|
|
||||||
if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) {
|
if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) {
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_max);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s "
|
msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s "
|
||||||
"file descriptors, would overflow size_t", strbuff1);
|
"file descriptors, would overflow size_t", strbuff1);
|
||||||
store_errmsg(strbuff, 0);
|
store_errmsg(strbuff, 0);
|
||||||
|
@ -303,7 +288,7 @@ static int rlimit(int keep_open)
|
||||||
|
|
||||||
/* allocate array for file descriptors */
|
/* allocate array for file descriptors */
|
||||||
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
fprintf(stderr, "allocating array for %s file descriptors\n", strbuff);
|
fprintf(stderr, "allocating array for %s file descriptors\n", strbuff);
|
||||||
|
|
||||||
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
|
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
|
||||||
|
@ -323,7 +308,7 @@ static int rlimit(int keep_open)
|
||||||
num_open.rlim_cur++)
|
num_open.rlim_cur++)
|
||||||
fd[num_open.rlim_cur] = -1;
|
fd[num_open.rlim_cur] = -1;
|
||||||
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
fprintf(stderr, "trying to open %s file descriptors\n", strbuff);
|
fprintf(stderr, "trying to open %s file descriptors\n", strbuff);
|
||||||
|
|
||||||
/* open a dummy descriptor */
|
/* open a dummy descriptor */
|
||||||
|
@ -351,19 +336,19 @@ static int rlimit(int keep_open)
|
||||||
|
|
||||||
fd[num_open.rlim_cur] = -1;
|
fd[num_open.rlim_cur] = -1;
|
||||||
|
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
|
msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
|
||||||
msnprintf(strbuff1, sizeof(strbuff), fmt, num_open.rlim_cur);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s",
|
msnprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s",
|
||||||
strbuff1);
|
strbuff1);
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
|
||||||
num_open.rlim_max = NUM_NEEDED;
|
num_open.rlim_max = NUM_NEEDED;
|
||||||
|
|
||||||
msnprintf(strbuff2, sizeof(strbuff2), fmt, num_open.rlim_max);
|
rlim2str(strbuff2, sizeof(strbuff2), num_open.rlim_max);
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s",
|
msnprintf(strbuff, sizeof(strbuff), "fds needed %s > system limit %s",
|
||||||
strbuff2, strbuff1);
|
strbuff2, strbuff1);
|
||||||
store_errmsg(strbuff, 0);
|
store_errmsg(strbuff, 0);
|
||||||
|
@ -377,12 +362,10 @@ static int rlimit(int keep_open)
|
||||||
fd = NULL;
|
fd = NULL;
|
||||||
free(memchunk);
|
free(memchunk);
|
||||||
return -9;
|
return -9;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
|
||||||
fprintf(stderr, "%s file descriptors open\n", strbuff);
|
fprintf(stderr, "%s file descriptors open\n", strbuff);
|
||||||
|
|
||||||
#if !defined(HAVE_POLL_FINE) && !defined(USE_WINSOCK)
|
#if !defined(HAVE_POLL_FINE) && !defined(USE_WINSOCK)
|
||||||
|
@ -437,13 +420,11 @@ static int rlimit(int keep_open)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(!fopen_works()) {
|
if(!fopen_works()) {
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_max);
|
||||||
msnprintf(strbuff, sizeof(strbuff),
|
msnprintf(strbuff, sizeof(strbuff), "fopen fails with %s fds open",
|
||||||
"fopen fails with %s fds open()",
|
|
||||||
strbuff1);
|
strbuff1);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
msnprintf(strbuff, sizeof(strbuff),
|
msnprintf(strbuff, sizeof(strbuff), "fopen fails with lots of fds open");
|
||||||
"fopen fails with lots of fds open()");
|
|
||||||
store_errmsg(strbuff, 0);
|
store_errmsg(strbuff, 0);
|
||||||
close_file_descriptors();
|
close_file_descriptors();
|
||||||
free(memchunk);
|
free(memchunk);
|
||||||
|
@ -464,10 +445,6 @@ static int rlimit(int keep_open)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int test(char *URL)
|
int test(char *URL)
|
||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|
|
@ -59,8 +59,8 @@ static void store_errmsg(const char *msg, int err)
|
||||||
if(!err)
|
if(!err)
|
||||||
msnprintf(msgbuff, sizeof(msgbuff), "%s", msg);
|
msnprintf(msgbuff, sizeof(msgbuff), "%s", msg);
|
||||||
else
|
else
|
||||||
msnprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg, err,
|
msnprintf(msgbuff, sizeof(msgbuff), "%s, errno %d, %s", msg,
|
||||||
strerror(err));
|
err, strerror(err));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_file_descriptors(void)
|
static void close_file_descriptors(void)
|
||||||
|
@ -99,30 +99,35 @@ static int fopen_works(void)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
static void rlim2str(char *buf, size_t len, rlim_t val)
|
||||||
#pragma clang diagnostic push
|
{
|
||||||
#pragma clang diagnostic ignored "-Wformat-nonliteral"
|
#ifdef RLIM_INFINITY
|
||||||
|
if(val == RLIM_INFINITY) {
|
||||||
|
msnprintf(buf, len, "INFINITY");
|
||||||
|
return;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_LONGLONG
|
||||||
|
if(sizeof(rlim_t) > sizeof(long))
|
||||||
|
msnprintf(buf, len, "%llu", (unsigned long long)val);
|
||||||
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
if(sizeof(rlim_t) < sizeof(long))
|
||||||
|
msnprintf(buf, len, "%u", (unsigned int)val);
|
||||||
|
else
|
||||||
|
msnprintf(buf, len, "%lu", (unsigned long)val);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int rlimit(int keep_open)
|
static int rlimit(int keep_open)
|
||||||
{
|
{
|
||||||
int *tmpfd;
|
int *tmpfd;
|
||||||
rlim_t nitems, i;
|
rlim_t nitems, i;
|
||||||
int *memchunk = NULL;
|
int *memchunk = NULL;
|
||||||
char *fmt;
|
|
||||||
struct rlimit rl;
|
struct rlimit rl;
|
||||||
char strbuff[256];
|
char strbuff[256];
|
||||||
char strbuff1[81];
|
char strbuff1[81];
|
||||||
char fmt_u[] = "%u";
|
|
||||||
char fmt_lu[] = "%lu";
|
|
||||||
#ifdef HAVE_LONGLONG
|
|
||||||
char fmt_llu[] = "%llu";
|
|
||||||
|
|
||||||
if(sizeof(rl.rlim_max) > sizeof(long))
|
|
||||||
fmt = fmt_llu;
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
fmt = (sizeof(rl.rlim_max) < sizeof(long))?fmt_u:fmt_lu;
|
|
||||||
|
|
||||||
/* get initial open file limits */
|
/* get initial open file limits */
|
||||||
|
|
||||||
|
@ -134,20 +139,10 @@ static int rlimit(int keep_open)
|
||||||
|
|
||||||
/* show initial open file limits */
|
/* show initial open file limits */
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_cur);
|
||||||
if(rl.rlim_cur == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
|
|
||||||
fprintf(stderr, "initial soft limit: %s\n", strbuff);
|
fprintf(stderr, "initial soft limit: %s\n", strbuff);
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_max);
|
||||||
if(rl.rlim_max == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
|
|
||||||
fprintf(stderr, "initial hard limit: %s\n", strbuff);
|
fprintf(stderr, "initial hard limit: %s\n", strbuff);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -194,20 +189,10 @@ static int rlimit(int keep_open)
|
||||||
|
|
||||||
/* show current open file limits */
|
/* show current open file limits */
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_cur);
|
||||||
if(rl.rlim_cur == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_cur);
|
|
||||||
fprintf(stderr, "current soft limit: %s\n", strbuff);
|
fprintf(stderr, "current soft limit: %s\n", strbuff);
|
||||||
|
|
||||||
#ifdef RLIM_INFINITY
|
rlim2str(strbuff, sizeof(strbuff), rl.rlim_max);
|
||||||
if(rl.rlim_max == RLIM_INFINITY)
|
|
||||||
strcpy(strbuff, "INFINITY");
|
|
||||||
else
|
|
||||||
#endif
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, rl.rlim_max);
|
|
||||||
fprintf(stderr, "current hard limit: %s\n", strbuff);
|
fprintf(stderr, "current hard limit: %s\n", strbuff);
|
||||||
|
|
||||||
} /* (rl.rlim_cur != rl.rlim_max) */
|
} /* (rl.rlim_cur != rl.rlim_max) */
|
||||||
|
@ -237,7 +222,7 @@ static int rlimit(int keep_open)
|
||||||
nitems = 0x40000;
|
nitems = 0x40000;
|
||||||
do {
|
do {
|
||||||
num_open.rlim_max = sizeof(*memchunk) * nitems;
|
num_open.rlim_max = sizeof(*memchunk) * nitems;
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
fprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
|
fprintf(stderr, "allocating memchunk %s byte array\n", strbuff);
|
||||||
memchunk = malloc(sizeof(*memchunk) * (size_t)nitems);
|
memchunk = malloc(sizeof(*memchunk) * (size_t)nitems);
|
||||||
if(!memchunk) {
|
if(!memchunk) {
|
||||||
|
@ -280,7 +265,7 @@ static int rlimit(int keep_open)
|
||||||
/* verify that we won't overflow size_t in malloc() */
|
/* verify that we won't overflow size_t in malloc() */
|
||||||
|
|
||||||
if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) {
|
if((size_t)(num_open.rlim_max) > ((size_t)-1) / sizeof(*fd)) {
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_max);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s "
|
msnprintf(strbuff, sizeof(strbuff), "unable to allocate an array for %s "
|
||||||
"file descriptors, would overflow size_t", strbuff1);
|
"file descriptors, would overflow size_t", strbuff1);
|
||||||
store_errmsg(strbuff, 0);
|
store_errmsg(strbuff, 0);
|
||||||
|
@ -292,8 +277,9 @@ static int rlimit(int keep_open)
|
||||||
/* allocate array for file descriptors */
|
/* allocate array for file descriptors */
|
||||||
|
|
||||||
do {
|
do {
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
fprintf(stderr, "allocating array for %s file descriptors\n", strbuff);
|
fprintf(stderr, "allocating array for %s file descriptors\n", strbuff);
|
||||||
|
|
||||||
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
|
fd = malloc(sizeof(*fd) * (size_t)(num_open.rlim_max));
|
||||||
if(!fd) {
|
if(!fd) {
|
||||||
fprintf(stderr, "fd, malloc() failed\n");
|
fprintf(stderr, "fd, malloc() failed\n");
|
||||||
|
@ -316,7 +302,7 @@ static int rlimit(int keep_open)
|
||||||
num_open.rlim_cur++)
|
num_open.rlim_cur++)
|
||||||
fd[num_open.rlim_cur] = -1;
|
fd[num_open.rlim_cur] = -1;
|
||||||
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
fprintf(stderr, "trying to open %s file descriptors\n", strbuff);
|
fprintf(stderr, "trying to open %s file descriptors\n", strbuff);
|
||||||
|
|
||||||
/* open a dummy descriptor */
|
/* open a dummy descriptor */
|
||||||
|
@ -344,11 +330,11 @@ static int rlimit(int keep_open)
|
||||||
|
|
||||||
fd[num_open.rlim_cur] = -1;
|
fd[num_open.rlim_cur] = -1;
|
||||||
|
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
|
msnprintf(strbuff, sizeof(strbuff), "dup() attempt %s failed", strbuff1);
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s",
|
msnprintf(strbuff, sizeof(strbuff), "fds system limit seems close to %s",
|
||||||
strbuff1);
|
strbuff1);
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
@ -356,7 +342,7 @@ static int rlimit(int keep_open)
|
||||||
num_open.rlim_max = num_open.rlim_cur - 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;
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_cur);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_cur);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "closing %s file descriptors",
|
msnprintf(strbuff, sizeof(strbuff), "closing %s file descriptors",
|
||||||
strbuff1);
|
strbuff1);
|
||||||
fprintf(stderr, "%s\n", strbuff);
|
fprintf(stderr, "%s\n", strbuff);
|
||||||
|
@ -368,7 +354,7 @@ static int rlimit(int keep_open)
|
||||||
fd[num_open.rlim_cur] = -1;
|
fd[num_open.rlim_cur] = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
rlim2str(strbuff, sizeof(strbuff), 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 */
|
/* we don't care if we can't shrink it */
|
||||||
|
@ -380,12 +366,10 @@ static int rlimit(int keep_open)
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
rlim2str(strbuff, sizeof(strbuff), num_open.rlim_max);
|
||||||
|
|
||||||
msnprintf(strbuff, sizeof(strbuff), fmt, num_open.rlim_max);
|
|
||||||
fprintf(stderr, "%s file descriptors open\n", strbuff);
|
fprintf(stderr, "%s file descriptors open\n", strbuff);
|
||||||
|
|
||||||
#if !defined(HAVE_POLL_FINE) && !defined(USE_WINSOCK)
|
#if !defined(HAVE_POLL_FINE) && !defined(USE_WINSOCK)
|
||||||
|
@ -440,7 +424,7 @@ static int rlimit(int keep_open)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if(!fopen_works()) {
|
if(!fopen_works()) {
|
||||||
msnprintf(strbuff1, sizeof(strbuff1), fmt, num_open.rlim_max);
|
rlim2str(strbuff1, sizeof(strbuff1), num_open.rlim_max);
|
||||||
msnprintf(strbuff, sizeof(strbuff), "fopen fails with %s fds open",
|
msnprintf(strbuff, sizeof(strbuff), "fopen fails with %s fds open",
|
||||||
strbuff1);
|
strbuff1);
|
||||||
fprintf(stderr, "%s\n", msgbuff);
|
fprintf(stderr, "%s\n", msgbuff);
|
||||||
|
@ -465,10 +449,6 @@ static int rlimit(int keep_open)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
|
||||||
#pragma clang diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
int test(char *URL)
|
int test(char *URL)
|
||||||
{
|
{
|
||||||
CURLcode res;
|
CURLcode res;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user