2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

More coverity fixes:

3410.   [bug]           Addressed Coverity warnings. [RT #31626]
Squashed commit of the following:

commit 6fec07bbb69ead784063052f2099674f8b52c6b3
Author: Mark Andrews <marka@isc.org>
Date:   Tue Oct 30 18:14:35 2012 +1100

    use strl{cat,cpy}

commit 19a5d3766f3dbc8a2944b21640a8226a89aae7ba
Author: Mark Andrews <marka@isc.org>
Date:   Tue Oct 30 14:38:55 2012 +1100

    address unchecked xmlTextWriter* calls
This commit is contained in:
Mark Andrews
2012-11-01 10:22:11 +11:00
parent c2e80cf47e
commit bbf31e6b62
11 changed files with 327 additions and 242 deletions

View File

@@ -920,7 +920,7 @@ generatexml(ns_server_t *server, int *buflen, xmlChar **buf) {
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR
"cachestats"));
dns_cache_renderxml(view->cache, writer);
TRY0(dns_cache_renderxml(view->cache, writer));
TRY0(xmlTextWriterEndElement(writer)); /* cachestats */
if (view->adbstats != NULL) {
@@ -941,11 +941,11 @@ generatexml(ns_server_t *server, int *buflen, xmlChar **buf) {
TRY0(xmlTextWriterEndElement(writer)); /* views */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socketmgr"));
isc_socketmgr_renderxml(ns_g_socketmgr, writer);
TRY0(isc_socketmgr_renderxml(ns_g_socketmgr, writer));
TRY0(xmlTextWriterEndElement(writer)); /* socketmgr */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "taskmgr"));
isc_taskmgr_renderxml(ns_g_taskmgr, writer);
TRY0(isc_taskmgr_renderxml(ns_g_taskmgr, writer));
TRY0(xmlTextWriterEndElement(writer)); /* taskmgr */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "server"));
@@ -1008,7 +1008,7 @@ generatexml(ns_server_t *server, int *buflen, xmlChar **buf) {
TRY0(xmlTextWriterEndElement(writer)); /* server */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "memory"));
isc_mem_renderxml(writer);
TRY0(isc_mem_renderxml(writer));
TRY0(xmlTextWriterEndElement(writer)); /* memory */
TRY0(xmlTextWriterEndElement(writer)); /* statistics */

View File

