diff --git a/modules/event_flatstore/event_flatstore.c b/modules/event_flatstore/event_flatstore.c index 490731a34..fd28847c9 100644 --- a/modules/event_flatstore/event_flatstore.c +++ b/modules/event_flatstore/event_flatstore.c @@ -249,6 +249,20 @@ static struct flat_socket *search_for_fd(str value){ return NULL; } +/* search for a file descriptor using the file's path and version and update */ +static int update_fd_version(str file_path, int src_version, int target_version){ + int count = 0; + struct flat_socket *list = *list_files; + while (list != NULL) { + if (str_cmp(list->path, file_path) && list->rotate_version == src_version) { + list->rotate_version = target_version; + count++; + } + list = list->next; + } + return count; +} + static struct mi_root* mi_rotate(struct mi_root* root, void *param){ /* sanity checks */ @@ -276,11 +290,11 @@ static struct mi_root* mi_rotate(struct mi_root* root, void *param){ return init_mi_tree( 400, MI_SSTR("File not found")); } - LM_DBG("Found file descriptor and updating rotating version for %s, to %d\n", - found_fd->path.s, found_fd->rotate_version + 1); - - found_fd->rotate_version++; + int num_of_fd = update_fd_version(root->node.kids->value, found_fd->rotate_version, found_fd->rotate_version+1); + LM_DBG("Found %d file descriptor(s) rotating fd(s) for %s, to version %d\n", + num_of_fd, found_fd->path.s, found_fd->rotate_version); + lock_release(global_lock); /* return a mi_root structure with a success return code*/