[Opendnssec-commits] [keihatsu.kirei.se/svn/dnssec] r1729 - trunk/OpenDNSSEC/libhsm/src

Jakob Schlyter jakob at kirei.se
Fri Aug 28 10:22:20 CEST 2009


Author: jakob
Date: 2009-08-28 10:22:19 +0200 (Fri, 28 Aug 2009)
New Revision: 1729

Modified:
   trunk/OpenDNSSEC/libhsm/src/hsmtest.c
   trunk/OpenDNSSEC/libhsm/src/hsmtest.h
   trunk/OpenDNSSEC/libhsm/src/hsmutil.c
Log:
better error handling


Modified: trunk/OpenDNSSEC/libhsm/src/hsmtest.c
===================================================================
--- trunk/OpenDNSSEC/libhsm/src/hsmtest.c	2009-08-28 08:12:12 UTC (rev 1728)
+++ trunk/OpenDNSSEC/libhsm/src/hsmtest.c	2009-08-28 08:22:19 UTC (rev 1729)
@@ -76,7 +76,7 @@
     return result;
 }
 
-static void
+static int
 hsm_test_random()
 {
     hsm_ctx_t *ctx = NULL;
@@ -91,7 +91,7 @@
     if (result) {
         printf("Failed, error: %d\n", result);
         hsm_print_error(ctx);
-        return;
+        return 1;
     } else {
         printf("OK\n");
     }
@@ -103,9 +103,11 @@
     printf("Generating 64-bit random data... ");
     r64 = hsm_random64(ctx);
     printf("%llu\n", r64);
+    
+    return 0;
 }
 
-void
+int
 hsm_test (const char *repository)
 {
     int result;
@@ -115,11 +117,12 @@
     hsm_ctx_t *ctx = NULL;
     hsm_key_t *key = NULL;
     char *id;
+    int errors = 0;
 
     /* Check for repository before starting any tests */
     if (hsm_token_attached(ctx, repository) == 0) {
         hsm_print_error(ctx);
-        return;        
+        return 1;
     }
 
     /*
@@ -131,6 +134,7 @@
         printf("Generating %d-bit RSA key... ", keysize);
         key = hsm_generate_rsa_key(ctx, repository, keysize);
         if (!key) {
+            errors++;
             printf("Failed\n");
             hsm_print_error(ctx);
             printf("\n");
@@ -142,6 +146,7 @@
         printf("Extracting key identifier... ");
         id = hsm_get_key_id(ctx, key);
         if (!id) {
+            errors++;
             printf("Failed\n");
             hsm_print_error(ctx);
             printf("\n");
@@ -152,6 +157,7 @@
         printf("Signing with key... ");
         result = hsm_test_sign(ctx, key);
         if (result) {
+            errors++;
             printf("Failed, error: %d\n", result);
             hsm_print_error(ctx);
         } else {
@@ -161,6 +167,7 @@
         printf("Deleting key... ");
         result = hsm_remove_key(ctx, key);
         if (result) {
+            errors++;
             printf("Failed: error: %d\n", result);
             hsm_print_error(ctx);
         } else {
@@ -170,5 +177,9 @@
         printf("\n");
     }
     
-    hsm_test_random();
+    if (hsm_test_random()) {
+        errors++;
+    }
+    
+    return errors;
 }

Modified: trunk/OpenDNSSEC/libhsm/src/hsmtest.h
===================================================================
--- trunk/OpenDNSSEC/libhsm/src/hsmtest.h	2009-08-28 08:12:12 UTC (rev 1728)
+++ trunk/OpenDNSSEC/libhsm/src/hsmtest.h	2009-08-28 08:22:19 UTC (rev 1729)
@@ -29,7 +29,7 @@
 #ifndef HSMTEST_H
 #define HSMTEST_H 1
 
-void
+int
 hsm_test (const char *repository);
 
 #endif /* HSMTEST_H */

Modified: trunk/OpenDNSSEC/libhsm/src/hsmutil.c
===================================================================
--- trunk/OpenDNSSEC/libhsm/src/hsmutil.c	2009-08-28 08:12:12 UTC (rev 1728)
+++ trunk/OpenDNSSEC/libhsm/src/hsmutil.c	2009-08-28 08:22:19 UTC (rev 1729)
@@ -286,16 +286,20 @@
         argv++;
 
         printf("Testing repository: %s\n\n", repository);
-        hsm_test(repository);
+        return hsm_test(repository);
     } else {
         usage_test();
     }
+    
+    return 0;
 }
 
 int
-cmd_debug (int argc, char *argv[])
+cmd_debug ()
 {
     hsm_print_ctx(NULL);
+
+    return 0;
 }
 
 int
@@ -359,7 +363,7 @@
     } else if (!strcasecmp(argv[0], "debug")) {
         argc --;
         argv ++;
-        result = cmd_debug(argc, argv);
+        result = cmd_debug();
     } else {
         usage();
         result = -1;




More information about the Opendnssec-commits mailing list