aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authormmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-03-26 19:22:16 +0000
committermmichelson <mmichelson@f38db490-d61c-443f-a65b-d21fe96a405b>2008-03-26 19:22:16 +0000
commit241f567d5ab8aff0e96cd5bd9bde2a61946d5e03 (patch)
tree09b82424ad2fb4fffedc2f6abc981de59bd8cc28 /apps
parent9b7ad2d24f8f97cc09bf6c1e10aa29ba8c7fb795 (diff)
Add a lock to the vm_state structure and use the lock around mail_open calls
to prevent concurrent access of the same mailstream. This, along with trunk's ability to configure TCP timeouts for IMAP storage will help to prevent crashes and hangs when using voicemail with IMAP storage. (closes issue #10487) Reported by: ewilhelmsen git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.4@111049 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rw-r--r--apps/app_voicemail.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index 59e751c4d..97e26f66c 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -372,6 +372,7 @@ struct vm_state {
int starting;
int repeats;
#ifdef IMAP_STORAGE
+ ast_mutex_t lock;
int updated; /* decremented on each mail check until 1 -allows delay */
long msgArray[256];
MAILSTREAM *mailstream;
@@ -4781,7 +4782,9 @@ static int init_mailstream(struct vm_state *vms, int box)
#endif
/* Connect to INBOX first to get folders delimiter */
imap_mailbox_name(tmp, sizeof(tmp), vms, 0, 1);
+ ast_mutex_lock(&vms->lock);
stream = mail_open (stream, tmp, debug ? OP_DEBUG : NIL);
+ ast_mutex_unlock(&vms->lock);
if (stream == NIL) {
ast_log (LOG_ERROR, "Can't connect to imap server %s\n", tmp);
return -1;
@@ -4796,7 +4799,9 @@ static int init_mailstream(struct vm_state *vms, int box)
imap_mailbox_name(tmp, sizeof(tmp), vms, box, 1);
if (option_debug > 2)
ast_log (LOG_DEBUG,"Before mail_open, server: %s, box:%d\n", tmp, box);
+ ast_mutex_lock(&vms->lock);
vms->mailstream = mail_open (stream, tmp, debug ? OP_DEBUG : NIL);
+ ast_mutex_unlock(&vms->lock);
if (vms->mailstream == NIL) {
return -1;
} else {
@@ -9026,6 +9031,7 @@ static void vmstate_delete(struct vm_state *vms)
if (!vf) {
ast_log(LOG_ERROR, "No vmstate found for user:%s, mailbox %s\n",vms->imapuser,vms->username);
} else {
+ ast_mutex_destroy(&vms->lock);
free(vf);
}
ast_mutex_unlock(&vmstate_lock);
@@ -9057,6 +9063,7 @@ static void init_vm_state(struct vm_state *vms)
for (x = 0; x < 256; x++) {
vms->msgArray[x] = 0;
}
+ ast_mutex_init(&vms->lock);
}
static void check_msgArray(struct vm_state *vms)