@@ -61,6 +61,7 @@ cleandir(char *path) {
DIR *dirp;
struct dirent *pe;
char fullname[PATH_MAX + 1];
size_t l;
dirp = opendir(path);
if (dirp == NULL) {
@@ -73,11 +74,16 @@ cleandir(char *path) {
continue;
if (! strcmp(pe->d_name, ".."))
continue;
strcpy(fullname, path);
strcat(fullname, "/");
strcat(fullname, pe->d_name);
(void)strlcpy(fullname, path, sizeof(fullname));
(void)strlcat(fullname, "/", sizeof(fullname));
l = strlcat(fullname, pe->d_name, sizeof(fullname));
if (l < sizeof(fullname)) {
if (remove(fullname))
t_info("remove(%s) failed %d\n", fullname, errno);
t_info("remove(%s) failed %d\n", fullname,
errno);
} else
t_info("unable to remove '%s/%s': path too long\n",
path, pe->d_name);
}
(void)closedir(dirp);

View File

@@ -1395,50 +1395,58 @@ dns_cache_dumpstats(dns_cache_t *cache, FILE *fp) {
}
#ifdef HAVE_LIBXML2
static void
#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
static int
renderstat(const char *name, isc_uint64_t value, xmlTextWriterPtr writer) {
xmlTextWriterStartElement(writer, ISC_XMLCHAR "cachestat");
xmlTextWriterStartElement(writer, ISC_XMLCHAR "name");
xmlTextWriterWriteString(writer, ISC_XMLCHAR name);
xmlTextWriterEndElement(writer); /* name */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "value");
xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u", value);
xmlTextWriterEndElement(writer); /* value */
xmlTextWriterEndElement(writer); /* cachestat */
int xmlrc;
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "cachestat"));
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name"));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR name));
TRY0(xmlTextWriterEndElement(writer)); /* name */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "value"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u", value));
TRY0(xmlTextWriterEndElement(writer)); /* value */
TRY0(xmlTextWriterEndElement(writer)); /* cachestat */
error:
return (xmlrc);
}
void
int
dns_cache_renderxml(dns_cache_t *cache, xmlTextWriterPtr writer) {
int indices[dns_cachestatscounter_max];
isc_uint64_t values[dns_cachestatscounter_max];
int xmlrc;
REQUIRE(VALID_CACHE(cache));
getcounters(cache->stats, isc_statsformat_file,
dns_cachestatscounter_max, indices, values);
renderstat("CacheHits",
values[dns_cachestatscounter_hits], writer);
renderstat("CacheMisses",
values[dns_cachestatscounter_misses], writer);
renderstat("QueryHits",
values[dns_cachestatscounter_queryhits], writer);
renderstat("QueryMisses",
values[dns_cachestatscounter_querymisses], writer);
renderstat("DeleteLRU",
values[dns_cachestatscounter_deletelru], writer);
renderstat("DeleteTTL",
values[dns_cachestatscounter_deletettl], writer);
TRY0(renderstat("CacheHits",
values[dns_cachestatscounter_hits], writer));
TRY0(renderstat("CacheMisses",
values[dns_cachestatscounter_misses], writer));
TRY0(renderstat("QueryHits",
values[dns_cachestatscounter_queryhits], writer));
TRY0(renderstat("QueryMisses",
values[dns_cachestatscounter_querymisses], writer));
TRY0(renderstat("DeleteLRU",
values[dns_cachestatscounter_deletelru], writer));
TRY0(renderstat("DeleteTTL",
values[dns_cachestatscounter_deletettl], writer));
renderstat("CacheNodes", dns_db_nodecount(cache->db), writer);
renderstat("CacheBuckets", dns_db_hashsize(cache->db), writer);
TRY0(renderstat("CacheNodes", dns_db_nodecount(cache->db), writer));
TRY0(renderstat("CacheBuckets", dns_db_hashsize(cache->db), writer));
renderstat("TreeMemTotal", isc_mem_total(cache->mctx), writer);
renderstat("TreeMemInUse", isc_mem_inuse(cache->mctx), writer);
renderstat("TreeMemMax", isc_mem_maxinuse(cache->mctx), writer);
TRY0(renderstat("TreeMemTotal", isc_mem_total(cache->mctx), writer));
TRY0(renderstat("TreeMemInUse", isc_mem_inuse(cache->mctx), writer));
TRY0(renderstat("TreeMemMax", isc_mem_maxinuse(cache->mctx), writer));
renderstat("HeapMemTotal", isc_mem_total(cache->hmctx), writer);
renderstat("HeapMemInUse", isc_mem_inuse(cache->hmctx), writer);
renderstat("HeapMemMax", isc_mem_maxinuse(cache->hmctx), writer);
TRY0(renderstat("HeapMemTotal", isc_mem_total(cache->hmctx), writer));
TRY0(renderstat("HeapMemInUse", isc_mem_inuse(cache->hmctx), writer));
TRY0(renderstat("HeapMemMax", isc_mem_maxinuse(cache->hmctx), writer));
error:
return (xmlrc);
}
#endif

View File

