]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
Improve child process reaping (bug #278)
authorMark Spencer <markster@digium.com>
Tue, 16 Sep 2003 19:35:57 +0000 (19:35 +0000)
committerMark Spencer <markster@digium.com>
Tue, 16 Sep 2003 19:35:57 +0000 (19:35 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@1521 65c4cc65-6c06-0410-ace0-fbb531ad65f3

asterisk.c
res/res_musiconhold.c

index 88c5f01ceec10d21eeb288253b0f81c8b36f13db..d8a6563e0e5970bd2eae28918c34061760bebfe9 100755 (executable)
@@ -337,11 +337,19 @@ static void hup_handler(int num)
        ast_module_reload();
 }
 
-
-static void pipe_handler(int num)
+static void child_handler(int sig)
 {
-       /* Ignore sigpipe */
+       int n, status;
+
+       /*
+        * Reap all dead children -- not just one
+        */
+       for (n = 0; wait4(-1, &status, WNOHANG, NULL) > 0; n++)
+               ;
+       if (n == 0 && option_debug)     
+               ast_log(LOG_DEBUG, "Huh?  Child handler, but nobody there?\n");
 }
+
 static void set_title(char *text)
 {
        /* Set an X-term or screen title */
@@ -1366,11 +1374,14 @@ int main(int argc, char *argv[])
        }
        if (option_console && !option_verbose) 
                ast_verbose("[ Booting...");
+
        signal(SIGURG, urg_handler);
        signal(SIGINT, __quit_handler);
        signal(SIGTERM, __quit_handler);
        signal(SIGHUP, hup_handler);
-       signal(SIGPIPE, pipe_handler);
+       signal(SIGCHLD, child_handler);
+       signal(SIGPIPE, SIG_IGN);
+
        if (set_priority(option_highpriority)) {
                printf(term_quit());
                exit(1);
index 3dc78fba0242df06cd9fa13e3c71908f693aa187..3dccd4eb3fc5609a83370ef202e5dc21346aa7ea 100755 (executable)
@@ -94,17 +94,10 @@ static struct mohclass *mohclasses;
 
 static ast_mutex_t moh_lock = AST_MUTEX_INITIALIZER;
 
+#define LOCAL_MPG_123 "/usr/local/bin/mpg123"
 #define MPG_123 "/usr/bin/mpg123"
 #define MAX_MP3S 256
 
-static void child_handler(int sig)
-{
-       int status;
-       if (wait4(-1,&status, WNOHANG, NULL)<1) 
-               if (option_debug)       
-                       ast_log(LOG_DEBUG, "Huh?  Child handler, but nobody there?\n");
-}
-
 static int spawn_mp3(struct mohclass *class)
 {
        int fds[2];
@@ -121,7 +114,7 @@ static int spawn_mp3(struct mohclass *class)
                ast_log(LOG_WARNING, "%s is not a valid directory\n", class->dir);
                return -1;
        }
-       argv[0] = MPG_123;
+       argv[0] = "mpg123";
        argv[1] = "-q";
        argv[2] = "-s";
        argv[3] = "--mono";
@@ -190,7 +183,12 @@ static int spawn_mp3(struct mohclass *class)
                        close(x);
                /* Child */
                chdir(class->dir);
+               /* Default install is /usr/local/bin */
+               execv(LOCAL_MPG_123, argv);
+               /* Many places have it in /usr/bin */
                execv(MPG_123, argv);
+               /* Check PATH as a last-ditch effort */
+               execvp("mpg123", argv);
                ast_log(LOG_WARNING, "Exec failed: %s\n", strerror(errno));
                exit(1);
        } else {
@@ -220,7 +218,6 @@ static void *monmp3thread(void *data)
        tv.tv_usec = 0;
        error_sec = 0;
        error_usec = 0;
-       signal(SIGCHLD, child_handler);
        for(;/* ever */;) {
                /* Spawn mp3 player if it's not there */
                if (class->srcfd < 0)  {