aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandra Ellwood <lxs@mit.edu>2008-05-27 16:25:51 +0000
committerAlexandra Ellwood <lxs@mit.edu>2008-05-27 16:25:51 +0000
commit4130bdde9450dd7b399aa3650ef7ae3ff7d738da (patch)
tree33aea844c9614b43abb687ef63f5104663f88f89
parented90b10ddaaf6f681c0faa95f286a0bea84e5bb6 (diff)
downloadkrb5-4130bdde9450dd7b399aa3650ef7ae3ff7d738da.zip
krb5-4130bdde9450dd7b399aa3650ef7ae3ff7d738da.tar.gz
krb5-4130bdde9450dd7b399aa3650ef7ae3ff7d738da.tar.bz2
Profile library should not call rw_access earlier than needed
Call rw_access lazily so we only call access just before we need to write to the file to avoid calling access as often. Deprecated bit in profile structures to track writability. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20341 dc483132-0cff-0310-8789-dd5450dbe970
-rw-r--r--src/util/profile/prof_file.c15
-rw-r--r--src/util/profile/prof_init.c2
-rw-r--r--src/util/profile/prof_int.h12
3 files changed, 20 insertions, 9 deletions
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c
index c6f15fe..cee34ef 100644
--- a/src/util/profile/prof_file.c
+++ b/src/util/profile/prof_file.c
@@ -157,6 +157,15 @@ static int r_access(const_profile_filespec_t filespec)
#endif
}
+int profile_file_is_writable(prf_file_t profile)
+{
+ if (profile && profile->data) {
+ return rw_access(profile->data->filespec);
+ } else {
+ return 0;
+ }
+}
+
prf_data_t
profile_make_prf_data(const char *filename)
{
@@ -371,9 +380,7 @@ errcode_t profile_update_file_data(prf_data_t data)
}
set_cloexec_file(f);
data->upd_serial++;
- data->flags &= PROFILE_FILE_SHARED;
- if (rw_access(data->filespec))
- data->flags |= PROFILE_FILE_RW;
+ data->flags &= PROFILE_FILE_SHARED; /* FIXME same as '=' operator */
retval = profile_parse_file(f, &data->root);
fclose(f);
if (retval) {
@@ -472,8 +479,6 @@ static errcode_t write_data_to_file(prf_data_t data, const char *outfile,
}
data->flags = 0;
- if (rw_access(outfile))
- data->flags |= PROFILE_FILE_RW;
retval = 0;
errout:
diff --git a/src/util/profile/prof_init.c b/src/util/profile/prof_init.c
index 9a5659a..f0ff137 100644
--- a/src/util/profile/prof_init.c
+++ b/src/util/profile/prof_init.c
@@ -160,7 +160,7 @@ profile_is_writable(profile_t profile, int *writable)
return EINVAL;
if (profile->first_file)
- *writable = (profile->first_file->data->flags & PROFILE_FILE_RW);
+ *writable = profile_file_is_writable(profile->first_file);
return 0;
}
diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h
index d6349af..02e1f21 100644
--- a/src/util/profile/prof_int.h
+++ b/src/util/profile/prof_int.h
@@ -72,10 +72,13 @@ typedef struct _prf_file_t *prf_file_t;
/*
* The profile flags
+ *
+ * Deprecated use of read/write profile flag.
+ * Check whether file is writable lazily so we don't call access as often.
*/
-#define PROFILE_FILE_RW 0x0001
-#define PROFILE_FILE_DIRTY 0x0002
-#define PROFILE_FILE_SHARED 0x0004
+#define PROFILE_FILE_DEPRECATED_RW 0x0001
+#define PROFILE_FILE_DIRTY 0x0002
+#define PROFILE_FILE_SHARED 0x0004
/*
* This structure defines the high-level, user visible profile_t
@@ -218,6 +221,9 @@ void profile_free_file
errcode_t profile_close_file
(prf_file_t profile);
+int profile_file_is_writable
+ (prf_file_t profile);
+
void profile_dereference_data (prf_data_t);
void profile_dereference_data_locked (prf_data_t);