aboutsummaryrefslogtreecommitdiffstats
path: root/main/file.c
diff options
context:
space:
mode:
authormjordan <mjordan@f38db490-d61c-443f-a65b-d21fe96a405b>2011-07-05 13:38:37 +0000
committermjordan <mjordan@f38db490-d61c-443f-a65b-d21fe96a405b>2011-07-05 13:38:37 +0000
commit0359d5c64359aefbf9ede3f3e9420b8397f7235c (patch)
tree83325484d5c4bc87222fe568b48f4455fc43dbb0 /main/file.c
parentd4d597bf7bbf8aa85a0afc7104975deddde625a7 (diff)
Merged revisions 326209 via svnmerge from
https://origsvn.digium.com/svn/asterisk/branches/1.8 ........ r326209 | mjordan | 2011-07-05 08:23:57 -0500 (Tue, 05 Jul 2011) | 7 lines 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: http://svn.digium.com/svn/asterisk/trunk@326210 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/file.c')
-rw-r--r--main/file.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/main/file.c b/main/file.c
index ffae33b5a..6912a37bc 100644
--- a/main/file.c
+++ b/main/file.c
@@ -29,6 +29,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include <dirent.h>
#include <sys/stat.h>
+#include <sys/wait.h>
#include <math.h>
#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);
}
}