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:
parent
7ea3cd35f9
commit
126b6df920
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user