Skip to content
Snippets Groups Projects
Commit 5bcdea51 authored by Tilghman Lesher's avatar Tilghman Lesher
Browse files

Merged revisions 20966 via svnmerge from

https://origsvn.digium.com/svn/asterisk/branches/1.2

........
r20966 | tilghman | 2006-04-17 12:00:16 -0500 (Mon, 17 Apr 2006) | 2 lines

Bug 6544 - when we remove a music class, the thread servicing it should die

........


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@21002 65c4cc65-6c06-0410-ace0-fbb531ad65f3
parent fc071a18
Branches
Tags
No related merge requests found
...@@ -168,6 +168,10 @@ static void ast_moh_free_class(struct mohclass **class) ...@@ -168,6 +168,10 @@ static void ast_moh_free_class(struct mohclass **class)
members = members->next; members = members->next;
free(mtmp); free(mtmp);
} }
if ((*class)->thread) {
pthread_cancel((*class)->thread);
(*class)->thread = 0;
}
free(*class); free(*class);
*class = NULL; *class = NULL;
} }
...@@ -483,17 +487,20 @@ static void *monmp3thread(void *data) ...@@ -483,17 +487,20 @@ static void *monmp3thread(void *data)
tv.tv_sec = 0; tv.tv_sec = 0;
tv.tv_usec = 0; tv.tv_usec = 0;
for(;/* ever */;) { for(;/* ever */;) {
pthread_testcancel();
/* Spawn mp3 player if it's not there */ /* Spawn mp3 player if it's not there */
if (class->srcfd < 0) { if (class->srcfd < 0) {
if ((class->srcfd = spawn_mp3(class)) < 0) { if ((class->srcfd = spawn_mp3(class)) < 0) {
ast_log(LOG_WARNING, "Unable to spawn mp3player\n"); ast_log(LOG_WARNING, "Unable to spawn mp3player\n");
/* Try again later */ /* Try again later */
sleep(500); sleep(500);
pthread_testcancel();
} }
} }
if (class->pseudofd > -1) { if (class->pseudofd > -1) {
/* Pause some amount of time */ /* Pause some amount of time */
res = read(class->pseudofd, buf, sizeof(buf)); res = read(class->pseudofd, buf, sizeof(buf));
pthread_testcancel();
} else { } else {
long delta; long delta;
/* Reliable sleep */ /* Reliable sleep */
...@@ -504,6 +511,7 @@ static void *monmp3thread(void *data) ...@@ -504,6 +511,7 @@ static void *monmp3thread(void *data)
if (delta < MOH_MS_INTERVAL) { /* too early */ if (delta < MOH_MS_INTERVAL) { /* too early */
tv = ast_tvadd(tv, ast_samp2tv(MOH_MS_INTERVAL, 1000)); /* next deadline */ tv = ast_tvadd(tv, ast_samp2tv(MOH_MS_INTERVAL, 1000)); /* next deadline */
usleep(1000 * (MOH_MS_INTERVAL - delta)); usleep(1000 * (MOH_MS_INTERVAL - delta));
pthread_testcancel();
} else { } else {
ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n"); ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
tv = tv_tmp; tv = tv_tmp;
...@@ -519,7 +527,12 @@ static void *monmp3thread(void *data) ...@@ -519,7 +527,12 @@ static void *monmp3thread(void *data)
if (!res2) { if (!res2) {
close(class->srcfd); close(class->srcfd);
class->srcfd = -1; class->srcfd = -1;
pthread_testcancel();
if (class->pid) { if (class->pid) {
kill(class->pid, SIGHUP);
usleep(100000);
kill(class->pid, SIGTERM);
usleep(100000);
kill(class->pid, SIGKILL); kill(class->pid, SIGKILL);
class->pid = 0; class->pid = 0;
} }
...@@ -527,6 +540,7 @@ static void *monmp3thread(void *data) ...@@ -527,6 +540,7 @@ static void *monmp3thread(void *data)
ast_log(LOG_DEBUG, "Read %d bytes of audio while expecting %d\n", res2, len); ast_log(LOG_DEBUG, "Read %d bytes of audio while expecting %d\n", res2, len);
continue; continue;
} }
pthread_testcancel();
ast_mutex_lock(&moh_lock); ast_mutex_lock(&moh_lock);
moh = class->members; moh = class->members;
while (moh) { while (moh) {
...@@ -1064,6 +1078,13 @@ static void ast_moh_destroy(void) ...@@ -1064,6 +1078,13 @@ static void ast_moh_destroy(void)
stime = time(NULL) + 2; stime = time(NULL) + 2;
pid = moh->pid; pid = moh->pid;
moh->pid = 0; moh->pid = 0;
/* Back when this was just mpg123, SIGKILL was fine. Now we need
* to give the process a reason and time enough to kill off its
* children. */
kill(pid, SIGHUP);
usleep(100000);
kill(pid, SIGTERM);
usleep(100000);
kill(pid, SIGKILL); kill(pid, SIGKILL);
while ((ast_wait_for_input(moh->srcfd, 100) > 0) && (bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime) { while ((ast_wait_for_input(moh->srcfd, 100) > 0) && (bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime) {
tbytes = tbytes + bytes; tbytes = tbytes + bytes;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment