aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-12 15:46:56 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-12 15:46:56 +0000
commitdc4160359b9924be7d84ff491598b332d90e9d6c (patch)
tree0741a4ee9ad1409237f6445592a52f4c9e41f406
parente8aef6fdfe0405465c49e184b0d974855b0ffe7d (diff)
fix a case where ast_lock_path() could leave a randomly-named lock file hanging around
make ast_unlock_path actually report when unlocking fails git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.2@37441 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--app.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/app.c b/app.c
index 64fa49fa7..a47776904 100644
--- a/app.c
+++ b/app.c
@@ -1167,11 +1167,13 @@ enum AST_LOCK_RESULT ast_lock_path(const char *path)
time(&start);
while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5))
usleep(1);
+
+ unlink(fs);
+
if (res) {
ast_log(LOG_WARNING, "Failed to lock path '%s': %s\n", path, strerror(errno));
return AST_LOCK_TIMEOUT;
} else {
- unlink(fs);
ast_log(LOG_DEBUG, "Locked path '%s'\n", path);
return AST_LOCK_SUCCESS;
}
@@ -1180,12 +1182,22 @@ enum AST_LOCK_RESULT ast_lock_path(const char *path)
int ast_unlock_path(const char *path)
{
char *s;
+ int res;
+
s = alloca(strlen(path) + 10);
- if (!s)
+ if (!s) {
+ ast_log(LOG_WARNING, "Out of memory!\n");
return -1;
+ }
+
snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
- ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path);
- return unlink(s);
+
+ if ((res = unlink(s)))
+ ast_log(LOG_ERROR, "Could not unlock path '%s': %s\n", path, strerror(errno));
+ else
+ ast_log(LOG_DEBUG, "Unlocked path '%s'\n", path);
+
+ return res;
}
int ast_record_review(struct ast_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, const char *path)