@@ -326,7 +326,7 @@ dns_cache_dumpstats(dns_cache_t *cache, FILE *fp);
*/
#ifdef HAVE_LIBXML2
void
int
dns_cache_renderxml(dns_cache_t *cache, xmlTextWriterPtr writer);
/*
* Render cache statistics and status in XML for 'writer'.

View File

@@ -547,7 +547,7 @@ isc_mem_gettag(isc_mem_t *ctx);
*/
#ifdef HAVE_LIBXML2
void
int
isc_mem_renderxml(xmlTextWriterPtr writer);
/*%<
* Render all contexts' statistics and status in XML for writer.

View File

@@ -1144,7 +1144,7 @@ isc__socketmgr_maxudp(isc_socketmgr_t *mgr, int maxudp);
#ifdef HAVE_LIBXML2
void
int
isc_socketmgr_renderxml(isc_socketmgr_t *mgr, xmlTextWriterPtr writer);
/*%<
* Render internal statistics and other state into the XML document.

View File

@@ -788,7 +788,7 @@ isc_taskmgr_excltask(isc_taskmgr_t *mgr, isc_task_t **taskp);
#ifdef HAVE_LIBXML2
void
int
isc_taskmgr_renderxml(isc_taskmgr_t *mgr, xmlTextWriterPtr writer);
#endif

View File

@@ -2386,25 +2386,27 @@ typedef struct summarystat {
isc_uint64_t contextsize;
} summarystat_t;
static void
#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
static int
renderctx(isc__mem_t *ctx, summarystat_t *summary, xmlTextWriterPtr writer) {
int xmlrc;
REQUIRE(VALID_CONTEXT(ctx));
xmlTextWriterStartElement(writer, ISC_XMLCHAR "context");
MCTXLOCK(ctx, &ctx->lock);
xmlTextWriterStartElement(writer, ISC_XMLCHAR "id");
xmlTextWriterWriteFormatString(writer, "%p", ctx);
xmlTextWriterEndElement(writer); /* id */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "context"));
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
TRY0(xmlTextWriterWriteFormatString(writer, "%p", ctx));
TRY0(xmlTextWriterEndElement(writer)); /* id */
if (ctx->name[0] != 0) {
xmlTextWriterStartElement(writer, ISC_XMLCHAR "name");
xmlTextWriterWriteFormatString(writer, "%s", ctx->name);
xmlTextWriterEndElement(writer); /* name */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "name"));
TRY0(xmlTextWriterWriteFormatString(writer, "%s", ctx->name));
TRY0(xmlTextWriterEndElement(writer)); /* name */
}
REQUIRE(VALID_CONTEXT(ctx));
MCTXLOCK(ctx, &ctx->lock);
summary->contextsize += sizeof(*ctx) +
(ctx->max_size + 1) * sizeof(struct stats) +
ctx->max_size * sizeof(element *) +
@@ -2416,70 +2418,79 @@ renderctx(isc__mem_t *ctx, summarystat_t *summary, xmlTextWriterPtr writer) {
ctx->debuglistcnt * sizeof(debuglink_t);
}
#endif
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
xmlTextWriterWriteFormatString(writer, "%d", ctx->references);
xmlTextWriterEndElement(writer); /* references */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d", ctx->references));
TRY0(xmlTextWriterEndElement(writer)); /* references */
summary->total += ctx->total;
xmlTextWriterStartElement(writer, ISC_XMLCHAR "total");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->total);
xmlTextWriterEndElement(writer); /* total */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "total"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->total));
TRY0(xmlTextWriterEndElement(writer)); /* total */
summary->inuse += ctx->inuse;
xmlTextWriterStartElement(writer, ISC_XMLCHAR "inuse");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->inuse);
xmlTextWriterEndElement(writer); /* inuse */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "inuse"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->inuse));
TRY0(xmlTextWriterEndElement(writer)); /* inuse */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "maxinuse");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->maxinuse);
xmlTextWriterEndElement(writer); /* maxinuse */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "maxinuse"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->maxinuse));
TRY0(xmlTextWriterEndElement(writer)); /* maxinuse */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "blocksize");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "blocksize"));
if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) {
summary->blocksize += ctx->basic_table_count *
NUM_BASIC_BLOCKS * ctx->mem_target;
xmlTextWriterWriteFormatString(writer,
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)
ctx->basic_table_count *
NUM_BASIC_BLOCKS *
ctx->mem_target);
ctx->mem_target));
} else
xmlTextWriterWriteFormatString(writer, "%s", "-");
xmlTextWriterEndElement(writer); /* blocksize */
TRY0(xmlTextWriterWriteFormatString(writer, "%s", "-"));
TRY0(xmlTextWriterEndElement(writer)); /* blocksize */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "pools");
xmlTextWriterWriteFormatString(writer, "%u", ctx->poolcnt);
xmlTextWriterEndElement(writer); /* pools */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "pools"));
TRY0(xmlTextWriterWriteFormatString(writer, "%u", ctx->poolcnt));
TRY0(xmlTextWriterEndElement(writer)); /* pools */
summary->contextsize += ctx->poolcnt * sizeof(isc_mempool_t);
xmlTextWriterStartElement(writer, ISC_XMLCHAR "hiwater");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->hi_water);
xmlTextWriterEndElement(writer); /* hiwater */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "hiwater"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->hi_water));
TRY0(xmlTextWriterEndElement(writer)); /* hiwater */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "lowater");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->lo_water);
xmlTextWriterEndElement(writer); /* lowater */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "lowater"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
(isc_uint64_t)ctx->lo_water));
TRY0(xmlTextWriterEndElement(writer)); /* lowater */
TRY0(xmlTextWriterEndElement(writer)); /* context */
error:
MCTXUNLOCK(ctx, &ctx->lock);
xmlTextWriterEndElement(writer); /* context */
return (xmlrc);
}
void
int
isc_mem_renderxml(xmlTextWriterPtr writer) {
isc__mem_t *ctx;
summarystat_t summary;
isc_uint64_t lost;
int xmlrc;
memset(&summary, 0, sizeof(summary));
xmlTextWriterStartElement(writer, ISC_XMLCHAR "contexts");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "contexts"));
RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
@@ -2488,40 +2499,51 @@ isc_mem_renderxml(xmlTextWriterPtr writer) {
for (ctx = ISC_LIST_HEAD(contexts);
ctx != NULL;
ctx = ISC_LIST_NEXT(ctx, link)) {
renderctx(ctx, &summary, writer);
xmlrc = renderctx(ctx, &summary, writer);
if (xmlrc < 0) {
UNLOCK(&lock);
goto error;
}
}
UNLOCK(&lock);
xmlTextWriterEndElement(writer); /* contexts */
TRY0(xmlTextWriterEndElement(writer)); /* contexts */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "summary");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "summary"));
xmlTextWriterStartElement(writer, ISC_XMLCHAR "TotalUse");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
summary.total);
xmlTextWriterEndElement(writer); /* TotalUse */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "TotalUse"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
summary.total));
TRY0(xmlTextWriterEndElement(writer)); /* TotalUse */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "InUse");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
summary.inuse);
xmlTextWriterEndElement(writer); /* InUse */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "InUse"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
summary.inuse));
TRY0(xmlTextWriterEndElement(writer)); /* InUse */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "BlockSize");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
summary.blocksize);
xmlTextWriterEndElement(writer); /* BlockSize */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "BlockSize"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
summary.blocksize));
TRY0(xmlTextWriterEndElement(writer)); /* BlockSize */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "ContextSize");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
summary.contextsize);
xmlTextWriterEndElement(writer); /* ContextSize */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "ContextSize"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
summary.contextsize));
TRY0(xmlTextWriterEndElement(writer)); /* ContextSize */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "Lost");
xmlTextWriterWriteFormatString(writer, "%" ISC_PRINT_QUADFORMAT "u",
lost);
xmlTextWriterEndElement(writer); /* Lost */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "Lost"));
TRY0(xmlTextWriterWriteFormatString(writer,
"%" ISC_PRINT_QUADFORMAT "u",
lost));
TRY0(xmlTextWriterEndElement(writer)); /* Lost */
xmlTextWriterEndElement(writer); /* summary */
TRY0(xmlTextWriterEndElement(writer)); /* summary */
error:
return (xmlrc);
}
#endif /* HAVE_LIBXML2 */

