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.
This commit is contained in:
Ed Schouten 2012-03-23 08:26:31 +00:00
parent 7ea3cd35f9
commit 126b6df920
2 changed files with 9 additions and 0 deletions

View File

@ -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)

View File

@ -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);