[PATCH 4 of 4] (issue46) Make debug output optional in cinst and mozilla and propagate its setting

Wald Commits scm-commit at wald.intevation.org
Tue Sep 9 18:49:10 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1410281342 -7200
# Node ID 317ee9dc4684b2df73807b2f11212e374e6a75d7
# Parent  f638eb1f3b0f7702e95be7895e77583e2050bc44
(issue46) Make debug output optional in cinst and mozilla and propagate its setting.

diff -r f638eb1f3b0f -r 317ee9dc4684 cinst/main.c
--- a/cinst/main.c	Tue Sep 09 18:00:37 2014 +0200
+++ b/cinst/main.c	Tue Sep 09 18:49:02 2014 +0200
@@ -35,6 +35,8 @@
  *  to remove all certificates (Even those marked with I) that
  *  are part of the list.
  *
+ *  For more verbose debug output add --debug to the call.
+ *
  **/
 #include <stdio.h>
 #include <stdlib.h>
@@ -199,6 +201,7 @@
   return 0;
 }
 
+bool g_debug = false;
 
 int
 main (int argc, char **argv)
@@ -219,18 +222,24 @@
   /* Some very static argument parsing. list= and choices= is only
      added to make it more transparent how this programm is called if
      a user looks at the detailed uac dialog. */
-  if (argc != 3 || strncmp(argv[1], "list=", 5) != 0 ||
+  if ((argc != 3 && argc != 4) || strncmp(argv[1], "list=", 5) != 0 ||
       strncmp(argv[2], "choices=", 8) != 0)
     {
       ERRORPRINTF ("Invalid arguments.\n"
                    "Expected arguments: list=<certificate_list> \n"
-                   "                    choices=<choices_file>|uninstall\n");
+                   "                    choices=<choices_file>|uninstall\n"
+                   "Optional: --debug\n");
       return ERR_INVALID_PARAMS;
     }
 
   certificate_file_name = strchr(argv[1], '=') + 1;
   choices_file_name = strchr(argv[2], '=') + 1;
 
