The following commit has been merged in the master branch:
commit c1f899c832f5c676a8f3b36366605da1599760f6
Author: Guillem Jover <[email protected]>
Date:   Sun Oct 10 12:04:20 2010 +0200

    libdpkg: Refactor default error handler into new catch_fatal_error()

diff --git a/dselect/main.cc b/dselect/main.cc
index 9b3ad46..0510823 100644
--- a/dselect/main.cc
+++ b/dselect/main.cc
@@ -507,7 +507,7 @@ int main(int, const char *const *argv) {
 
   if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
     cursesoff();
-    error_unwind(ehflag_bombout); exit(2);
+    catch_fatal_error();
   }
   push_error_handler(&ejbuf,print_error_fatal,0);
 
diff --git a/lib/dpkg/dpkg.h b/lib/dpkg/dpkg.h
index 97950e9..8a8bbff 100644
--- a/lib/dpkg/dpkg.h
+++ b/lib/dpkg/dpkg.h
@@ -108,7 +108,7 @@ DPKG_BEGIN_DECLS
 
 #define standard_startup(ejbuf) do {\
   if (setjmp(*ejbuf)) { /* expect warning about possible clobbering of argv */\
-    error_unwind(ehflag_bombout); exit(2);\
+    catch_fatal_error(); \
   }\
   push_error_handler(ejbuf, print_error_fatal, NULL); \
   umask(022); /* Make sure all our status databases are readable. */\
diff --git a/lib/dpkg/ehandle.c b/lib/dpkg/ehandle.c
index 7345b27..8d85f79 100644
--- a/lib/dpkg/ehandle.c
+++ b/lib/dpkg/ehandle.c
@@ -259,6 +259,19 @@ void ohshit(const char *fmt, ...) {
   run_error_handler();
 }
 
+/**
+ * Default fatal error handler.
+ *
+ * This handler performs all error unwinding for the current context, and
+ * terminates the program with an error exit code.
+ */
+void
+catch_fatal_error(void)
+{
+  error_unwind(ehflag_bombout);
+  exit(2);
+}
+
 void print_error_fatal(const char *emsg, const char *contextstring) {
   fprintf(stderr, "%s: %s\n",thisname,emsg);
 }
diff --git a/lib/dpkg/ehandle.h b/lib/dpkg/ehandle.h
index 856cd19..96ad86d 100644
--- a/lib/dpkg/ehandle.h
+++ b/lib/dpkg/ehandle.h
@@ -43,6 +43,7 @@ enum {
 typedef void error_printer(const char *emsg, const char *contextstring);
 
 void print_error_fatal(const char *emsg, const char *contextstring);
+void catch_fatal_error(void);
 
 void push_error_handler(jmp_buf *jbufp, error_printer *printerror,
                         const char *contextstring);
diff --git a/lib/dpkg/libdpkg.Versions b/lib/dpkg/libdpkg.Versions
index be9ba22..cf460c4 100644
--- a/lib/dpkg/libdpkg.Versions
+++ b/lib/dpkg/libdpkg.Versions
@@ -11,6 +11,7 @@ LIBDPKG_PRIVATE {
        # Error handling
        set_error_display;
        print_error_fatal;
+       catch_fatal_error;
        push_error_handler;
        push_checkpoint;
        push_cleanup;
diff --git a/lib/dpkg/test.h b/lib/dpkg/test.h
index eb18f17..9a48332 100644
--- a/lib/dpkg/test.h
+++ b/lib/dpkg/test.h
@@ -47,8 +47,7 @@ main(int argc, char **argv)
 
        /* Initialize environment. */
        if (setjmp(ejbuf)) {
-               error_unwind(ehflag_bombout);
-               return 2;
+               catch_fatal_error();
        }
        push_error_handler(&ejbuf, print_error_fatal, NULL);
 
diff --git a/src/main.c b/src/main.c
index 79324ef..b04a636 100644
--- a/src/main.c
+++ b/src/main.c
@@ -588,7 +588,7 @@ void commandfd(const char *const *argv) {
     ohshite(_("couldn't open `%i' for stream"), (int) infd);
 
   if (setjmp(ejbuf)) { /* expect warning about possible clobbering of argv */
-    error_unwind(ehflag_bombout); exit(2);
+    catch_fatal_error();
   }
 
   for (;;) {

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to