[Reproducible-commits] [dpkg] 15/30: libdpkg: Refactor and colorize abort printing into a new function

Mattia Rizzolo mattia at debian.org
Mon May 9 09:02:51 UTC 2016


This is an automated email from the git hooks/post-receive script.

mattia pushed a commit to branch pu/reproducible_builds
in repository dpkg.

commit 7b1652626d343b661794b4f1eb670eb14f984456
Author: Guillem Jover <guillem at debian.org>
Date:   Sat May 7 02:42:31 2016 +0200

    libdpkg: Refactor and colorize abort printing into a new function
---
 debian/changelog   |  1 +
 lib/dpkg/ehandle.c | 20 ++++++++++++--------
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 4e794d6..abf5581 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -12,6 +12,7 @@ dpkg (1.18.7) UNRELEASED; urgency=medium
     - In dselect to print main and access methods menu entries.
     - In libdpkg command-line option parsing errors.
     - In libdpkg warning, notice and info reporting.
+  * Colorize all fatal-error printing codepaths in libdpkg.
   * Perl modules:
     - Relax dependency restrictions parsing to allow again sloppy spaces
       around versions, architectures and profile restrictions.
diff --git a/lib/dpkg/ehandle.c b/lib/dpkg/ehandle.c
index 61c0792..1704df4 100644
--- a/lib/dpkg/ehandle.c
+++ b/lib/dpkg/ehandle.c
@@ -107,6 +107,14 @@ print_fatal_error(const char *emsg, const void *data)
           color_get(COLOR_ERROR), _("error"), color_reset(), emsg);
 }
 
+static void
+print_abort_error(const char *etype, const char *emsg)
+{
+  fprintf(stderr, _("%s%s%s: %s%s:%s\n %s\n"),
+          color_get(COLOR_PROG), dpkg_get_progname(), color_reset(),
+          color_get(COLOR_ERROR), etype, color_reset(), emsg);
+}
+
 static struct error_context *
 error_context_new(void)
 {
@@ -179,8 +187,7 @@ push_error_context(void)
 static void
 print_cleanup_error(const char *emsg, const void *data)
 {
-  fprintf(stderr, _("%s: error while cleaning up:\n %s\n"),
-          dpkg_get_progname(), emsg);
+  print_abort_error(_("error while cleaning up"), emsg);
 }
 
 static void
@@ -198,8 +205,7 @@ run_cleanups(struct error_context *econ, int flagsetin)
 
   if (++preventrecurse > 3) {
     onerr_abort++;
-    fprintf(stderr, _("%s: too many nested errors during error recovery!!\n"),
-            dpkg_get_progname());
+    print_cleanup_error(_("too many nested errors during error recovery"), NULL);
     flagset= 0;
   } else {
     flagset= flagsetin;
@@ -332,14 +338,12 @@ run_error_handler(void)
      * why we will not try to do any error unwinding either. We'll just
      * abort. Hopefully the user can fix the situation (out of disk, out
      * of memory, etc). */
-    fprintf(stderr, _("%s: unrecoverable fatal error, aborting:\n %s\n"),
-            dpkg_get_progname(), errmsg);
+    print_abort_error(_("unrecoverable fatal error, aborting"), errmsg);
     exit(2);
   }
 
   if (econtext == NULL) {
-    fprintf(stderr, _("%s: outside error context, aborting:\n %s\n"),
-            dpkg_get_progname(), errmsg);
+    print_abort_error(_("outside error context, aborting"), errmsg);
     exit(2);
   } else if (econtext->handler_type == HANDLER_TYPE_FUNC) {
     econtext->handler.func();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/dpkg.git



More information about the Reproducible-commits mailing list