revert patch from bug #4532 until CPU consumption problem can be resolved

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6111 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Kevin P. Fleming
2005-07-12 18:57:20 +00:00
parent 4bcf6f7806
commit 37184c4244

View File

@@ -402,44 +402,19 @@ static int spawn_mp3(struct mohclass *class)
ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno)); ast_log(LOG_WARNING, "Fork failed: %s\n", strerror(errno));
return -1; return -1;
} }
if (class->pid != 0) { /* parent */ if (!class->pid) {
close(fds[1]); int x;
return fds[0]; close(fds[0]);
} else { /* Stdout goes to pipe */
/* Child */ dup2(fds[1], STDOUT_FILENO);
int i; /* Close unused file descriptors */
/* for (x=3;x<8192;x++) {
* On BSD systems with userland pthreads libraries, we need if (-1 != fcntl(x, F_GETFL)) {
* to call fcntl() _before_ close() to avoid resetting close(x);
* O_NONBLOCK on the internal descriptors.
* It should not harm in other systems.
*
* After that, close the descriptors not needed in the child.
* It is also important that we do not share descriptors
* with the child process or it could change their blocking
* state and give trouble in the thread scheduling.
* Here, parent and child are connected only through the
* endpoints of a pipe, so they share no descriptors.
*/
for (i=0; i < getdtablesize(); i++) {
long fl = fcntl(i, F_GETFL);
if (fl != -1 && i != fds[1]) {
/* open and must be closed in the child */
fcntl(i, F_SETFL, O_NONBLOCK | fl);
close(i);
} }
} }
/* Stdout in the child goes to pipe */ /* Child */
dup2(fds[1], STDOUT_FILENO);
chdir(class->dir); chdir(class->dir);
/*
* mpg123 may fork children to be more responsive, and we
* want to kill them all when we exit. To do so we set
* the process group id of mpg123 and children to a different
* value than the asterisk process so we can kill all at once.
* So remember, class->pid is really class->pgid!
*/
setpgid(0, getpid());
if (ast_test_flag(class, MOH_CUSTOM)) { if (ast_test_flag(class, MOH_CUSTOM)) {
execv(argv[0], argv); execv(argv[0], argv);
} else { } else {
@@ -450,9 +425,14 @@ static int spawn_mp3(struct mohclass *class)
/* Check PATH as a last-ditch effort */ /* Check PATH as a last-ditch effort */
execvp("mpg123", argv); execvp("mpg123", argv);
} }
ast_log(LOG_WARNING, "Exec failed: %s\n", strerror(errno));
close(fds[1]);
exit(1); exit(1);
return 0; /* unreached */ } else {
/* Parent */
close(fds[1]);
} }
return fds[0];
} }
static void *monmp3thread(void *data) static void *monmp3thread(void *data)
@@ -531,7 +511,7 @@ static void *monmp3thread(void *data)
close(class->srcfd); close(class->srcfd);
class->srcfd = -1; class->srcfd = -1;
if (class->pid) { if (class->pid) {
killpg(class->pid, SIGKILL); /* pgid! */ kill(class->pid, SIGKILL);
class->pid = 0; class->pid = 0;
} }
} else } else
@@ -977,7 +957,7 @@ 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;
killpg(pid, SIGKILL); /* pgid! */ kill(pid, SIGKILL);
while ((ast_wait_for_input(moh->srcfd, 100) > -1) && (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; tbytes = tbytes + bytes;
} }