diff options
author | Ken Raeburn <raeburn@mit.edu> | 2002-12-20 22:38:04 +0000 |
---|---|---|
committer | Ken Raeburn <raeburn@mit.edu> | 2002-12-20 22:38:04 +0000 |
commit | 7c28091d5daeb6431e6e76aeeca9ba1d33665d66 (patch) | |
tree | be6b961a9753ec8941509c03fa7c16fbbeabf4d9 /src/util/profile/prof_set.c | |
parent | 100ac673adeb87a48fa1deb2cff348af36a1c103 (diff) | |
download | krb5-7c28091d5daeb6431e6e76aeeca9ba1d33665d66.zip krb5-7c28091d5daeb6431e6e76aeeca9ba1d33665d66.tar.gz krb5-7c28091d5daeb6431e6e76aeeca9ba1d33665d66.tar.bz2 |
Merge in data tree sharing, minus locking support, plus a bugfix or two
* prof_int.h (SHARE_TREE_DATA): Define.
(struct _prf_file_t) [SHARE_TREE_DATA]: Make data field a pointer rather than
an array.
(struct global_shared_profile_data): New type, for profile library global
data.
(krb5int_profile_shared_data): Declare new variable.
(g_shared_trees): New macro, refers to a field in the global data.
(PROFILE_FILE_SHARED): New flag macro.
* prof_file.c (krb5int_profile_shared_data): Initialize here.
(profile_open_file) [SHARE_TREE_DATA]: Scan g_shared_trees for an entry with
the same filename. If found, increment its reference count, update it, and
return it; otherwise, allocate a new one, and add it to the list after filling
it in.
(profile_dereference_data): New function. Decrement reference count if
SHARE_TREE_DATA, and free the data if appropriate.
(profile_free_file): Call profile_dereference_data.
(profile_free_file_data) [SHARE_TREE_DATA]: If the SHARED flag is set, remove
it from the g_shared_trees list before freeing. Free up the allocated space.
* prof_set.c (rw_setup) [SHARE_TREE_DATA]: If the object's data is shared, copy
it into a new data structure not in the global shared list, and dereference the
old one.
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15060 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/util/profile/prof_set.c')
-rw-r--r-- | src/util/profile/prof_set.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/src/util/profile/prof_set.c b/src/util/profile/prof_set.c index 4c6ccb2..5abf5ec 100644 --- a/src/util/profile/prof_set.c +++ b/src/util/profile/prof_set.c @@ -24,7 +24,7 @@ static errcode_t rw_setup(profile) profile_t profile; { prf_file_t file; - errcode_t retval; + errcode_t retval = 0; if (!profile) return PROF_NO_PROFILE; @@ -39,7 +39,39 @@ static errcode_t rw_setup(profile) /* Don't update the file if we've already made modifications */ if (file->data->flags & PROFILE_FILE_DIRTY) return 0; - + +#ifdef SHARE_TREE_DATA + if ((file->data->flags & PROFILE_FILE_SHARED) != 0) { + prf_data_t new_data; + new_data = malloc(sizeof(struct _prf_data_t)); + if (new_data == NULL) { + retval = ENOMEM; + } else { + *new_data = *file->data; + /* We can blow away the information because update + will be called further down */ + new_data->comment = NULL; + new_data->root = NULL; + new_data->flags &= ~PROFILE_FILE_SHARED; + new_data->timestamp = 0; + /* copy the file spec */ + new_data->filespec = malloc(strlen(file->data->filespec) + 1); + if (new_data->filespec == NULL) { + retval = ENOMEM; + } else { + strcpy (new_data->filespec, file->data->filespec); + } + } + + if (retval != 0) { + free(new_data); + return retval; + } + profile_dereference_data(file->data); + file->data = new_data; + } +#endif /* SHARE_TREE_DATA */ + retval = profile_update_file(file); return retval; |