Blame SOURCES/opencryptoki-3.18.0-fix-json-output.patch

e56abe
commit 1600eebb422ae2a733de3a0bd47464620e39ab0d
e56abe
Author: Ingo Franzki <ifranzki@linux.ibm.com>
e56abe
Date:   Tue Jun 7 08:58:16 2022 +0200
e56abe
e56abe
    pkcsstats: Fix JSON output in case of errors
e56abe
    
e56abe
    Produce correct JSON output, even if an error occurs during obtaining
e56abe
    of the statistics for a user.
e56abe
    
e56abe
    Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
e56abe
e56abe
diff --git a/usr/sbin/pkcsstats/pkcsstats.c b/usr/sbin/pkcsstats/pkcsstats.c
e56abe
index 8eb049dd..65d4833f 100644
e56abe
--- a/usr/sbin/pkcsstats/pkcsstats.c
e56abe
+++ b/usr/sbin/pkcsstats/pkcsstats.c
e56abe
@@ -789,7 +789,7 @@ int main(int argc, char **argv)
e56abe
     bool reset = false, reset_all = false;
e56abe
     bool delete = false, delete_all = false;
e56abe
     bool slot_id_specified = false;
e56abe
-    bool json = false;
e56abe
+    bool json = false, json_started = false;
e56abe
     CK_SLOT_ID slot_id = 0;
e56abe
     void *dll = NULL;
e56abe
     CK_FUNCTION_LIST *func_list = NULL;
e56abe
@@ -949,8 +949,11 @@ int main(int argc, char **argv)
e56abe
         goto done;
e56abe
     }
e56abe
 
e56abe
-    if (json && print_json_start() != 0)
e56abe
-        goto done;
e56abe
+    if (json) {
e56abe
+        if (print_json_start() != 0)
e56abe
+            goto done;
e56abe
+        json_started = true;
e56abe
+    }
e56abe
 
e56abe
     dd.func_list = func_list;
e56abe
     dd.num_slots = num_slots;
e56abe
@@ -972,7 +975,7 @@ int main(int argc, char **argv)
e56abe
     }
e56abe
 
e56abe
 done:
e56abe
-    if (rc == 0 && json)
e56abe
+    if (json && json_started)
e56abe
         printf("\n\t]\n}\n");
e56abe
 
e56abe
     if (slots != NULL)