Index: res/res_musiconhold.c =================================================================== --- res/res_musiconhold.c (revision 103754) +++ res/res_musiconhold.c (working copy) @@ -992,18 +992,17 @@ int x; #endif struct mohclass *mohclass = NULL; + int res = 0; AST_RWLIST_WRLOCK(&mohclasses); if ((mohclass = get_mohbyname(moh->name, 0)) && !moh_diff(mohclass, moh)) { - mohclass->delete = 0; - if (reload) { - ast_debug(1, "Music on Hold class '%s' left alone from initial load.\n", moh->name); - } else { + if (!mohclass->delete) { + mohclass->delete = 0; ast_log(LOG_WARNING, "Music on Hold class '%s' already exists\n", moh->name); + ast_free(moh); + AST_RWLIST_UNLOCK(&mohclasses); + return -1; } - ast_free(moh); - AST_RWLIST_UNLOCK(&mohclasses); - return -1; } AST_RWLIST_UNLOCK(&mohclasses); @@ -1011,7 +1010,12 @@ moh->start -= respawn_time; if (!strcasecmp(moh->mode, "files")) { - if (!moh_scan_files(moh)) { + res = moh_scan_files(moh); + if (res <= 0) { + if (res == 0) { + if (option_verbose > 2) + ast_verbose(VERBOSE_PREFIX_3 "Files not found in %s for moh class:%s\n", moh->dir, moh->name); + } ast_moh_free_class(&moh); return -1; } @@ -1404,7 +1408,6 @@ /* Don't leak a class when it's already registered */ moh_register(class, reload); - numclasses++; } } @@ -1568,14 +1571,6 @@ AST_RWLIST_REMOVE_CURRENT(list); if (!moh->inuse) ast_moh_destroy_one(moh); - } else if (moh->total_files) { - if (moh_scan_files(moh) <= 0) { - ast_log(LOG_WARNING, "No files found for class '%s'\n", moh->name); - moh->delete = 1; - AST_LIST_REMOVE_CURRENT(list); - if (!moh->inuse) - ast_moh_destroy_one(moh); - } } } AST_RWLIST_TRAVERSE_SAFE_END @@ -1619,7 +1614,31 @@ static int unload_module(void) { - return -1; + int res = 0; + struct mohclass *class = NULL; + + AST_RWLIST_WRLOCK(&mohclasses); + AST_LIST_TRAVERSE(&mohclasses, class, list) { + if (class->inuse > 0) { + res = -1; + break; + } + } + AST_RWLIST_UNLOCK(&mohclasses); + if (res < 0) { + ast_log(LOG_WARNING, "Unable to unload res_musiconhold due to active MOH channels\n"); + return res; + } + + ast_uninstall_music_functions(); + ast_moh_destroy(); + res = ast_unregister_application(play_moh); + res |= ast_unregister_application(wait_moh); + res |= ast_unregister_application(set_moh); + res |= ast_unregister_application(start_moh); + res |= ast_unregister_application(stop_moh); + ast_cli_unregister_multiple(cli_moh, sizeof(cli_moh) / sizeof(struct ast_cli_entry)); + return res; } AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Music On Hold Resource",