+  if (argc == 4 && strncmp(argv[3], "--debug", 7) == 0)
+    {
+      g_debug = true;
+    }
+
   if (!certificate_file_name || !choices_file_name)
     {
       ERRORPRINTF ("Invalid arguments.\n"
diff -r f638eb1f3b0f -r 317ee9dc4684 cinst/mozilla.c
--- 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;
     }
diff -r f638eb1f3b0f -r 317ee9dc4684 cinst/nssstore_linux.c
--- a/cinst/nssstore_linux.c	Tue Sep 09 18:00:37 2014 +0200
+++ b/cinst/nssstore_linux.c	Tue Sep 09 18:49:02 2014 +0200
@@ -49,7 +49,7 @@
 {
   int pipe_fd[2];
   pid_t pid = 0;
-  char *argv[2] = {NULL, NULL},
+  char *argv[3] = {NULL, NULL, NULL},
                   *envp[2] = {NULL, NULL},
                              *inst_dir = NULL;
   size_t homedir_len = 0,
@@ -92,6 +92,11 @@
   exe_path_len = strlen(inst_dir) + strlen(NSS_PROCESS_NAME);
   argv[0] = xmalloc (exe_path_len + 1);
 
+  if (g_debug)
+    {
+      argv[1] = "--debug";
+    }
+
   ret = snprintf(argv[0], exe_path_len + 1, "%s%s", inst_dir, NSS_PROCESS_NAME);
   xfree (inst_dir);
   if (ret < 0 || (size_t) ret != exe_path_len)
diff -r f638eb1f3b0f -r 317ee9dc4684 cinst/nssstore_win.c
--- a/cinst/nssstore_win.c	Tue Sep 09 18:00:37 2014 +0200
+++ b/cinst/nssstore_win.c	Tue Sep 09 18:49:02 2014 +0200
@@ -415,6 +415,11 @@
      + NULL */
   cmd_line_len = wcslen (w_inst_dir) + 1 + 2 + wcslen (NSS_APP_NAME) +
                  + 1 + 2 + wcslen(selection_file) + 1;
+  if (g_debug)
+    {
+      /* Add space for whitespace and --debug*/
+      cmd_line_len += 8;
+    }
   retval = xmalloc (cmd_line_len * sizeof(wchar_t));
 
   wcscpy_s (retval, cmd_line_len, L"\"");
@@ -425,6 +430,11 @@
   wcscat_s (retval, cmd_line_len, selection_file);
   wcscat_s (retval, cmd_line_len, L"\"");
 
+  if (g_debug)
+    {
+      wcscat_s (retval, cmd_line_len, L" --debug");
+    }
+
   return retval;
 }
 
diff -r f638eb1f3b0f -r 317ee9dc4684 common/logging.h
--- a/common/logging.h	Tue Sep 09 18:00:37 2014 +0200
+++ b/common/logging.h	Tue Sep 09 18:49:02 2014 +0200
@@ -70,9 +70,10 @@
  */
 #ifdef DEBUGOUTPUT
 # ifndef WIN32
-#  define DEBUGPRINTF(fmt, ...) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__);
+#  define DEBUGPRINTF(fmt, ...) if (g_debug) fprintf(stderr, DEBUGPREFIX "DEBUG: " fmt, ##__VA_ARGS__);
 # else /* WIN32 */
 #  define DEBUGPRINTF(fmt, ...) \
+ if (g_debug) \
   { \
     char buf[512]; \
     snprintf(buf, 511, "DEBUG: " fmt, ##__VA_ARGS__); \
@@ -113,8 +114,8 @@
       if (my_error) { \
         ERRORPRINTF(msg" : %s\n", my_error); \
         free (my_error); \
-      } \
-  ERRORPRINTF ("Failed to get error information\n");
+      } else \
+    ERRORPRINTF ("Failed to get error information\n");
 
 
 /**
diff -r f638eb1f3b0f -r 317ee9dc4684 ui/installwrapper.cpp
--- a/ui/installwrapper.cpp	Tue Sep 09 18:00:37 2014 +0200
+++ b/ui/installwrapper.cpp	Tue Sep 09 18:49:02 2014 +0200
@@ -94,6 +94,10 @@
     QString parameters = "\"list=" + mCertListFile +
         "\" \"choices=" + choicesFile.fileName() + "\"";
 
+    if (g_debug) {
+        parameters += " --debug";
+    }
+
     shExecInfo.cbSize = sizeof(SHELLEXECUTEINFOW);
     shExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
     if (!is_system_install()) {
@@ -155,6 +159,10 @@
     choicesFile.setAutoRemove(false);
     parameters << "list=" + mCertListFile << "choices=" + choicesFile.fileName();
 
+    if (g_debug) {
+        parameters << "--debug";
+    }
+
     bool sudo_started = false;
     bool use_sudo = is_admin() && is_system_install();
     if (use_sudo) {
diff -r f638eb1f3b0f -r 317ee9dc4684 ui/tests/binverifytest.cpp
--- a/ui/tests/binverifytest.cpp	Tue Sep 09 18:00:37 2014 +0200
+++ b/ui/tests/binverifytest.cpp	Tue Sep 09 18:49:02 2014 +0200
@@ -98,5 +98,6 @@
   QVERIFY(VerifyValid == verify_binary (outfile.fileName().toUtf8().constData(),
                                         outfile.fileName().toUtf8().size()));
 }
+bool g_debug = true;
 
 QTEST_MAIN (BinVerifyTest);
diff -r f638eb1f3b0f -r 317ee9dc4684 ui/tests/cinstprocesstest.cpp
--- a/ui/tests/cinstprocesstest.cpp	Tue Sep 09 18:00:37 2014 +0200
+++ b/ui/tests/cinstprocesstest.cpp	Tue Sep 09 18:49:02 2014 +0200
@@ -32,8 +32,11 @@
         }
     }
 
+    QStringList newArgs = args;
+    newArgs << "--debug";
+
     QProcess *installerProcess = new QProcess();
-    installerProcess->setArguments(args);
+    installerProcess->setArguments(newArgs);
     installerProcess->setProgram(processPath);
     installerProcess->start();
     installerProcess->waitForStarted();
diff -r f638eb1f3b0f -r 317ee9dc4684 ui/tests/createcertlisttest.cpp
--- a/ui/tests/createcertlisttest.cpp	Tue Sep 09 18:00:37 2014 +0200
+++ b/ui/tests/createcertlisttest.cpp	Tue Sep 09 18:49:02 2014 +0200
@@ -84,4 +84,6 @@
     QVERIFY(signature.toBase64() == QByteArray("KMOni98NWbt6SWd13H0JlGA1B7hBlXWH84e883s7gMrWeCCj0fUyHmdsNCyY0rmosu+o9mo2K847S3CdnxFPPJcjbfcmILZWRw0hHMtUYta1i9jypHJbz4oznuDctgXz59L4SQzzliCNUzItNoe6UpUznkS5gja4ZHbzqIj3qDVX3H86Z+qOdLICw+LXKlTs5ghsq+SdhZRAFFpHnt+URICWHjEIQKRlmIGEUIh1NgEHInHB/teFLqNGJMu1khi0MTsWDzesAEF5LQTM7Fo3fKmVxEUSbHKupluZrX1XSfnp5w3MaxBQK/t5nFvkVVdFrdEWvb68FIkMt21XqCvjyCPG2oWNh9jjfx3/R+eQ8kFbXzgUIhlZNxbB7bOCVDe2fYNxlXhy+HAqfHsIDP8qegHU+ngLck7tJHScC5dZwTCBDL6sxAvaeGyb3m6FraqaipNI+SGLii63ou9H7PlH5xWOTY9JvJDXGpfjN9U0UrZ6X5hPutOa/llT7s0pmoQb"));
 }
 
+bool g_debug = true;
+
 QTEST_GUILESS_MAIN (CreateCertListTest);
diff -r f638eb1f3b0f -r 317ee9dc4684 ui/tests/nsstest.cpp
--- a/ui/tests/nsstest.cpp	Tue Sep 09 18:00:37 2014 +0200
+++ b/ui/tests/nsstest.cpp	Tue Sep 09 18:49:02 2014 +0200
@@ -266,4 +266,7 @@
         write_stores_nss(to_install, to_remove);
     }
 }
+
+bool g_debug = true;
+
 QTEST_GUILESS_MAIN (NSSTest);
diff -r f638eb1f3b0f -r 317ee9dc4684 ui/tests/windowsstoretest.cpp
--- a/ui/tests/windowsstoretest.cpp	Tue Sep 09 18:00:37 2014 +0200
+++ b/ui/tests/windowsstoretest.cpp	Tue Sep 09 18:49:02 2014 +0200
@@ -158,4 +158,7 @@
 void WindowsStoreTest::cleanupTestCase() {
     CertCloseStore(testStore, 0);
 }
+
+bool g_debug = true;
+
 QTEST_GUILESS_MAIN (WindowsStoreTest);


More information about the Trustbridge-commits mailing list