View File

@@ -1781,10 +1781,12 @@ isc_task_exiting(isc_task_t *t) {
#if defined(HAVE_LIBXML2) && defined(BIND9)
void
#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
int
isc_taskmgr_renderxml(isc_taskmgr_t *mgr0, xmlTextWriterPtr writer) {
isc__taskmgr_t *mgr = (isc__taskmgr_t *)mgr0;
isc__task_t *task;
isc__task_t *task = NULL;
int xmlrc;
LOCK(&mgr->lock);
@@ -1792,80 +1794,91 @@ isc_taskmgr_renderxml(isc_taskmgr_t *mgr0, xmlTextWriterPtr writer) {
* Write out the thread-model, and some details about each depending
* on which type is enabled.
*/
xmlTextWriterStartElement(writer, ISC_XMLCHAR "thread-model");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "thread-model"));
#ifdef ISC_PLATFORM_USETHREADS
xmlTextWriterStartElement(writer, ISC_XMLCHAR "type");
xmlTextWriterWriteString(writer, ISC_XMLCHAR "threaded");
xmlTextWriterEndElement(writer); /* type */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "type"));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR "threaded"));
TRY0(xmlTextWriterEndElement(writer)); /* type */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "worker-threads");
xmlTextWriterWriteFormatString(writer, "%d", mgr->workers);
xmlTextWriterEndElement(writer); /* worker-threads */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "worker-threads"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->workers));
TRY0(xmlTextWriterEndElement(writer)); /* worker-threads */
#else /* ISC_PLATFORM_USETHREADS */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "type");
xmlTextWriterWriteString(writer, ISC_XMLCHAR "non-threaded");
xmlTextWriterEndElement(writer); /* type */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "type"));
TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR "non-threaded"));
TRY0(xmlTextWriterEndElement(writer)); /* type */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
xmlTextWriterWriteFormatString(writer, "%d", mgr->refs);
xmlTextWriterEndElement(writer); /* references */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->refs));
TRY0(xmlTextWriterEndElement(writer)); /* references */
#endif /* ISC_PLATFORM_USETHREADS */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "default-quantum");
xmlTextWriterWriteFormatString(writer, "%d", mgr->default_quantum);
xmlTextWriterEndElement(writer); /* default-quantum */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "default-quantum"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d",
mgr->default_quantum));
TRY0(xmlTextWriterEndElement(writer)); /* default-quantum */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks-running");
xmlTextWriterWriteFormatString(writer, "%d", mgr->tasks_running);
xmlTextWriterEndElement(writer); /* tasks-running */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks-running"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->tasks_running));
TRY0(xmlTextWriterEndElement(writer)); /* tasks-running */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks-ready");
xmlTextWriterWriteFormatString(writer, "%d", mgr->tasks_ready);
xmlTextWriterEndElement(writer); /* tasks-ready */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks-ready"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->tasks_ready));
TRY0(xmlTextWriterEndElement(writer)); /* tasks-ready */
xmlTextWriterEndElement(writer); /* thread-model */
TRY0(xmlTextWriterEndElement(writer)); /* thread-model */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "tasks"));
task = ISC_LIST_HEAD(mgr->tasks);
while (task != NULL) {
LOCK(&task->lock);
xmlTextWriterStartElement(writer, ISC_XMLCHAR "task");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "task"));
if (task->name[0] != 0) {
xmlTextWriterStartElement(writer, ISC_XMLCHAR "name");
xmlTextWriterWriteFormatString(writer, "%s",
task->name);
xmlTextWriterEndElement(writer); /* name */
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "name"));
TRY0(xmlTextWriterWriteFormatString(writer, "%s",
task->name));
TRY0(xmlTextWriterEndElement(writer)); /* name */
}
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
xmlTextWriterWriteFormatString(writer, "%d", task->references);
xmlTextWriterEndElement(writer); /* references */
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d",
task->references));
TRY0(xmlTextWriterEndElement(writer)); /* references */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "id");
xmlTextWriterWriteFormatString(writer, "%p", task);
xmlTextWriterEndElement(writer); /* id */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
TRY0(xmlTextWriterWriteFormatString(writer, "%p", task));
TRY0(xmlTextWriterEndElement(writer)); /* id */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "state");
xmlTextWriterWriteFormatString(writer, "%s",
statenames[task->state]);
xmlTextWriterEndElement(writer); /* state */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "state"));
TRY0(xmlTextWriterWriteFormatString(writer, "%s",
statenames[task->state]));
TRY0(xmlTextWriterEndElement(writer)); /* state */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "quantum");
xmlTextWriterWriteFormatString(writer, "%d", task->quantum);
xmlTextWriterEndElement(writer); /* quantum */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "quantum"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d",
task->quantum));
TRY0(xmlTextWriterEndElement(writer)); /* quantum */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "events");
xmlTextWriterWriteFormatString(writer, "%d", task->nevents);
xmlTextWriterEndElement(writer); /* events */
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "events"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d",
task->nevents));
TRY0(xmlTextWriterEndElement(writer)); /* events */
xmlTextWriterEndElement(writer);
TRY0(xmlTextWriterEndElement(writer));
UNLOCK(&task->lock);
task = ISC_LIST_NEXT(task, link);
}
xmlTextWriterEndElement(writer); /* tasks */
TRY0(xmlTextWriterEndElement(writer)); /* tasks */
error:
if (task != NULL)
UNLOCK(&task->lock);
UNLOCK(&mgr->lock);
return (xmlrc);
}
#endif /* HAVE_LIBXML2 && BIND9 */

