Adds a wrapper for fork(2) that drops and real-time priority. The function ast_dropprio_fork() should perhaps be added in another file. --- asterisk/asterisk.c.ORIG 2004-11-10 20:55:50.000000000 +0100 +++ asterisk/asterisk.c 2004-11-10 21:22:33.000000000 +0100 @@ -187,7 +187,7 @@ struct rusage rusage; int status; void (*prev_handler) = signal(SIGCHLD, null_sig_handler); - pid = fork(); + pid = ast_dropprio_fork(); if (pid == 0) { /* Close file descriptors and launch system command */ for (x=STDERR_FILENO + 1; x<4096;x++) { @@ -518,6 +518,18 @@ return 0; } +pid_t ast_dropprio_fork(void) +{ + pid_t pid; + + pid = fork(); + if (pid == 0) { + /* This is the child. Drop elevated priority */ + set_priority(0); + } + return pid; +} + static void ast_run_atexits(void) { struct ast_atexit *ae; --- asterisk/include/asterisk/app.h.wf-dropprio-fork 2005-01-22 13:31:14.000000000 +0100 +++ asterisk/include/asterisk/app.h 2005-01-22 13:53:35.000000000 +0100 @@ -53,6 +53,9 @@ /*! Safely spawn an external program while closingn file descriptors */ extern int ast_safe_system(const char *s); +/*! Fork and drop elevated priority in the child */ +extern pid_t ast_dropprio_fork(void); + /*! Send DTMF to chan (optionally entertain peer) */ int ast_dtmf_stream(struct ast_channel *chan, struct ast_channel *peer, char *digits, int between); --- asterisk/apps/app_festival.c.ORIG 2004-11-10 21:22:56.000000000 +0100 +++ asterisk/apps/app_festival.c 2004-11-10 21:23:39.000000000 +0100 @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -111,7 +112,7 @@ char c; #endif - res = fork(); + res = ast_dropprio_fork(); if (res < 0) ast_log(LOG_WARNING, "Fork failed\n"); if (res) --- asterisk/apps/app_ices.c.ORIG 2004-11-10 21:24:11.000000000 +0100 +++ asterisk/apps/app_ices.c 2004-11-10 21:24:59.000000000 +0100 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -52,7 +53,7 @@ { int res; int x; - res = fork(); + res = ast_dropprio_fork(); if (res < 0) ast_log(LOG_WARNING, "Fork failed\n"); if (res) --- asterisk/apps/app_mp3.c.ORIG 2004-11-10 21:25:20.000000000 +0100 +++ asterisk/apps/app_mp3.c 2004-11-10 21:25:36.000000000 +0100 @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -49,7 +50,7 @@ { int res; int x; - res = fork(); + res = ast_dropprio_fork(); if (res < 0) ast_log(LOG_WARNING, "Fork failed\n"); if (res) --- asterisk/res/res_musiconhold.c.ORIG 2004-11-10 08:59:32.000000000 +0100 +++ asterisk/res/res_musiconhold.c 2004-11-10 21:27:43.000000000 +0100 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -211,7 +212,7 @@ sleep(respawn_time - (time(NULL) - class->start)); } time(&class->start); - class->pid = fork(); + class->pid = ast_dropprio_fork(); if (class->pid < 0) { close(fds[0]); close(fds[1]); --- asterisk/res/res_agi.c.ORIG 2004-11-10 21:26:24.000000000 +0100 +++ asterisk/res/res_agi.c 2004-11-10 21:26:45.000000000 +0100 @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -242,7 +243,7 @@ return -1; } } - pid = fork(); + pid = ast_dropprio_fork(); if (pid < 0) { ast_log(LOG_WARNING, "Failed to fork(): %s\n", strerror(errno)); return -1;