1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

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.
This commit is contained in:
Andy Green 2019-09-13 05:31:28 +01:00
parent a97347a18e
commit d3aa28c2db

View file

@ -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), "]}");