[asterisk-commits] branch 1.2 r37441 - /branches/1.2/app.c

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Wed Jul 12 08:46:57 MST 2006


Author: kpfleming
Date: Wed Jul 12 10:46:56 2006
New Revision: 37441

URL: http://svn.digium.com/view/asterisk?rev=37441&view=rev
Log:
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

Modified:
    branches/1.2/app.c

Modified: branches/1.2/app.c
URL: http://svn.digium.com/view/asterisk/branches/1.2/app.c?rev=37441&r1=37440&r2=37441&view=diff
==============================================================================
--- branches/1.2/app.c (original)
+++ branches/1.2/app.c Wed Jul 12 10:46:56 2006
@@ -1167,11 +1167,13 @@
 	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 @@
 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) 



More information about the asterisk-commits mailing list