From: Michal Privoznik Date: Tue, 24 Jun 2025 08:17:44 +0000 (+0200) Subject: nss: Debug print JSON files as they are parsed X-Git-Tag: v11.6.0-rc1~76 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=618eafca05f42f616bb1aa321c4a564c093ad796;p=thirdparty%2Flibvirt.git nss: Debug print JSON files as they are parsed It may help in case the NSS plugin ever faces a corrupted JSON Signed-off-by: Michal Privoznik Reviewed-by: Ján Tomko --- diff --git a/tools/nss/libvirt_nss_leases.c b/tools/nss/libvirt_nss_leases.c index 6624df2928..c1b4cd7392 100644 --- a/tools/nss/libvirt_nss_leases.c +++ b/tools/nss/libvirt_nss_leases.c @@ -265,10 +265,9 @@ findLeases(const char *file, json_tokener *tok = NULL; enum json_tokener_error jerr = json_tokener_error_parse_eof; int jsonflags = JSON_TOKENER_STRICT | JSON_TOKENER_VALIDATE_UTF8; - char line[1024]; size_t nreadTotal = 0; - int rv; + DEBUG("Processing %s", file); if ((fd = open(file, O_RDONLY)) < 0) { ERROR("Cannot open %s", file); goto cleanup; @@ -282,7 +281,11 @@ findLeases(const char *file, json_tokener_set_flags(tok, jsonflags); do { - rv = read(fd, line, sizeof(line)); + char line[1024] = { 0 }; + ssize_t rv; + + rv = read(fd, line, sizeof(line) - 1); + DEBUG("read: rv=%zd line='%s'", rv, line); if (rv < 0) goto cleanup; if (rv == 0) @@ -293,6 +296,9 @@ findLeases(const char *file, jerr = json_tokener_get_error(tok); } while (jerr == json_tokener_continue); + DEBUG("Done reading, nreadTotal=%zu, jerr=%d '%s'", + nreadTotal, (int)jerr, json_tokener_error_desc(jerr)); + if (nreadTotal == 0) { ret = 0; goto cleanup;