From 3aab3d8401cf44b1872ee5d8d30896f38f6db802 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 13 Sep 2019 05:50:08 +0100 Subject: [PATCH] server-status: still produce valid json if files cant be opened Kernel update changed the /sys path for temp monitoring... the status had already emitted a , in the json committing it to make a new entry, but the code skips making it if the file can't be opened. Change it to produce "(unknown)" in that case. --- plugins/protocol_lws_server_status.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/protocol_lws_server_status.c b/plugins/protocol_lws_server_status.c index 0e6bda14a..2bed87373 100644 --- a/plugins/protocol_lws_server_status.c +++ b/plugins/protocol_lws_server_status.c @@ -75,21 +75,22 @@ update(struct vhd *v) if (!first) p += lws_snprintf(p, lws_ptr_diff(end, p), ","); + strcpy(pure, "(unknown)"); fd = lws_open(fp->filepath, LWS_O_RDONLY); if (fd >= 0) { n = read(fd, contents, sizeof(contents) - 1); + close(fd); if (n >= 0) { contents[n] = '\0'; lws_json_purify(pure, contents, sizeof(pure)); - - p += lws_snprintf(p, lws_ptr_diff(end, p), - "{\"path\":\"%s\",\"val\":\"%s\"}", - fp->filepath, pure); - first = 0; } - close(fd); } + p += lws_snprintf(p, lws_ptr_diff(end, p), + "{\"path\":\"%s\",\"val\":\"%s\"}", + fp->filepath, pure); + first = 0; + fp = fp->next; } p += lws_snprintf(p, lws_ptr_diff(end, p), "]}");