Patch to force freshclam download progress meter

Mark Allan <[email protected]>
Newsgroups gmane.comp.security.virus.clamav.devel
Message-ID <[email protected]>
Hi all,

With the release of 0.99, I got caught out by a change to freshclam's output.  The end result is the same (defs do/don't get updated) so none of my automated tests caught it, but when you actually sit and watch the output, I'm not getting the download progress meter in my GUI any more.

The change that tripped it up was commit #cf5ba11 - Avoid emitting incremental progress messages when not outputting to a terminal.

I've included a patch which works against 0.99 stable as well as current HEAD (#1f85811) to add a new command line flag --show-progress to freshclam to force the output of the progress meter if freshclam isn't being called via a terminal.

Hopefully the additional flag won't cause problems for anyone, so it would be really great if the patch could be included please.

Many thanks,
Mark

_______________________________________________
http://lurker.clamav.net/list/clamav-devel.html
Please submit your patches to our Bugzilla: http://bugs.clamav.net

http://www.clamav.net/contact.html#ml
freshclam_show-progress.patch (application/octet-stream, 3.6 KB)
diff -Naurw clamav-0.99/freshclam/freshclam.c clamav-0.99_patched/freshclam/freshclam.c
--- clamav-0.99/freshclam/freshclam.c	2015-11-23 23:13:46.000000000 +0000
+++ clamav-0.99_patched/freshclam/freshclam.c	2015-12-14 16:37:31.000000000 +0000
@@ -164,6 +164,8 @@
         ("    --no-warnings                        don't print and log warnings\n");
     mprintf
         ("    --stdout                             write to stdout instead of stderr\n");
+    mprintf
+        ("    --show-progress                      show download progress percentage\n");
     mprintf ("\n");
     mprintf
         ("    --config-file=FILE                   read configuration from FILE.\n");
@@ -456,6 +458,9 @@
     if (optget (opts, "stdout")->enabled)
         mprintf_stdout = 1;
 
+    if (optget (opts, "show-progress")->enabled)
+        mprintf_progress = 1;
+
     /* initialize logger */
     logg_verbose = mprintf_verbose ? 1 : optget (opts, "LogVerbose")->enabled;
     logg_time = optget (opts, "LogTime")->enabled;
diff -Naurw clamav-0.99/freshclam/manager.c clamav-0.99_patched/freshclam/manager.c
--- clamav-0.99/freshclam/manager.c	2015-11-23 23:13:46.000000000 +0000
+++ clamav-0.99_patched/freshclam/manager.c	2015-12-14 16:39:18.000000000 +0000
@@ -930,7 +930,7 @@
             percentage = (int) (100 * (float) totaldownloaded / totalsize);
 
 #ifdef HAVE_UNISTD_H
-        if (!mprintf_quiet && isatty(fileno(stdout)))
+        if (!mprintf_quiet && (mprintf_progress || isatty(fileno(stdout))))
 #else
         if (!mprintf_quiet)
 #endif
diff -Naurw clamav-0.99/shared/optparser.c clamav-0.99_patched/shared/optparser.c
--- clamav-0.99/shared/optparser.c	2015-11-23 23:13:46.000000000 +0000
+++ clamav-0.99_patched/shared/optparser.c	2015-12-15 11:42:46.000000000 +0000
@@ -76,6 +76,7 @@
     { NULL, "quiet", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
     { NULL, "leave-temps", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_CLAMSCAN, "", "" },
     { NULL, "no-warnings", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
+    { NULL, "show-progress", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
     { NULL, "stdout", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM | OPT_CLAMSCAN | OPT_CLAMDSCAN | OPT_SIGTOOL, "", "" },
     { NULL, "daemon", 'd', CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
     { NULL, "no-dns", 0, CLOPT_TYPE_BOOL, MATCH_BOOL, 0, NULL, 0, OPT_FRESHCLAM, "", "" },
diff -Naurw clamav-0.99/shared/output.c clamav-0.99_patched/shared/output.c
--- clamav-0.99/shared/output.c	2015-09-18 21:48:45.000000000 +0100
+++ clamav-0.99_patched/shared/output.c	2015-12-14 16:33:14.000000000 +0000
@@ -91,7 +91,7 @@
 #endif
 
 short int mprintf_disabled = 0, mprintf_verbose = 0, mprintf_quiet = 0,
-	  mprintf_stdout = 0, mprintf_nowarn = 0, mprintf_send_timeout = 100;
+	  mprintf_stdout = 0, mprintf_nowarn = 0, mprintf_send_timeout = 100, mprintf_progress = 0;
 
 #define ARGLEN(args, str, len)			    \
 {						    \
diff -Naurw clamav-0.99/shared/output.h clamav-0.99_patched/shared/output.h
--- clamav-0.99/shared/output.h	2015-09-18 21:48:45.000000000 +0100
+++ clamav-0.99_patched/shared/output.h	2015-12-14 16:32:43.000000000 +0000
@@ -61,6 +61,6 @@
 void mprintf(const char *str, ...);
 #endif
 
-extern short int mprintf_disabled, mprintf_verbose, mprintf_quiet, mprintf_nowarn, mprintf_stdout, mprintf_send_timeout;
+extern short int mprintf_disabled, mprintf_verbose, mprintf_quiet, mprintf_nowarn, mprintf_stdout, mprintf_send_timeout, mprintf_progress;
 
 #endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.