make h_errno thread-local
authorRich Felker <dalias@aerifal.cx>
Tue, 25 Aug 2020 01:38:49 +0000 (21:38 -0400)
committerRich Felker <dalias@aerifal.cx>
Tue, 25 Aug 2020 01:38:49 +0000 (21:38 -0400)
the framework to do this always existed but it was deemed unnecessary
because the only [ex-]standard functions using h_errno were not
thread-safe anyway. however, some of the nonstandard res_* functions
are also supposed to set h_errno to indicate the cause of error, and
were unable to do so because it was not thread-safe. this change is a
prerequisite for fixing them.

src/internal/pthread_impl.h
src/network/h_errno.c

index 5742dfc..5749a33 100644 (file)
@@ -43,6 +43,7 @@ struct pthread {
                long off;
                volatile void *volatile pending;
        } robust_list;
+       int h_errno_val;
        volatile int timer_id;
        locale_t locale;
        volatile int killlock[1];
index 4f700ce..8677a92 100644 (file)
@@ -1,9 +1,7 @@
 #include <netdb.h>
-
-#undef h_errno
-int h_errno;
+#include "pthread_impl.h"
 
 int *__h_errno_location(void)
 {
-       return &h_errno;
+       return &__pthread_self()->h_errno_val;
 }