View File

@@ -5959,94 +5959,112 @@ _socktype(isc_sockettype_t type)
return ("not-initialized");
}
ISC_SOCKETFUNC_SCOPE void
#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
ISC_SOCKETFUNC_SCOPE int
isc_socketmgr_renderxml(isc_socketmgr_t *mgr0, xmlTextWriterPtr writer) {
isc__socketmgr_t *mgr = (isc__socketmgr_t *)mgr0;
isc__socket_t *sock;
char peerbuf[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_t addr;
ISC_SOCKADDR_LEN_T len;
int xmlrc;
LOCK(&mgr->lock);
#ifdef USE_SHARED_MANAGER
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
xmlTextWriterWriteFormatString(writer, "%d", mgr->refs);
xmlTextWriterEndElement(writer);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->refs));
TRY0(xmlTextWriterEndElement(writer));
#endif /* USE_SHARED_MANAGER */
xmlTextWriterStartElement(writer, ISC_XMLCHAR "sockets");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "sockets"));
sock = ISC_LIST_HEAD(mgr->socklist);
while (sock != NULL) {
LOCK(&sock->lock);
xmlTextWriterStartElement(writer, ISC_XMLCHAR "socket");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socket"));
xmlTextWriterStartElement(writer, ISC_XMLCHAR "id");
xmlTextWriterWriteFormatString(writer, "%p", sock);
xmlTextWriterEndElement(writer);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
TRY0(xmlTextWriterWriteFormatString(writer, "%p", sock));
TRY0(xmlTextWriterEndElement(writer));
if (sock->name[0] != 0) {
xmlTextWriterStartElement(writer, ISC_XMLCHAR "name");
xmlTextWriterWriteFormatString(writer, "%s",
sock->name);
xmlTextWriterEndElement(writer); /* name */
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "name"));
TRY0(xmlTextWriterWriteFormatString(writer, "%s",
sock->name));
TRY0(xmlTextWriterEndElement(writer)); /* name */
}
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
xmlTextWriterWriteFormatString(writer, "%d", sock->references);
xmlTextWriterEndElement(writer);
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d",
sock->references));
TRY0(xmlTextWriterEndElement(writer));
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR _socktype(sock->type));
TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR _socktype(sock->type)));
if (sock->connected) {
isc_sockaddr_format(&sock->peer_address, peerbuf,
sizeof(peerbuf));
xmlTextWriterWriteElement(writer,
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "peer-address",
ISC_XMLCHAR peerbuf);
ISC_XMLCHAR peerbuf));
}
len = sizeof(addr);
if (getsockname(sock->fd, &addr.type.sa, (void *)&len) == 0) {
isc_sockaddr_format(&addr, peerbuf, sizeof(peerbuf));
xmlTextWriterWriteElement(writer,
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "local-address",
ISC_XMLCHAR peerbuf);
ISC_XMLCHAR peerbuf));
}
xmlTextWriterStartElement(writer, ISC_XMLCHAR "states");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "states"));
if (sock->pending_recv)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-receive");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-receive"));
if (sock->pending_send)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-send");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-send"));
if (sock->pending_accept)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "pending_accept");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "pending_accept"));
if (sock->listener)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "listener");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "listener"));
if (sock->connected)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "connected");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "connected"));
if (sock->connecting)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "connecting");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "connecting"));
if (sock->bound)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "bound");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "bound"));
xmlTextWriterEndElement(writer); /* states */
TRY0(xmlTextWriterEndElement(writer)); /* states */
xmlTextWriterEndElement(writer); /* socket */
TRY0(xmlTextWriterEndElement(writer)); /* socket */
UNLOCK(&sock->lock);
sock = ISC_LIST_NEXT(sock, link);
}
xmlTextWriterEndElement(writer); /* sockets */
TRY0(xmlTextWriterEndElement(writer)); /* sockets */
error:
if (sock != NULL)
UNLOCK(&sock->lock);
UNLOCK(&mgr->lock);
return (xmlrc);
}
#endif /* HAVE_LIBXML2 */

