aboutsummaryrefslogtreecommitdiffstats
path: root/res
diff options
context:
space:
mode:
authorroot <root@f38db490-d61c-443f-a65b-d21fe96a405b>2006-04-17 17:06:46 +0000
committerroot <root@f38db490-d61c-443f-a65b-d21fe96a405b>2006-04-17 17:06:46 +0000
commit70e94d1733eaf522c1bd7dec02c30adf2f7e76fa (patch)
treeffbec00670464fced096f17e3477306220eb8f86 /res
parent9ffdc094925aedede5e706ea9f8103c78c81065b (diff)
automerge commit
git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2-netsec@21001 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'res')
-rw-r--r--res/res_musiconhold.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c
index 97ae3d871..d31bf08ac 100644
--- a/res/res_musiconhold.c
+++ b/res/res_musiconhold.c
@@ -166,6 +166,10 @@ static void ast_moh_free_class(struct mohclass **class)
members = members->next;
free(mtmp);
}
+ if ((*class)->thread) {
+ pthread_cancel((*class)->thread);
+ (*class)->thread = 0;
+ }
free(*class);
*class = NULL;
}
@@ -482,17 +486,20 @@ static void *monmp3thread(void *data)
tv.tv_sec = 0;
tv.tv_usec = 0;
for(;/* ever */;) {
+ pthread_testcancel();
/* Spawn mp3 player if it's not there */
if (class->srcfd < 0) {
if ((class->srcfd = spawn_mp3(class)) < 0) {
ast_log(LOG_WARNING, "Unable to spawn mp3player\n");
/* Try again later */
sleep(500);
+ pthread_testcancel();
}
}
if (class->pseudofd > -1) {
/* Pause some amount of time */
res = read(class->pseudofd, buf, sizeof(buf));
+ pthread_testcancel();
} else {
long delta;
/* Reliable sleep */
@@ -503,6 +510,7 @@ static void *monmp3thread(void *data)
if (delta < MOH_MS_INTERVAL) { /* too early */
tv = ast_tvadd(tv, ast_samp2tv(MOH_MS_INTERVAL, 1000)); /* next deadline */
usleep(1000 * (MOH_MS_INTERVAL - delta));
+ pthread_testcancel();
} else {
ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
tv = tv_tmp;
@@ -518,7 +526,12 @@ static void *monmp3thread(void *data)
if (!res2) {
close(class->srcfd);
class->srcfd = -1;
+ pthread_testcancel();
if (class->pid) {
+ kill(class->pid, SIGHUP);
+ usleep(100000);
+ kill(class->pid, SIGTERM);
+ usleep(100000);
kill(class->pid, SIGKILL);
class->pid = 0;
}
@@ -526,6 +539,7 @@ static void *monmp3thread(void *data)
ast_log(LOG_DEBUG, "Read %d bytes of audio while expecting %d\n", res2, len);
continue;
}
+ pthread_testcancel();
ast_mutex_lock(&moh_lock);
moh = class->members;
while (moh) {
@@ -1078,6 +1092,13 @@ static void ast_moh_destroy(void)
stime = time(NULL) + 2;
pid = moh->pid;
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);
while ((ast_wait_for_input(moh->srcfd, 100) > 0) && (bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime) {
tbytes = tbytes + bytes;