Procházet zdrojové kódy

libdpkg: Refactor error handler execution code

Move all longjmp calls to a new run_error_handler function.
Guillem Jover před 18 roky
rodič
revize
9080bf737b
2 změnil soubory, kde provedl 28 přidání a 5 odebrání
  1. 10 0
      ChangeLog
  2. 18 5
      lib/ehandle.c

+ 10 - 0
ChangeLog

@@ -1,3 +1,13 @@
+2008-11-14  Guillem Jover  <guillem@debian.org>
+
+	* lib/ehandle.c (run_error_handler): New function.
+	(push_error_handler): Use run_error_handler instead of directly
+	calling longjmp.
+	(ohshit): Likewise.
+	(ohshitvb): Likewise.
+	(ohshitv): Likewise.
+	(ohshite): Likewise.
+
 2008-11-07  Raphael Hertzog  <hertzog@debian.org>
 
 	* scripts/Dpkg/Version.pm: Synchronize code with version used by

+ 18 - 5
lib/ehandle.c

@@ -70,6 +70,14 @@ void set_error_display(error_printer *printerror,
   econtext->contextstring= contextstring;
 }
 
+static void run_error_handler(void) NONRETURNING;
+
+static void
+run_error_handler(void)
+{
+  longjmp(*econtext->jbufp, 1);
+}
+
 void push_error_handler(jmp_buf *jbufp,
                         error_printer *printerror,
                         const char *contextstring) {
@@ -80,7 +88,8 @@ void push_error_handler(jmp_buf *jbufp,
     snprintf(errmsgbuf, sizeof(errmsgbuf), "%s%s", 
 	    _("out of memory pushing error handler: "), strerror(e));
     errmsg= errmsgbuf;
-    if (econtext) longjmp(*econtext->jbufp,1);
+    if (econtext)
+      run_error_handler();
     fprintf(stderr, "%s: %s\n", thisname, errmsgbuf); exit(2);
   }
   necp->next= econtext;
@@ -219,7 +228,8 @@ void ohshit(const char *fmt, ...) {
   vsnprintf(errmsgbuf,sizeof(errmsgbuf),fmt,al);
   va_end(al);
   errmsg= errmsgbuf;
-  longjmp(*econtext->jbufp,1);
+
+  run_error_handler();
 }
 
 void print_error_fatal(const char *emsg, const char *contextstring) {
@@ -232,13 +242,15 @@ void ohshitvb(struct varbuf *vb) {
   m= m_malloc(strlen(vb->buf));
   strcpy(m,vb->buf);
   errmsg= m;
-  longjmp(*econtext->jbufp,1);
+
+  run_error_handler();
 }
 
 void ohshitv(const char *fmt, va_list al) {
   vsnprintf(errmsgbuf,sizeof(errmsgbuf),fmt,al);
   errmsg= errmsgbuf;
-  longjmp(*econtext->jbufp,1);
+
+  run_error_handler();
 }
 
 void ohshite(const char *fmt, ...) {
@@ -253,7 +265,8 @@ void ohshite(const char *fmt, ...) {
 
   snprintf(errmsgbuf,sizeof(errmsgbuf),"%s: %s",buf,strerror(e));
   errmsg= errmsgbuf; 
-  longjmp(*econtext->jbufp,1);
+
+  run_error_handler();
 }
 
 void warningf(const char *fmt, ...) {