mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-09-02 15:45:25 +00:00
4516. [bug] isc_socketmgr_renderjson was missing from the
windows build. [RT #43602]
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -1,3 +1,6 @@
|
|||||||
|
4516. [bug] isc_socketmgr_renderjson was missing from the
|
||||||
|
windows build. [RT #43602]
|
||||||
|
|
||||||
4515. [port] FreeBSD: Find readline headers when they are in
|
4515. [port] FreeBSD: Find readline headers when they are in
|
||||||
edit/readline/ instead of readline/. [RT #43658]
|
edit/readline/ instead of readline/. [RT #43658]
|
||||||
|
|
||||||
|
@@ -4113,6 +4113,145 @@ error:
|
|||||||
}
|
}
|
||||||
#endif /* HAVE_LIBXML2 */
|
#endif /* HAVE_LIBXML2 */
|
||||||
|
|
||||||
|
#ifdef HAVE_JSON
|
||||||
|
#define CHECKMEM(m) do { \
|
||||||
|
if (m == NULL) { \
|
||||||
|
result = ISC_R_NOMEMORY;\
|
||||||
|
goto error;\
|
||||||
|
} \
|
||||||
|
} while(0)
|
||||||
|
|
||||||
|
isc_result_t
|
||||||
|
isc_socketmgr_renderjson(isc_socketmgr_t *mgr, json_object *stats) {
|
||||||
|
isc_result_t result = ISC_R_SUCCESS;
|
||||||
|
isc_socket_t *sock = NULL;
|
||||||
|
char peerbuf[ISC_SOCKADDR_FORMATSIZE];
|
||||||
|
isc_sockaddr_t addr;
|
||||||
|
ISC_SOCKADDR_LEN_T len;
|
||||||
|
json_object *obj, *array = json_object_new_array();
|
||||||
|
|
||||||
|
CHECKMEM(array);
|
||||||
|
|
||||||
|
LOCK(&mgr->lock);
|
||||||
|
|
||||||
|
#ifdef USE_SHARED_MANAGER
|
||||||
|
obj = json_object_new_int(mgr->refs);
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_object_add(stats, "references", obj);
|
||||||
|
#endif /* USE_SHARED_MANAGER */
|
||||||
|
|
||||||
|
sock = ISC_LIST_HEAD(mgr->socklist);
|
||||||
|
while (sock != NULL) {
|
||||||
|
json_object *states, *entry = json_object_new_object();
|
||||||
|
char buf[255];
|
||||||
|
|
||||||
|
CHECKMEM(entry);
|
||||||
|
json_object_array_add(array, entry);
|
||||||
|
|
||||||
|
LOCK(&sock->lock);
|
||||||
|
|
||||||
|
sprintf(buf, "%p", sock);
|
||||||
|
obj = json_object_new_string(buf);
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_object_add(entry, "id", obj);
|
||||||
|
|
||||||
|
if (sock->name[0] != 0) {
|
||||||
|
obj = json_object_new_string(sock->name);
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_object_add(entry, "name", obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
obj = json_object_new_int(sock->references);
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_object_add(entry, "references", obj);
|
||||||
|
|
||||||
|
obj = json_object_new_string(_socktype(sock->type));
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_object_add(entry, "type", obj);
|
||||||
|
|
||||||
|
if (sock->connected) {
|
||||||
|
isc_sockaddr_format(&sock->address, peerbuf,
|
||||||
|
sizeof(peerbuf));
|
||||||
|
obj = json_object_new_string(peerbuf);
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_object_add(entry, "peer-address", obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
len = sizeof(addr);
|
||||||
|
if (getsockname(sock->fd, &addr.type.sa, (void *)&len) == 0) {
|
||||||
|
isc_sockaddr_format(&addr, peerbuf, sizeof(peerbuf));
|
||||||
|
obj = json_object_new_string(peerbuf);
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_object_add(entry, "local-address", obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
states = json_object_new_array();
|
||||||
|
CHECKMEM(states);
|
||||||
|
json_object_object_add(entry, "states", states);
|
||||||
|
|
||||||
|
if (sock->pending_recv) {
|
||||||
|
obj = json_object_new_string("pending-receive");
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_array_add(states, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sock->pending_send) {
|
||||||
|
obj = json_object_new_string("pending-send");
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_array_add(states, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sock->pending_accept) {
|
||||||
|
obj = json_object_new_string("pending-accept");
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_array_add(states, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sock->listener) {
|
||||||
|
obj = json_object_new_string("listener");
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_array_add(states, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sock->connected) {
|
||||||
|
obj = json_object_new_string("connected");
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_array_add(states, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sock->pending_connect) {
|
||||||
|
obj = json_object_new_string("connecting");
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_array_add(states, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sock->bound) {
|
||||||
|
obj = json_object_new_string("bound");
|
||||||
|
CHECKMEM(obj);
|
||||||
|
json_object_array_add(states, obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
UNLOCK(&sock->lock);
|
||||||
|
sock = ISC_LIST_NEXT(sock, link);
|
||||||
|
}
|
||||||
|
|
||||||
|
json_object_object_add(stats, "sockets", array);
|
||||||
|
array = NULL;
|
||||||
|
result = ISC_R_SUCCESS;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (array != NULL)
|
||||||
|
json_object_put(array);
|
||||||
|
|
||||||
|
if (sock != NULL)
|
||||||
|
UNLOCK(&sock->lock);
|
||||||
|
|
||||||
|
UNLOCK(&mgr->lock);
|
||||||
|
|
||||||
|
return (result);
|
||||||
|
}
|
||||||
|
#endif /* HAVE_JSON */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Replace ../socket_api.c
|
* Replace ../socket_api.c
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user