diff options
author | Stefan Fritsch <sf@sfritsch.de> | 2014-03-29 21:56:19 +0100 |
---|---|---|
committer | Stefan Fritsch <sf@sfritsch.de> | 2014-03-29 21:56:45 +0100 |
commit | 2a463b3cd73c32ee9dcd508248d0194923f435f4 (patch) | |
tree | 2ff478255a77a55031056790918b6f983bb7b20a /support | |
parent | 86d5cc79d9d6750da8771fdb0c9ab22c19b8ad45 (diff) | |
download | apache2-2a463b3cd73c32ee9dcd508248d0194923f435f4.tar.gz |
Imported Upstream version 2.4.9upstream/2.4.9
Diffstat (limited to 'support')
-rw-r--r-- | support/ab.c | 72 | ||||
-rw-r--r-- | support/apxs.in | 1 | ||||
-rw-r--r-- | support/htcacheclean.c | 44 |
3 files changed, 69 insertions, 48 deletions
diff --git a/support/ab.c b/support/ab.c index e2d19b9b..13041505 100644 --- a/support/ab.c +++ b/support/ab.c @@ -392,6 +392,48 @@ static void apr_err(const char *s, apr_status_t rv) exit(rv); } +static void *xmalloc(size_t size) +{ + void *ret = malloc(size); + if (ret == NULL) { + fprintf(stderr, "Could not allocate memory (%" + APR_SIZE_T_FMT" bytes)\n", size); + exit(1); + } + return ret; +} + +static void *xcalloc(size_t num, size_t size) +{ + void *ret = calloc(num, size); + if (ret == NULL) { + fprintf(stderr, "Could not allocate memory (%" + APR_SIZE_T_FMT" bytes)\n", size*num); + exit(1); + } + return ret; +} + +static char *xstrdup(const char *s) +{ + char *ret = strdup(s); + if (ret == NULL) { + fprintf(stderr, "Could not allocate memory (%" + APR_SIZE_T_FMT " bytes)\n", strlen(s)); + exit(1); + } + return ret; +} + +/* pool abort function */ +static int abort_on_oom(int retcode) +{ + fprintf(stderr, "Could not allocate memory\n"); + exit(1); + /* not reached */ + return retcode; +} + static void set_polled_events(struct connection *c, apr_int16_t new_reqevents) { apr_status_t rv; @@ -625,7 +667,7 @@ static void ssl_proceed_handshake(struct connection *c) else pk_bits = 0; /* Anon DH */ - ssl_info = malloc(128); + ssl_info = xmalloc(128); apr_snprintf(ssl_info, 128, "%s,%s,%d,%d", SSL_get_version(c->ssl), SSL_CIPHER_get_name(ci), @@ -1608,16 +1650,13 @@ static void test(void) fflush(stdout); } - con = calloc(concurrency, sizeof(struct connection)); + con = xcalloc(concurrency, sizeof(struct connection)); /* * XXX: a way to calculate the stats without requiring O(requests) memory * XXX: would be nice. */ - stats = calloc(requests, sizeof(struct data)); - if (stats == NULL || con == NULL) { - err("Cannot allocate memory for result statistics"); - } + stats = xcalloc(requests, sizeof(struct data)); if ((status = apr_pollset_create(&readbits, concurrency, cntxt, APR_POLLSET_NOCOPY)) != APR_SUCCESS) { @@ -1689,11 +1728,7 @@ static void test(void) * Combine headers and (optional) post file into one continuous buffer */ if (send_body) { - char *buff = malloc(postlen + reqlen + 1); - if (!buff) { - fprintf(stderr, "error creating request buffer: out of memory\n"); - return; - } + char *buff = xmalloc(postlen + reqlen + 1); strcpy(buff, request); memcpy(buff + reqlen, postdata, postlen); request = buff; @@ -1853,14 +1888,14 @@ static void test(void) static void copyright(void) { if (!use_html) { - printf("This is ApacheBench, Version %s\n", AP_AB_BASEREVISION " <$Revision: 1528965 $>"); + printf("This is ApacheBench, Version %s\n", AP_AB_BASEREVISION " <$Revision: 1554214 $>"); printf("Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/\n"); printf("Licensed to The Apache Software Foundation, http://www.apache.org/\n"); printf("\n"); } else { printf("<p>\n"); - printf(" This is ApacheBench, Version %s <i><%s></i><br>\n", AP_AB_BASEREVISION, "$Revision: 1528965 $"); + printf(" This is ApacheBench, Version %s <i><%s></i><br>\n", AP_AB_BASEREVISION, "$Revision: 1554214 $"); printf(" Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/<br>\n"); printf(" Licensed to The Apache Software Foundation, http://www.apache.org/<br>\n"); printf("</p>\n<p>\n"); @@ -2031,11 +2066,7 @@ static apr_status_t open_postfile(const char *pfile) return rv; } postlen = (apr_size_t)finfo.size; - postdata = malloc(postlen); - if (!postdata) { - fprintf(stderr, "ab: Could not allocate POST data buffer\n"); - return APR_ENOMEM; - } + postdata = xmalloc(postlen); rv = apr_file_read_full(postfd, postdata, postlen, NULL); if (rv != APR_SUCCESS) { fprintf(stderr, "ab: Could not read POST data file: %s\n", @@ -2073,6 +2104,7 @@ int main(int argc, const char * const argv[]) apr_app_initialize(&argc, &argv, NULL); atexit(apr_terminate); apr_pool_create(&cntxt, NULL); + apr_pool_abort_set(abort_on_oom, cntxt); #ifdef NOT_ASCII status = apr_xlate_open(&to_ascii, "ISO-8859-1", APR_DEFAULT_CHARSET, cntxt); @@ -2125,13 +2157,13 @@ int main(int argc, const char * const argv[]) method = HEAD; break; case 'g': - gnuplot = strdup(opt_arg); + gnuplot = xstrdup(opt_arg); break; case 'd': percentile = 0; break; case 'e': - csvperc = strdup(opt_arg); + csvperc = xstrdup(opt_arg); break; case 'S': confidence = 0; diff --git a/support/apxs.in b/support/apxs.in index 8bdc2dac..ad1287ff 100644 --- a/support/apxs.in +++ b/support/apxs.in @@ -676,7 +676,6 @@ top_builddir=%PREFIX% include %INSTALLBUILDDIR%/special.mk # the used tools -APXS=apxs APACHECTL=apachectl # additional defines, includes and libraries diff --git a/support/htcacheclean.c b/support/htcacheclean.c index 4150936f..92d09e18 100644 --- a/support/htcacheclean.c +++ b/support/htcacheclean.c @@ -1087,9 +1087,8 @@ static apr_status_t remove_directory(apr_pool_t *pool, const char *dir) return rv; } if (rv != APR_SUCCESS) { - char errmsg[120]; - apr_file_printf(errfile, "Could not open directory %s: %s" APR_EOL_STR, - dir, apr_strerror(rv, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not open directory %s: %pm" APR_EOL_STR, + dir, &rv); return rv; } @@ -1110,10 +1109,9 @@ static apr_status_t remove_directory(apr_pool_t *pool, const char *dir) const char *file = apr_pstrcat(pool, dir, "/", dirent.name, NULL); rv = apr_file_remove(file, pool); if (APR_SUCCESS != rv) { - char errmsg[120]; apr_file_printf(errfile, - "Could not remove file '%s': %s" APR_EOL_STR, file, - apr_strerror(rv, errmsg, sizeof errmsg)); + "Could not remove file '%s': %pm" APR_EOL_STR, file, + &rv); break; } } @@ -1127,9 +1125,8 @@ static apr_status_t remove_directory(apr_pool_t *pool, const char *dir) rv = APR_SUCCESS; } if (rv != APR_SUCCESS) { - char errmsg[120]; - apr_file_printf(errfile, "Could not remove directory %s: %s" APR_EOL_STR, - dir, apr_strerror(rv, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not remove directory %s: %pm" APR_EOL_STR, + dir, &rv); } } @@ -1151,9 +1148,8 @@ static apr_status_t find_directory(apr_pool_t *pool, const char *base, rv = apr_dir_open(&dirp, base, pool); if (rv != APR_SUCCESS) { - char errmsg[120]; - apr_file_printf(errfile, "Could not open directory %s: %s" APR_EOL_STR, - base, apr_strerror(rv, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not open directory %s: %pm" APR_EOL_STR, + base, &rv); return rv; } @@ -1194,18 +1190,16 @@ static apr_status_t find_directory(apr_pool_t *pool, const char *base, remove = apr_pstrcat(pool, base, "/", header, NULL); status = apr_file_remove(remove, pool); if (status != APR_SUCCESS && !APR_STATUS_IS_ENOENT(status)) { - char errmsg[120]; - apr_file_printf(errfile, "Could not remove file %s: %s" APR_EOL_STR, - remove, apr_strerror(status, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not remove file %s: %pm" APR_EOL_STR, + remove, &status); rv = status; } remove = apr_pstrcat(pool, base, "/", data, NULL); status = apr_file_remove(remove, pool); if (status != APR_SUCCESS && !APR_STATUS_IS_ENOENT(status)) { - char errmsg[120]; - apr_file_printf(errfile, "Could not remove file %s: %s" APR_EOL_STR, - remove, apr_strerror(status, errmsg, sizeof errmsg)); + apr_file_printf(errfile, "Could not remove file %s: %pm" APR_EOL_STR, + remove, &status); rv = status; } @@ -1357,7 +1351,6 @@ static void usage_repeated_arg(apr_pool_t *pool, char option) { static void log_pid(apr_pool_t *pool, const char *pidfilename, apr_file_t **pidfile) { apr_status_t status; - char errmsg[120]; pid_t mypid = getpid(); if (APR_SUCCESS == (status = apr_file_open(pidfile, pidfilename, @@ -1369,9 +1362,8 @@ static void log_pid(apr_pool_t *pool, const char *pidfilename, apr_file_t **pidf else { if (errfile) { apr_file_printf(errfile, - "Could not write the pid file '%s': %s" APR_EOL_STR, - pidfilename, - apr_strerror(status, errmsg, sizeof errmsg)); + "Could not write the pid file '%s': %pm" APR_EOL_STR, + pidfilename, &status); } exit(1); } @@ -1393,7 +1385,6 @@ int main(int argc, const char * const argv[]) char opt; const char *arg; char *proxypath, *path, *pidfilename; - char errmsg[1024]; interrupted = 0; repeat = 0; @@ -1579,8 +1570,8 @@ int main(int argc, const char * const argv[]) } proxypath = apr_pstrdup(pool, arg); if ((status = apr_filepath_set(proxypath, pool)) != APR_SUCCESS) { - usage(apr_psprintf(pool, "Could not set filepath to '%s': %s", - proxypath, apr_strerror(status, errmsg, sizeof errmsg))); + usage(apr_psprintf(pool, "Could not set filepath to '%s': %pm", + proxypath, &status)); } break; @@ -1680,8 +1671,7 @@ int main(int argc, const char * const argv[]) } if (apr_filepath_get(&path, 0, pool) != APR_SUCCESS) { - usage(apr_psprintf(pool, "Could not get the filepath: %s", - apr_strerror(status, errmsg, sizeof errmsg))); + usage(apr_psprintf(pool, "Could not get the filepath: %pm", &status)); } baselen = strlen(path); |