Profile library should not call rw_access earlier than needed
authorAlexandra Ellwood <lxs@mit.edu>
Tue, 27 May 2008 16:25:51 +0000 (16:25 +0000)
committerAlexandra Ellwood <lxs@mit.edu>
Tue, 27 May 2008 16:25:51 +0000 (16:25 +0000)
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

src/util/profile/prof_file.c
src/util/profile/prof_init.c
src/util/profile/prof_int.h

index c6f15fee599ff1ea0f173f318aa8b2d4e053cb58..cee34ef2c8455d250cd52a84099ae70b1c07a167 100644 (file)
@@ -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:
index 9a5659a8ce1c220ee55741674c205c234adff7a9..f0ff1370c33ca83db9934701a8a487f56c8c61cc 100644 (file)
@@ -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;
 }
index d6349afd725ea34f01931adbfbb27edaa34cf5c9..02e1f21da72552686a772b8331a5c0350ad588af 100644 (file)
@@ -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);