diff cinst/mozilla.c @ 1060:317ee9dc4684

(issue46) Make debug output optional in cinst and mozilla and propagate its setting.
author Andre Heinecke <andre.heinecke@intevation.de>
date Tue, 09 Sep 2014 18:49:02 +0200
parents 78798d3af8f0
children f110a3f6e387
line wrap: on
line diff
--- a/cinst/mozilla.c	Tue Sep 09 18:00:37 2014 +0200
+++ b/cinst/mozilla.c	Tue Sep 09 18:49:02 2014 +0200
@@ -45,6 +45,9 @@
  * purposes each installation / removal of a certificate will be reported
  * with the profile name that it modified.
  *
+ * To get more verbose output add the --debug parameter
+ * as the last parameter on the command line.
+ *
  */
 
 /**
@@ -142,7 +145,7 @@
     return cdir;
   else
     {
-      DEBUGPRINTF("FATAL!  No %s in environment.\n", envvar);
+      ERRORPRINTF("FATAL!  No %s in environment.\n", envvar);
       exit(ERR_MOZ_HOMELESS);
     }
 }
@@ -560,7 +563,7 @@
   o_str = x509_parse_subject(secitemp->data, secitemp->len, CERT_OID_O);
   if (!cn_str || !o_str)
     {
-      DEBUGPRINTF("FATAL: Could not parse certificate!");
+      ERRORPRINTF("FATAL: Could not parse certificate!");
       exit(ERR_INVALID_CERT);
     }
   name_len = strlen(cn_str) + strlen(o_str) + 4;
@@ -826,12 +829,14 @@
 
       if (parserr)
         {
-          DEBUGPRINTF("FATAL: Invalid input: %s\n", inpl);
+          ERRORPRINTF("FATAL: Invalid input: %s\n", inpl);
           exit(ERR_MOZ_INVALID_INPUT);
         }
     }
 }
 
+bool g_debug = false;
+
 int
 main (int argc, char **argv)
 {
@@ -847,17 +852,29 @@
       input_stream = stdin;
       break;
     case 2:
+      if (strcmp(argv[1], "--debug") == 0)
+        {
+          g_debug = true;
+          DEBUGPRINTF("Opening STDIN for input...\n");
+          input_stream = stdin;
+          break;
+        }
+    case 3:
       DEBUGPRINTF("Opening %s for input...\n", argv[1]);
       if ((input_stream = fopen(argv[1], "r")) == NULL)
         {
-          DEBUGPRINTF("FATAL: Could not open %s for reading!\n",
-                      argv[1]);
+          ERRORPRINTF ("FATAL: Could not open %s for reading!\n",
+                       argv[1]);
           exit_code = ERR_MOZ_FAILED_TO_OPEN_INPUT;
           goto exit;
         }
+      if (argc == 3 && strcmp(argv[2], "--debug") == 0)
+        {
+          g_debug = true;
+        }
       break;
     default:
-      DEBUGPRINTF("FATAL: Wrong number of arguments!\n");
+      ERRORPRINTF("FATAL: Wrong number of arguments!\n");
       exit_code = ERR_MOZ_WRONG_ARGC;
       goto exit;
     }

http://wald.intevation.org/projects/trustbridge/