diff options
author | ed <ed@FreeBSD.org> | 2012-03-23 08:26:31 +0000 |
---|---|---|
committer | ed <ed@FreeBSD.org> | 2012-03-23 08:26:31 +0000 |
commit | 0818e862f45bc216835a0ed2623cc5855081713b (patch) | |
tree | ec23fad22b2e9397ae04846e69fbfbe37fa32529 /lib | |
parent | 106fa4a89cf02d0101a11cf994f58d850e50b527 (diff) | |
download | FreeBSD-src-0818e862f45bc216835a0ed2623cc5855081713b.zip FreeBSD-src-0818e862f45bc216835a0ed2623cc5855081713b.tar.gz |
Make utmpx(3) thread safe if we support TLS.
Because the utmpx interface is generally not required to be thread-safe,
but it is nice to have, if easy to do so. Therefore don't make a mess
out of the code and only use it if __NO_TLS is not defined.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/gen/getutxent.c | 5 | ||||
-rw-r--r-- | lib/libc/gen/utxdb.c | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/lib/libc/gen/getutxent.c b/lib/libc/gen/getutxent.c index 4e60868..a2e938a 100644 --- a/lib/libc/gen/getutxent.c +++ b/lib/libc/gen/getutxent.c @@ -38,8 +38,13 @@ __FBSDID("$FreeBSD$"); #include "utxdb.h" #include "un-namespace.h" +#ifdef __NO_TLS static FILE *uf = NULL; static int udb; +#else +static _Thread_local FILE *uf = NULL; +static _Thread_local int udb; +#endif int setutxdb(int db, const char *file) diff --git a/lib/libc/gen/utxdb.c b/lib/libc/gen/utxdb.c index 743629d..6667129 100644 --- a/lib/libc/gen/utxdb.c +++ b/lib/libc/gen/utxdb.c @@ -126,7 +126,11 @@ utx_to_futx(const struct utmpx *ut, struct futx *fu) struct utmpx * futx_to_utx(const struct futx *fu) { +#ifdef __NO_TLS static struct utmpx *ut; +#else + static _Thread_local struct utmpx *ut; +#endif if (ut == NULL) { ut = calloc(1, sizeof *ut); |