]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nss: Debug print JSON files as they are parsed
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 24 Jun 2025 08:17:44 +0000 (10:17 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 18 Jul 2025 13:05:41 +0000 (15:05 +0200)
It may help in case the NSS plugin ever faces a corrupted JSON

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
tools/nss/libvirt_nss_leases.c

index 6624df2928500cb197e416dc3bd8914f24889a2a..c1b4cd73929a55abd0e36b1d917809bfed6f06d2 100644 (file)
@@ -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;