Blob Blame History Raw
commit 1600eebb422ae2a733de3a0bd47464620e39ab0d
Author: Ingo Franzki <ifranzki@linux.ibm.com>
Date:   Tue Jun 7 08:58:16 2022 +0200

    pkcsstats: Fix JSON output in case of errors
    
    Produce correct JSON output, even if an error occurs during obtaining
    of the statistics for a user.
    
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>

diff --git a/usr/sbin/pkcsstats/pkcsstats.c b/usr/sbin/pkcsstats/pkcsstats.c
index 8eb049dd..65d4833f 100644
--- a/usr/sbin/pkcsstats/pkcsstats.c
+++ b/usr/sbin/pkcsstats/pkcsstats.c
@@ -789,7 +789,7 @@ int main(int argc, char **argv)
     bool reset = false, reset_all = false;
     bool delete = false, delete_all = false;
     bool slot_id_specified = false;
-    bool json = false;
+    bool json = false, json_started = false;
     CK_SLOT_ID slot_id = 0;
     void *dll = NULL;
     CK_FUNCTION_LIST *func_list = NULL;
@@ -949,8 +949,11 @@ int main(int argc, char **argv)
         goto done;
     }
 
-    if (json && print_json_start() != 0)
-        goto done;
+    if (json) {
+        if (print_json_start() != 0)
+            goto done;
+        json_started = true;
+    }
 
     dd.func_list = func_list;
     dd.num_slots = num_slots;
@@ -972,7 +975,7 @@ int main(int argc, char **argv)
     }
 
 done:
-    if (rc == 0 && json)
+    if (json && json_started)
         printf("\n\t]\n}\n");
 
     if (slots != NULL)