diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/util/profile/prof_file.c | 28 | ||||
| -rw-r--r-- | src/util/profile/prof_int.h | 3 | ||||
| -rw-r--r-- | src/util/profile/prof_tree.c | 9 |
3 files changed, 19 insertions, 21 deletions
diff --git a/src/util/profile/prof_file.c b/src/util/profile/prof_file.c index fad1b2871..b24fa59f9 100644 --- a/src/util/profile/prof_file.c +++ b/src/util/profile/prof_file.c @@ -303,7 +303,7 @@ errcode_t profile_open_file(const_profile_filespec_t filespec, return 0; } -errcode_t profile_update_file_data(prf_data_t data) +errcode_t profile_update_file_data_locked(prf_data_t data) { errcode_t retval; #ifdef HAVE_STAT @@ -313,20 +313,13 @@ errcode_t profile_update_file_data(prf_data_t data) #endif FILE *f; - retval = k5_mutex_lock(&data->lock); - if (retval) - return retval; - #ifdef HAVE_STAT now = time(0); if (now == data->last_stat && data->root != NULL) { - k5_mutex_unlock(&data->lock); return 0; } if (stat(data->filespec, &st)) { - retval = errno; - k5_mutex_unlock(&data->lock); - return retval; + return errno; } data->last_stat = now; #if defined HAVE_STRUCT_STAT_ST_MTIMENSEC @@ -341,7 +334,6 @@ errcode_t profile_update_file_data(prf_data_t data) if (st.st_mtime == data->timestamp && frac == data->frac_ts && data->root != NULL) { - k5_mutex_unlock(&data->lock); return 0; } if (data->root) { @@ -359,7 +351,6 @@ errcode_t profile_update_file_data(prf_data_t data) * profile file if it changes. */ if (data->root) { - k5_mutex_unlock(&data->lock); return 0; } #endif @@ -367,7 +358,6 @@ errcode_t profile_update_file_data(prf_data_t data) f = fopen(data->filespec, "r"); if (f == NULL) { retval = errno; - k5_mutex_unlock(&data->lock); if (retval == 0) retval = ENOENT; return retval; @@ -378,7 +368,6 @@ errcode_t profile_update_file_data(prf_data_t data) retval = profile_parse_file(f, &data->root); fclose(f); if (retval) { - k5_mutex_unlock(&data->lock); return retval; } assert(data->root != NULL); @@ -386,10 +375,21 @@ errcode_t profile_update_file_data(prf_data_t data) data->timestamp = st.st_mtime; data->frac_ts = frac; #endif - k5_mutex_unlock(&data->lock); return 0; } +errcode_t profile_update_file_data(prf_data_t data) +{ + errcode_t retval, retval2; + + retval = k5_mutex_lock(&data->lock); + if (retval) + return retval; + retval = profile_update_file_data_locked(data); + retval2 = k5_mutex_unlock(&data->lock); + return retval ? retval : retval2; +} + static int make_hard_link(const char *oldpath, const char *newpath) { diff --git a/src/util/profile/prof_int.h b/src/util/profile/prof_int.h index 02e1f21da..216c5986d 100644 --- a/src/util/profile/prof_int.h +++ b/src/util/profile/prof_int.h @@ -203,6 +203,9 @@ errcode_t profile_open_file #define profile_update_file(P) profile_update_file_data((P)->data) errcode_t profile_update_file_data (prf_data_t profile); +#define profile_update_file_locked(P) profile_update_file_data_locked((P)->data) +errcode_t profile_update_file_data_locked + (prf_data_t data); #define profile_flush_file(P) (((P) && (P)->magic == PROF_MAGIC_FILE) ? profile_flush_file_data((P)->data) : PROF_MAGIC_FILE) errcode_t profile_flush_file_data diff --git a/src/util/profile/prof_tree.c b/src/util/profile/prof_tree.c index 2b644a935..d8db45daf 100644 --- a/src/util/profile/prof_tree.c +++ b/src/util/profile/prof_tree.c @@ -497,8 +497,8 @@ get_new_file: *ret_value =0; return 0; } - k5_mutex_unlock(&iter->file->data->lock); - if ((retval = profile_update_file(iter->file))) { + if ((retval = profile_update_file_locked(iter->file))) { + k5_mutex_unlock(&iter->file->data->lock); if (retval == ENOENT || retval == EACCES) { /* XXX memory leak? */ iter->file = iter->file->next; @@ -517,11 +517,6 @@ get_new_file: return retval; } } - retval = k5_mutex_lock(&iter->file->data->lock); - if (retval) { - profile_node_iterator_free(iter_p); - return retval; - } iter->file_serial = iter->file->data->upd_serial; /* * Find the section to list if we are a LIST_SECTION, |
