summaryrefslogtreecommitdiff
path: root/p11-kit/conf.c
diff options
context:
space:
mode:
authorStef Walter <stef@thewalter.net>2013-08-26 14:48:59 +0200
committerStef Walter <stef@thewalter.net>2013-08-28 10:59:10 +0200
commitcdad5bceee79afbf8b3440b39c72890d2e67448d (patch)
treef07a8a45fd549a70277e4df9ae783fb996198c7d /p11-kit/conf.c
parente1042e93488f2b38abeea58b65440111df69afdc (diff)
Avoid multiple stat() calls for same file
As a side effect we can also not use the dirent.d_type field https://bugs.freedesktop.org/show_bug.cgi?id=68525
Diffstat (limited to 'p11-kit/conf.c')
-rw-r--r--p11-kit/conf.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/p11-kit/conf.c b/p11-kit/conf.c
index ef542f2..8a328ed 100644
--- a/p11-kit/conf.c
+++ b/p11-kit/conf.c
@@ -92,7 +92,9 @@ _p11_conf_merge_defaults (p11_dict *map,
}
p11_dict *
-_p11_conf_parse_file (const char* filename, int flags)
+_p11_conf_parse_file (const char* filename,
+ struct stat *sb,
+ int flags)
{
p11_dict *map = NULL;
void *data;
@@ -106,7 +108,7 @@ _p11_conf_parse_file (const char* filename, int flags)
p11_debug ("reading config file: %s", filename);
- mmap = p11_mmap_open (filename, &data, &length);
+ mmap = p11_mmap_open (filename, sb, &data, &length);
if (mmap == NULL) {
error = errno;
if ((flags & CONF_IGNORE_MISSING) &&
@@ -215,7 +217,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
*/
/* Load the main configuration */
- config = _p11_conf_parse_file (system_conf, CONF_IGNORE_MISSING);
+ config = _p11_conf_parse_file (system_conf, NULL, CONF_IGNORE_MISSING);
if (!config)
goto finished;
@@ -240,7 +242,7 @@ _p11_conf_load_globals (const char *system_conf, const char *user_conf,
/* Load up the user configuration, ignore selinux denying us access */
flags = CONF_IGNORE_MISSING | CONF_IGNORE_ACCESS_DENIED;
- uconfig = _p11_conf_parse_file (path, flags);
+ uconfig = _p11_conf_parse_file (path, NULL, flags);
if (!uconfig) {
error = errno;
goto finished;
@@ -325,6 +327,7 @@ calc_name_from_filename (const char *fname)
static bool
load_config_from_file (const char *configfile,
+ struct stat *sb,
const char *name,
p11_dict *configs,
int flags)
@@ -343,7 +346,7 @@ load_config_from_file (const char *configfile,
return_val_if_fail (key != NULL, false);
}
- config = _p11_conf_parse_file (configfile, flags);
+ config = _p11_conf_parse_file (configfile, sb, flags);
if (!config) {
free (key);
return false;
@@ -408,22 +411,16 @@ load_configs_from_directory (const char *directory,
path = p11_path_build (directory, dp->d_name, NULL);
return_val_if_fail (path != NULL, false);
-#ifdef HAVE_STRUCT_DIRENT_D_TYPE
- if(dp->d_type != DT_UNKNOWN) {
- is_dir = (dp->d_type == DT_DIR);
- } else
-#endif
- {
- if (stat (path, &st) < 0) {
- error = errno;
- p11_message_err (error, "couldn't stat path: %s", path);
- free (path);
- break;
- }
- is_dir = S_ISDIR (st.st_mode);
+ if (stat (path, &st) < 0) {
+ error = errno;
+ p11_message_err (error, "couldn't stat path: %s", path);
+ free (path);
+ break;
}
- if (!is_dir && !load_config_from_file (path, dp->d_name, configs, flags)) {
+ is_dir = S_ISDIR (st.st_mode);
+
+ if (!is_dir && !load_config_from_file (path, &st, dp->d_name, configs, flags)) {
error = errno;
free (path);
break;