diff options
author | Panu Matilainen <pmatilai@redhat.com> | 2013-02-15 15:20:09 +0200 |
---|---|---|
committer | Panu Matilainen <pmatilai@redhat.com> | 2013-02-15 15:20:09 +0200 |
commit | 713273858dd1048625eacae0bb680e14e9aef06b (patch) | |
tree | 07614668ab0898d056ec0aeb03a98bee5ddc6064 /rpmio/rpmfileutil.c | |
parent | 1db6c86c8aed8428352854ca12f6fd17182a4156 (diff) | |
download | rpm-713273858dd1048625eacae0bb680e14e9aef06b.tar.gz |
Make rpmConfigDir() thread-safe
Diffstat (limited to 'rpmio/rpmfileutil.c')
-rw-r--r-- | rpmio/rpmfileutil.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/rpmio/rpmfileutil.c b/rpmio/rpmfileutil.c index b116146fa..f411266cd 100644 --- a/rpmio/rpmfileutil.c +++ b/rpmio/rpmfileutil.c @@ -19,6 +19,7 @@ #include <errno.h> #include <popt.h> #include <ctype.h> +#include <pthread.h> #include <rpm/rpmfileutil.h> #include <rpm/rpmurl.h> @@ -31,6 +32,7 @@ #include "debug.h" static const char *rpm_config_dir = NULL; +static pthread_once_t configDirSet = PTHREAD_ONCE_INIT; static int is_prelinked(int fdno) { @@ -599,11 +601,14 @@ int rpmMkdirs(const char *root, const char *pathstr) return rc; } +static void setConfigDir(void) +{ + char *rpmenv = getenv("RPM_CONFIGDIR"); + rpm_config_dir = rpmenv ? xstrdup(rpmenv) : RPMCONFIGDIR; +} + const char *rpmConfigDir(void) { - if (rpm_config_dir == NULL) { - char *rpmenv = getenv("RPM_CONFIGDIR"); - rpm_config_dir = rpmenv ? xstrdup(rpmenv) : RPMCONFIGDIR; - } + pthread_once(&configDirSet, setConfigDir); return rpm_config_dir; } |