[asterisk-commits] rmudgett: branch 10 r377070 - in /branches/10: ./ main/cdr.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Dec 3 12:41:32 CST 2012


Author: rmudgett
Date: Mon Dec  3 12:41:28 2012
New Revision: 377070

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=377070
Log:
Cleanup CDR resources on exit.

* Simplify do_reload() return handling since it never returned anything
other than 0.

(issue ASTERISK-20649)
Reported by: Corey Farrell
Patches:
      cdr-cleanup-1_8.patch (license #5909) patch uploaded by Corey Farrell
      cdr-cleanup-10-11-trunk.patch (license #5909) patch uploaded by Corey Farrell
      Modified
........

Merged revisions 377069 from http://svn.asterisk.org/svn/asterisk/branches/1.8

Modified:
    branches/10/   (props changed)
    branches/10/main/cdr.c

Propchange: branches/10/
------------------------------------------------------------------------------
Binary property 'branch-1.8-merged' - no diff available.

Modified: branches/10/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/branches/10/main/cdr.c?view=diff&rev=377070&r1=377069&r2=377070
==============================================================================
--- branches/10/main/cdr.c (original)
+++ branches/10/main/cdr.c Mon Dec  3 12:41:28 2012
@@ -1481,7 +1481,7 @@
 static struct ast_cli_entry cli_submit = AST_CLI_DEFINE(handle_cli_submit, "Posts all pending batched CDR data");
 static struct ast_cli_entry cli_status = AST_CLI_DEFINE(handle_cli_status, "Display the CDR status");
 
-static int do_reload(int reload)
+static void do_reload(int reload)
 {
 	struct ast_config *config;
 	const char *enabled_value;
@@ -1497,11 +1497,10 @@
 	int cfg_time;
 	int was_enabled;
 	int was_batchmode;
-	int res=0;
 	struct ast_flags config_flags = { reload ? CONFIG_FLAG_FILEUNCHANGED : 0 };
 
 	if ((config = ast_config_load2("cdr.conf", "cdr", config_flags)) == CONFIG_STATUS_FILEUNCHANGED) {
-		return 0;
+		return;
 	}
 
 	ast_mutex_lock(&cdr_batch_lock);
@@ -1519,7 +1518,7 @@
 
 	if (config == CONFIG_STATUS_FILEMISSING || config == CONFIG_STATUS_FILEINVALID) {
 		ast_mutex_unlock(&cdr_batch_lock);
-		return 0;
+		return;
 	}
 
 	/* don't run the next scheduled CDR posting while reloading */
@@ -1582,7 +1581,6 @@
 		} else {
 			ast_cli_register(&cli_submit);
 			ast_register_atexit(ast_cdr_engine_term);
-			res = 0;
 		}
 	/* if this reload disabled the CDR and/or batch mode and there is a background thread,
 	   kill it */
@@ -1595,27 +1593,39 @@
 		ast_cond_destroy(&cdr_pending_cond);
 		ast_cli_unregister(&cli_submit);
 		ast_unregister_atexit(ast_cdr_engine_term);
-		res = 0;
 		/* if leaving batch mode, then post the CDRs in the batch,
 		   and don't reschedule, since we are stopping CDR logging */
 		if (!batchmode && was_batchmode) {
 			ast_cdr_engine_term();
 		}
-	} else {
-		res = 0;
 	}
 
 	ast_mutex_unlock(&cdr_batch_lock);
 	ast_config_destroy(config);
 	manager_event(EVENT_FLAG_SYSTEM, "Reload", "Module: CDR\r\nMessage: CDR subsystem reload requested\r\n");
-
-	return res;
+}
+
+static void cdr_engine_shutdown(void)
+{
+	if (cdr_thread != AST_PTHREADT_NULL) {
+		/* wake up the thread so it will exit */
+		pthread_cancel(cdr_thread);
+		pthread_kill(cdr_thread, SIGURG);
+		pthread_join(cdr_thread, NULL);
+		cdr_thread = AST_PTHREADT_NULL;
+		ast_cond_destroy(&cdr_pending_cond);
+	}
+	ast_cli_unregister(&cli_submit);
+
+	ast_cli_unregister(&cli_status);
+	ast_sched_context_destroy(sched);
+	sched = NULL;
+	ast_free(batch);
+	batch = NULL;
 }
 
 int ast_cdr_engine_init(void)
 {
-	int res;
-
 	sched = ast_sched_context_create();
 	if (!sched) {
 		ast_log(LOG_ERROR, "Unable to create schedule context.\n");
@@ -1623,15 +1633,10 @@
 	}
 
 	ast_cli_register(&cli_status);
-
-	res = do_reload(0);
-	if (res) {
-		ast_mutex_lock(&cdr_batch_lock);
-		res = init_batch();
-		ast_mutex_unlock(&cdr_batch_lock);
-	}
-
-	return res;
+	do_reload(0);
+	ast_register_atexit(cdr_engine_shutdown);
+
+	return 0;
 }
 
 /* \note This actually gets called a couple of times at shutdown.  Once, before we start
@@ -1643,7 +1648,8 @@
 
 int ast_cdr_engine_reload(void)
 {
-	return do_reload(1);
+	do_reload(1);
+	return 0;
 }
 
 int ast_cdr_data_add_structure(struct ast_data *tree, struct ast_cdr *cdr, int recur)




More information about the asterisk-commits mailing list