]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
error_message.c, init_et.c: Segregate error tables registered
authorTheodore Ts'o <tytso@mit.edu>
Mon, 20 Jun 2005 21:59:06 +0000 (17:59 -0400)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 20 Jun 2005 21:59:06 +0000 (17:59 -0400)
via add_error_table() and the other dynamic methods from
the ones allocated via initialize_xxx_error_table() so
that we won't fail even for error tables created using old
versions of compile_et.  Thanks to Nalin Dahyabhai for
this suggested patch.

lib/et/ChangeLog
lib/et/error_message.c
lib/et/init_et.c

index aa4880f8cdb2afa58ea2177ca944f0d900984090..72f86873ad6bbefcd38eb8bad452ded7c66bd9c4 100644 (file)
@@ -1,5 +1,12 @@
 2005-06-20  Theodore Ts'o  <tytso@mit.edu>
 
+       * error_message.c, init_et.c: Segregate error tables registered
+               via add_error_table() and the other dynamic methods from
+               the ones allocated via initialize_xxx_error_table() so
+               that we won't fail even for error tables created using old
+               versions of compile_et.  Thanks to Nalin Dahyabhai for
+               this suggested patch.
+
        * et_c.awk: Use a dynamically allocated structure in
                initialize_xxx_error_table(), to prevent segfaults if an
                old library calls initialize_xxx_error_table, and another
index 9326308c77aa8264c3fefcb8ed01363443dc8bed..90d63c417f1a6ada35bc568b48314f5f1fd3564d 100644 (file)
@@ -27,6 +27,7 @@
 static char buffer[25];
 
 struct et_list * _et_list = (struct et_list *) NULL;
+struct et_list * _et_dynamic_list = (struct et_list *) NULL;
 
 
 const char * error_message (errcode_t code)
@@ -61,6 +62,14 @@ const char * error_message (errcode_t code)
            return(et->table->msgs[offset]);
        }
     }
+    for (et = _et_dynamic_list; et; et = et->next) {
+       if (et->table->base == table_num) {
+           /* This is the right table */
+           if (et->table->n_msgs <= offset)
+               goto oops;
+           return(et->table->msgs[offset]);
+       }
+    }
 oops:
     strcpy (buffer, "Unknown code ");
     if (table_num) {
@@ -88,20 +97,14 @@ oops:
  */
 errcode_t add_error_table(const struct error_table * et)
 {
-       struct et_list *el = _et_list;
-
-       while (el) {
-               if (el->table->base == et->base)
-                       return EEXIST;
-               el = el->next;
-       }
+       struct et_list *el;
 
        if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
                return ENOMEM;
 
        el->table = et;
-       el->next = _et_list;
-       _et_list = el;
+       el->next = _et_dynamic_list;
+       _et_dynamic_list = el;
 
        return 0;
 }
@@ -111,7 +114,7 @@ errcode_t add_error_table(const struct error_table * et)
  */
 errcode_t remove_error_table(const struct error_table * et)
 {
-       struct et_list *el = _et_list;
+       struct et_list *el = _et_dynamic_list;
        struct et_list *el2 = 0;
 
        while (el) {
@@ -119,7 +122,7 @@ errcode_t remove_error_table(const struct error_table * et)
                        if (el2)        /* Not the beginning of the list */
                                el2->next = el->next;
                        else
-                               _et_list = el->next;
+                               _et_dynamic_list = el->next;
                        (void) free(el);
                        return 0;
                }
index 075d26a88b64e343cdca4ee394f2e47b335a0b19..bf27da11cc7a6fc8b62dce42de79a6df8022fcbd 100644 (file)
@@ -29,7 +29,7 @@ struct foobar {
     struct error_table et;
 };
 
-extern struct et_list * _et_list;
+extern struct et_list * _et_dynamic_list;
 
 int init_error_table(const char * const *msgs, long base, int count)
 {
@@ -46,7 +46,7 @@ int init_error_table(const char * const *msgs, long base, int count)
     new_et->et.base = base;
     new_et->et.n_msgs= count;
 
-    new_et->etl.next = _et_list;
-    _et_list = &new_et->etl;
+    new_et->etl.next = _et_dynamic_list;
+    _et_dynamic_list = &new_et->etl;
     return 0;
 }