<p>Sean Bright has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/11246">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">app_voicemail: Cleanup stale lock files on module load<br><br>If Asterisk crashes while a VM directory is locked, lock files in the VM<br>spool directory will not get properly cleaned up. We now clear them on<br>module load.<br><br>ASTERISK-20207 #close<br>Reported by: Steven Wheeler<br><br>Change-Id: If40ccd508e2f6e5ade94dde2f0bcef99056d0aaf<br>---<br>M apps/app_voicemail.c<br>1 file changed, 51 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/46/11246/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c</span><br><span>index 64167d1..407afab 100644</span><br><span>--- a/apps/app_voicemail.c</span><br><span>+++ b/apps/app_voicemail.c</span><br><span>@@ -3795,6 +3795,54 @@</span><br><span> </span><br><span> #endif /* IMAP_STORAGE */</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static void cleanup_orphaned_lock_files(const char *base)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ DIR *dir;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct dirent *e;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ dir = opendir(base);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!dir) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Don't complain about this too loudly */</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_debug(2, "Unable to open `%s': %s\n", base, strerror(errno));</span><br><span style="color: hsl(120, 100%, 40%);">+ return;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ while ((e = readdir(dir))) {</span><br><span style="color: hsl(120, 100%, 40%);">+ char *fullpath;</span><br><span style="color: hsl(120, 100%, 40%);">+ struct stat s;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Always skip . and .. */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, "..")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Build up the full path (using dynamic memory because PATH_MAX is crap) */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_asprintf(&fullpath, "%s/%s", base, e->d_name) == -1) {</span><br><span style="color: hsl(120, 100%, 40%);">+ break;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (lstat(fullpath, &s) < 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(fullpath);</span><br><span style="color: hsl(120, 100%, 40%);">+ continue;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* This is exposing an implementation detail of ast_lock_path, but it makes</span><br><span style="color: hsl(120, 100%, 40%);">+ * our life a bit easier */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!strcmp(e->d_name, ".lock") && S_ISLNK(s.st_mode)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_unlock_path(base)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(AST_LOG_NOTICE, "Cleaned up ophaned lock file: %s/.lock\n", base);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ } else if (S_ISDIR(s.st_mode)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* If it is a directory, let's dive down */</span><br><span style="color: hsl(120, 100%, 40%);">+ cleanup_orphaned_lock_files(fullpath);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(fullpath);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ closedir(dir);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> /*! \brief Lock file path</span><br><span> * only return failure if ast_lock_path returns 'timeout',</span><br><span> * not if the path does not exist or any other reason</span><br><span>@@ -15306,6 +15354,9 @@</span><br><span> /* compute the location of the voicemail spool directory */</span><br><span> snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Now that we have a spool directory, clean up old lock files */</span><br><span style="color: hsl(120, 100%, 40%);">+ cleanup_orphaned_lock_files(VM_SPOOL_DIR);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> if (!(mwi_subscription_tps = ast_taskprocessor_get("app_voicemail", 0))) {</span><br><span> ast_log(AST_LOG_WARNING, "failed to reference mwi subscription taskprocessor. MWI will not work\n");</span><br><span> }</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/11246">change 11246</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/11246"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: If40ccd508e2f6e5ade94dde2f0bcef99056d0aaf </div>
<div style="display:none"> Gerrit-Change-Number: 11246 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>