Просмотр исходного кода

libdpkg: Refactor default error handler into new catch_fatal_error()

Guillem Jover лет назад: 15
Родитель
Сommit
c1f899c832
7 измененных файлов с 19 добавлено и 5 удалено
  1. 1 1
      dselect/main.cc
  2. 1 1
      lib/dpkg/dpkg.h
  3. 13 0
      lib/dpkg/ehandle.c
  4. 1 0
      lib/dpkg/ehandle.h
  5. 1 0
      lib/dpkg/libdpkg.Versions
  6. 1 2
      lib/dpkg/test.h
  7. 1 1
      src/main.c

+ 1 - 1
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);
 

+ 1 - 1
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. */\

+ 13 - 0
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);
 }

+ 1 - 0
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);

+ 1 - 0
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;

+ 1 - 2
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);
 

+ 1 - 1
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 (;;) {