View File

@@ -3887,94 +3887,112 @@ _socktype(isc_sockettype_t type)
return ("not-initialized");
}
void
#define TRY0(a) do { xmlrc = (a); if (xmlrc < 0) goto error; } while(0)
int
isc_socketmgr_renderxml(isc_socketmgr_t *mgr, xmlTextWriterPtr writer)
{
isc_socket_t *sock;
char peerbuf[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_t addr;
ISC_SOCKADDR_LEN_T len;
int xmlrc;
LOCK(&mgr->lock);
#ifndef ISC_PLATFORM_USETHREADS
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
xmlTextWriterWriteFormatString(writer, "%d", mgr->refs);
xmlTextWriterEndElement(writer);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d", mgr->refs));
TRY0(xmlTextWriterEndElement(writer));
#endif
xmlTextWriterStartElement(writer, ISC_XMLCHAR "sockets");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "sockets"));
sock = ISC_LIST_HEAD(mgr->socklist);
while (sock != NULL) {
LOCK(&sock->lock);
xmlTextWriterStartElement(writer, ISC_XMLCHAR "socket");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "socket"));
xmlTextWriterStartElement(writer, ISC_XMLCHAR "id");
xmlTextWriterWriteFormatString(writer, "%p", sock);
xmlTextWriterEndElement(writer);
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "id"));
TRY0(xmlTextWriterWriteFormatString(writer, "%p", sock));
TRY0(xmlTextWriterEndElement(writer));
if (sock->name[0] != 0) {
xmlTextWriterStartElement(writer, ISC_XMLCHAR "name");
xmlTextWriterWriteFormatString(writer, "%s",
sock->name);
xmlTextWriterEndElement(writer); /* name */
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "name"));
TRY0(xmlTextWriterWriteFormatString(writer, "%s",
sock->name));
TRY0(xmlTextWriterEndElement(writer)); /* name */
}
xmlTextWriterStartElement(writer, ISC_XMLCHAR "references");
xmlTextWriterWriteFormatString(writer, "%d", sock->references);
xmlTextWriterEndElement(writer);
TRY0(xmlTextWriterStartElement(writer,
ISC_XMLCHAR "references"));
TRY0(xmlTextWriterWriteFormatString(writer, "%d",
sock->references));
TRY0(xmlTextWriterEndElement(writer));
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR _socktype(sock->type));
TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "type",
ISC_XMLCHAR _socktype(sock->type)));
if (sock->connected) {
isc_sockaddr_format(&sock->address, peerbuf,
sizeof(peerbuf));
xmlTextWriterWriteElement(writer,
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "peer-address",
ISC_XMLCHAR peerbuf);
ISC_XMLCHAR peerbuf));
}
len = sizeof(addr);
if (getsockname(sock->fd, &addr.type.sa, (void *)&len) == 0) {
isc_sockaddr_format(&addr, peerbuf, sizeof(peerbuf));
xmlTextWriterWriteElement(writer,
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "local-address",
ISC_XMLCHAR peerbuf);
ISC_XMLCHAR peerbuf));
}
xmlTextWriterStartElement(writer, ISC_XMLCHAR "states");
TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "states"));
if (sock->pending_recv)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-receive");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-receive"));
if (sock->pending_send)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-send");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "pending-send"));
if (sock->pending_accept)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "pending_accept");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "pending_accept"));
if (sock->listener)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "listener");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "listener"));
if (sock->connected)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "connected");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "connected"));
if (sock->pending_connect)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "connecting");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "connecting"));
if (sock->bound)
xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state",
ISC_XMLCHAR "bound");
TRY0(xmlTextWriterWriteElement(writer,
ISC_XMLCHAR "state",
ISC_XMLCHAR "bound"));
xmlTextWriterEndElement(writer); /* states */
TRY0(xmlTextWriterEndElement(writer)); /* states */
xmlTextWriterEndElement(writer); /* socket */
TRY0(xmlTextWriterEndElement(writer)); /* socket */
UNLOCK(&sock->lock);
sock = ISC_LIST_NEXT(sock, link);
}
xmlTextWriterEndElement(writer); /* sockets */
TRY0(xmlTextWriterEndElement(writer)); /* sockets */
error:
if (sock != NULL)
UNLOCK(&sock->lock);
UNLOCK(&mgr->lock);
return (xmlrc);
}
#endif /* HAVE_LIBXML2 */