From 46289ce3a01fe68c0d80d6eddcacd73f10d9f5fe Mon Sep 17 00:00:00 2001 From: Matthew Jordan Date: Tue, 5 Jul 2011 13:23:57 +0000 Subject: [PATCH] Updated filestream destructor to block until move is complete when cache is used When a cache directory is used, the process is forked and a mv command is executed to move the temporary file to the permanent location. This caused issues with voicemail, where a race condition occurred when the parent expected the file to be in the permanent location prior to the mv command completing. The parent process is now blocked until the mv command completes. (closes issue ASTERISK-17724) Reported by: Adiren P. Tested by: mjordan git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.8@326209 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- main/file.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/main/file.c b/main/file.c index 9195748af4..7b01646e5e 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() */ @@ -291,6 +292,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) { @@ -308,8 +311,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); } } -- 2.47.2