tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: getnameinfo(3) thread-safety



Hi,

2013/8/14 Christos Zoulas <christos%astron.com@localhost>:
> In article <1l7ljcq.aabx667531krM%manu%netbsd.org@localhost>,
> Emmanuel Dreyfus <manu%netbsd.org@localhost> wrote:
>>Hi
>>
>>getnameinfo(3) man page says the function is not thread safe. What is
>>the preferred method for getting the name for an address stored in a
>>sockaddr_t, in a threaded program?
>
> Ours is, IIRC. We could remove the restriction from the man page.

I reported that getnameinfo(3) is not thread safe as lib/46454.
http://gnats.netbsd.org/46454

The work arround patch is following, but the rwlock may cause speed down.

Index: lib/libc/net/nsdispatch.c
===================================================================
RCS file: /cvsroot/src/lib/libc/net/nsdispatch.c,v
retrieving revision 1.37
diff -u -r1.37 nsdispatch.c
--- lib/libc/net/nsdispatch.c       13 Mar 2012 21:13:42 -0000      1.37
+++ lib/libc/net/nsdispatch.c       15 May 2012 05:59:09 -0000
@@ -646,7 +646,7 @@
            return (NS_UNAVAIL);
    }

-   rwlock_rdlock(&_nslock);
+   rwlock_wrlock(&_nslock);

    key.name = database;
    dbt = bsearch(&key, _nsmap, _nsmapsize, sizeof(*_nsmap), _nsdbtcmp);


Thanks,


Home | Main Index | Thread Index | Old Index