diff --git a/main/file.c b/main/file.c index ffae33b5a0..6912a37bce 100644 --- a/main/file.c +++ b/main/file.c @@ -29,6 +29,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$") #include #include +#include #include #include "asterisk/_private.h" /* declare ast_file_init() */ @@ -289,6 +290,8 @@ static int exts_compare(const char *exts, const char *type) static void filestream_destructor(void *arg) { struct ast_filestream *f = arg; + int status; + int pid = -1; /* Stop a running stream if there is one */ if (f->owner) { @@ -306,8 +309,14 @@ static void filestream_destructor(void *arg) ast_translator_free_path(f->trans); if (f->realfilename && f->filename) { - if (ast_safe_fork(0) == 0) { + pid = ast_safe_fork(0); + if (!pid) { execl("/bin/mv", "mv", "-f", f->filename, f->realfilename, SENTINEL); + _exit(1); + } + else if (pid > 0) { + /* Block the parent until the move is complete.*/ + waitpid(pid, &status, 0); } }