From be929dbe2dffa82ca1f91538f56a1bb0490000bd Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Wed, 12 Nov 2014 15:04:27 +0100 Subject: Use peer specifier from log instead of the peer name for the status output This fixes a crash when status sockets are used with peers without names, but the JSON output format is changed: named peers will now use "" as key instead of "name". --- src/log.c | 4 ++-- src/log.h | 1 + src/status.c | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/log.c b/src/log.c index 1559496..8e2fa56 100644 --- a/src/log.c +++ b/src/log.c @@ -92,7 +92,7 @@ size_t fastd_snprint_peer_address(char *buffer, size_t size, const fastd_peer_ad } /** Creates a string representation of a peer */ -static size_t snprint_peer_str(char *buffer, size_t size, const fastd_peer_t *peer) { +size_t fastd_snprint_peer_str(char *buffer, size_t size, const fastd_peer_t *peer) { if (peer) { if (peer->name) { return snprintf_safe(buffer, size, "<%s>", peer->name); @@ -168,7 +168,7 @@ static int fastd_vsnprintf(char *buffer, size_t size, const char *format, va_lis break; case 'P': - buffer += snprint_peer_str(buffer, buffer_end-buffer, va_arg(ap, const fastd_peer_t *)); + buffer += fastd_snprint_peer_str(buffer, buffer_end-buffer, va_arg(ap, const fastd_peer_t *)); break; case 'I': diff --git a/src/log.h b/src/log.h index 5fce09f..31d1c8c 100644 --- a/src/log.h +++ b/src/log.h @@ -54,6 +54,7 @@ typedef enum fastd_loglevel { size_t fastd_snprint_peer_address(char *buffer, size_t size, const fastd_peer_address_t *address, const char *iface, bool bind_address, bool hide); +size_t fastd_snprint_peer_str(char *buffer, size_t size, const fastd_peer_t *peer); void fastd_logf(const fastd_loglevel_t level, const char *format, ...); diff --git a/src/status.c b/src/status.c index 8e0c427..36a38b6 100644 --- a/src/status.c +++ b/src/status.c @@ -174,7 +174,10 @@ static void dump_status(int fd) { if (!fastd_peer_is_enabled(peer)) continue; - json_object_object_add(peers, peer->name, dump_peer(peer)); + char name[1024]; + fastd_snprint_peer_str(name, sizeof(name), peer); + + json_object_object_add(peers, name, dump_peer(peer)); } -- cgit v1.2.3