From badc4dec4681a14695ef64d067a012d4aaa215fa Mon Sep 17 00:00:00 2001 From: Mark Spencer Date: Sat, 5 Mar 2005 03:20:55 +0000 Subject: [PATCH] Make mpg123 behave more nicely git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5142 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- include/asterisk/utils.h | 1 + res/res_musiconhold.c | 4 ++-- utils.c | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index f766ff4ca1..590815320a 100755 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -136,6 +136,7 @@ extern int test_for_thread_safety(void); extern const char *ast_inet_ntoa(char *buf, int bufsiz, struct in_addr ia); extern int ast_utils_init(void); +extern int ast_wait_for_input(int fd, int ms); /* The realloca lets us ast_restrdupa(), but you can't mix any other ast_strdup calls! */ diff --git a/res/res_musiconhold.c b/res/res_musiconhold.c index f948e206f8..7e386c7955 100755 --- a/res/res_musiconhold.c +++ b/res/res_musiconhold.c @@ -945,11 +945,11 @@ static void ast_moh_destroy(void) while (moh) { if (moh->pid) { ast_log(LOG_DEBUG, "killing %d!\n", moh->pid); - stime = time(NULL) + 5; + stime = time(NULL) + 2; pid = moh->pid; moh->pid = 0; kill(pid, SIGKILL); - while ((bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime) { + while ((ast_wait_for_input(moh->srcfd, 100) > -1) && (bytes = read(moh->srcfd, buff, 8192)) && time(NULL) < stime) { tbytes = tbytes + bytes; } ast_log(LOG_DEBUG, "mpg123 pid %d and child died after %d bytes read\n", pid, tbytes); diff --git a/utils.c b/utils.c index 3e9ddf67b3..ab71677f59 100755 --- a/utils.c +++ b/utils.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include @@ -404,6 +405,15 @@ int ast_pthread_create_stack(pthread_t *thread, pthread_attr_t *attr, void *(*st return pthread_create(thread, attr, start_routine, data); /* We're in ast_pthread_create, so it's okay */ } +int ast_wait_for_input(int fd, int ms) +{ + struct pollfd pfd[1]; + memset(pfd, 0, sizeof(pfd)); + pfd[0].fd = fd; + pfd[0].events = POLLIN|POLLPRI; + return poll(pfd, 1, ms); +} + /* Case-insensitive substring matching */ #ifndef LINUX static char *upper(const char *orig, char *buf, int bufsize)