From: Alexandra Ellwood Date: Tue, 27 May 2008 16:25:51 +0000 (+0000) Subject: Profile library should not call rw_access earlier than needed X-Git-Tag: krb5-1.7-alpha1~677 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4130bdde9450dd7b399aa3650ef7ae3ff7d738da;p=krb5.git 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 --- diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index c6f15fee5..cee34ef2c 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 9a5659a8c..f0ff1370c 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 d6349afd7..02e1f21da 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);