forked from pool/e2fsprogs
178 lines
5.1 KiB
Diff
178 lines
5.1 KiB
Diff
--- e2fsprogs-1.39/lib/et/com_err.pc.in
|
|
+++ e2fsprogs-1.39/lib/et/com_err.pc.in
|
|
@@ -7,5 +7,5 @@
|
|
Description: Common error description library
|
|
Version: @E2FSPROGS_VERSION@
|
|
Requires:
|
|
-Cflags: -I${includedir}
|
|
-Libs: -L${libdir} -lcom_err
|
|
+Cflags: -I${includedir} -pthread
|
|
+Libs: -L${libdir} -lcom_err -pthread
|
|
--- e2fsprogs-1.39/lib/et/error_message.c
|
|
+++ e2fsprogs-1.39/lib/et/error_message.c
|
|
@@ -20,6 +20,7 @@
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
+#include <pthread.h>
|
|
#include "com_err.h"
|
|
#include "error_table.h"
|
|
#include "internal.h"
|
|
@@ -27,6 +28,17 @@
|
|
struct et_list * _et_list = (struct et_list *) NULL;
|
|
struct et_list * _et_dynamic_list = (struct et_list *) NULL;
|
|
|
|
+static pthread_mutex_t _et_lock = PTHREAD_MUTEX_INITIALIZER;
|
|
+
|
|
+int et_list_lock()
|
|
+{
|
|
+ return pthread_mutex_lock(&_et_lock);
|
|
+}
|
|
+
|
|
+int et_list_unlock()
|
|
+{
|
|
+ return pthread_mutex_unlock(&_et_lock);
|
|
+}
|
|
|
|
const char * error_message (errcode_t code)
|
|
{
|
|
@@ -51,22 +63,32 @@
|
|
goto oops;
|
|
#endif
|
|
}
|
|
+ et_list_lock();
|
|
for (et = _et_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]);
|
|
+ if (et->table->n_msgs <= offset) {
|
|
+ break;
|
|
+ } else {
|
|
+ const char *msg = et->table->msgs[offset];
|
|
+ et_list_unlock();
|
|
+ return(msg);
|
|
+ }
|
|
}
|
|
}
|
|
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]);
|
|
+ if (et->table->n_msgs <= offset) {
|
|
+ break;
|
|
+ } else {
|
|
+ const char *msg = et->table->msgs[offset];
|
|
+ et_list_unlock();
|
|
+ return(msg);
|
|
+ }
|
|
}
|
|
}
|
|
+ et_list_unlock();
|
|
oops:
|
|
return "Unknown code";
|
|
}
|
|
@@ -81,10 +103,14 @@
|
|
if (!(el = (struct et_list *) malloc(sizeof(struct et_list))))
|
|
return ENOMEM;
|
|
|
|
+ if( 0 != et_list_lock())
|
|
+ return errno;
|
|
+
|
|
el->table = et;
|
|
el->next = _et_dynamic_list;
|
|
_et_dynamic_list = el;
|
|
|
|
+ et_list_unlock();
|
|
return 0;
|
|
}
|
|
|
|
@@ -93,9 +119,13 @@
|
|
*/
|
|
errcode_t remove_error_table(const struct error_table * et)
|
|
{
|
|
- struct et_list *el = _et_dynamic_list;
|
|
+ struct et_list *el;
|
|
struct et_list *el2 = 0;
|
|
|
|
+ if( 0 != et_list_lock())
|
|
+ return ENOENT;
|
|
+
|
|
+ el = _et_dynamic_list;
|
|
while (el) {
|
|
if (el->table->base == et->base) {
|
|
if (el2) /* Not the beginning of the list */
|
|
@@ -103,11 +133,13 @@
|
|
else
|
|
_et_dynamic_list = el->next;
|
|
(void) free(el);
|
|
+ et_list_unlock();
|
|
return 0;
|
|
}
|
|
el2 = el;
|
|
el = el->next;
|
|
}
|
|
+ et_list_unlock();
|
|
return ENOENT;
|
|
}
|
|
|
|
--- e2fsprogs-1.39/lib/et/error_table.h
|
|
+++ e2fsprogs-1.39/lib/et/error_table.h
|
|
@@ -19,6 +19,8 @@
|
|
const struct error_table *table;
|
|
};
|
|
extern struct et_list * _et_list;
|
|
+extern int et_list_lock(void);
|
|
+extern int et_list_unlock(void);
|
|
|
|
#define ERRCODE_RANGE 8 /* # of bits to shift table number */
|
|
#define BITS_PER_CHAR 6 /* # bits to shift per character in name */
|
|
--- e2fsprogs-1.39/lib/et/et_c.awk
|
|
+++ e2fsprogs-1.39/lib/et/et_c.awk
|
|
@@ -225,6 +225,8 @@
|
|
print " const struct error_table * table;" > outfile
|
|
print "};" > outfile
|
|
print "extern struct et_list *_et_list;" > outfile
|
|
+ print "extern int et_list_lock();" > outfile
|
|
+ print "extern int et_list_unlock();" > outfile
|
|
print "" > outfile
|
|
if (tab_base_high == 0) {
|
|
print "const struct error_table et_" table_name "_error_table = { text, " \
|
|
@@ -242,7 +244,22 @@
|
|
print "void initialize_" table_name "_error_table(void);" > outfile
|
|
print "" > outfile
|
|
print "void initialize_" table_name "_error_table(void) {" > outfile
|
|
- print " initialize_" table_name "_error_table_r(&_et_list);" > outfile
|
|
+ print " if(0 == et_list_lock()) {" > outfile
|
|
+ print " if ( !link.table) {" > outfile
|
|
+ print " struct et_list *el = _et_list;" > outfile
|
|
+ print " while (el) {" > outfile
|
|
+ print " if (el->table->base == et_" table_name "_error_table.base) {" > outfile
|
|
+ print " et_list_unlock();" > outfile
|
|
+ print " return;" > outfile
|
|
+ print " }" > outfile
|
|
+ print " el = el->next;" > outfile
|
|
+ print " }" > outfile
|
|
+ print " link.next = _et_list;" > outfile
|
|
+ print " link.table = &et_" table_name "_error_table;" > outfile
|
|
+ print " _et_list = &link;" > outfile
|
|
+ print " }" > outfile
|
|
+ print " et_list_unlock();" > outfile
|
|
+ print " }" > outfile
|
|
print "}" > outfile
|
|
print "" > outfile
|
|
print "/* For Heimdal compatibility */" > outfile
|
|
@@ -255,9 +272,6 @@
|
|
print " return;" > outfile
|
|
print " et = malloc(sizeof(struct et_list));" > outfile
|
|
print " if (et == 0) {" > outfile
|
|
- print " if (!link.table)" > outfile
|
|
- print " et = &link;" > outfile
|
|
- print " else" > outfile
|
|
print " return;" > outfile
|
|
print " }" > outfile
|
|
print " et->table = &et_" table_name "_error_table;" > outfile
|