Have 'openssl engine' exit with non-zero when some engine fails to load
authorRichard Levitte <levitte@openssl.org>
Tue, 19 Jul 2016 06:57:01 +0000 (08:57 +0200)
committerRichard Levitte <levitte@openssl.org>
Thu, 4 Aug 2016 14:57:49 +0000 (16:57 +0200)
Reviewed-by: Rich Salz <rsalz@openssl.org>
apps/engine.c

index c98839a9fcfa042b7cb14e1d71aaa2908524521e..ffd3137426de1fb6fe4a734076d78d141ed8e737 100644 (file)
@@ -342,6 +342,7 @@ int engine_main(int argc, char **argv)
         }
     }
 
         }
     }
 
+    ret = 0;
     for (i = 0; i < sk_OPENSSL_CSTRING_num(engines); i++) {
         const char *id = sk_OPENSSL_CSTRING_value(engines, i);
         if ((e = ENGINE_by_id(id)) != NULL) {
     for (i = 0; i < sk_OPENSSL_CSTRING_num(engines); i++) {
         const char *id = sk_OPENSSL_CSTRING_value(engines, i);
         if ((e = ENGINE_by_id(id)) != NULL) {
@@ -424,11 +425,14 @@ int engine_main(int argc, char **argv)
             if ((verbose > 0) && !util_verbose(e, verbose, out, indent))
                 goto end;
             ENGINE_free(e);
             if ((verbose > 0) && !util_verbose(e, verbose, out, indent))
                 goto end;
             ENGINE_free(e);
-        } else
+        } else {
             ERR_print_errors(bio_err);
             ERR_print_errors(bio_err);
+            /* because exit codes above 127 have special meaning on Unix */
+            if (++ret > 127)
+                ret = 127;
+        }
     }
 
     }
 
-    ret = 0;
  end:
 
     ERR_print_errors(bio_err);
  end:
 
     ERR_print_errors(bio_err);