This is the mail archive of the mailing list for the glibc project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] getXXent_r and getXXbyYY_r not really thread safe


The glibc getXXent_r and getXXbyYY_r functions are not really thread
safe, not even for files. You can see this, if you run setpwent(),
getpwent_r(), endpwent() from multiple threads on a UP machine. Every
thread will get another number of entries. Using "passwd: files nis"
with 1630 entries gives me:

4: found 272 entries
2: found 599 entries
3: found 1006 entries
5: found 1548 entries
1: found 2367 entries
0: found 3993 entries

There are two different problems:

One problem is, that a thread runs more than once through "files" or
"nis", because the pointer, which stores which service is currently in
use by a thread and which should be used as next, can be modified by
another thread in the meantime.

The other problem is, that another thread can modify the current file
handle (or NIS data) and a thread will get the same entry more than
once or never.

The only solution I found for this is to use thread local storage
for this static data, which has to be preserved over multiple
function calls in the same thread.

With my patches, I get:

3: found 1630 entries
0: found 1630 entries
5: found 1630 entries
2: found 1630 entries
1: found 1630 entries
4: found 1630 entries

There are 4 patches attached:

- for libc itself
- for nss_files
- for nss_nis

I have also attached a patch for nss_compat. But I have one problem
with nss_compat patch: nss_compat will crash in or not work correct
in other ways sometimes, and I have no idea what happens here.

Comments about how to solve better the #if mess?


Thorsten Kukuk
SuSE Linux AG        Maxfeldstr. 5                 D-90409 Nuernberg
Key fingerprint = A368 676B 5E1B 3E46 CFCE  2D97 F8FD 4E23 56C6 FB4B

Attachment: glibc-2.3.3-nss_glibc.diff
Description: Text document

Attachment: glibc-2.3.3-nss_files.diff
Description: Text document

Attachment: glibc-2.3.3-nss_nis.diff
Description: Text document

Attachment: glibc-2.3.3-nss_compat.diff
Description: Text document

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]