[Asterisk-cvs] asterisk app.c,1.68,1.69
kpfleming at lists.digium.com
kpfleming at lists.digium.com
Wed Jul 13 15:19:09 CDT 2005
Update of /usr/cvsroot/asterisk
In directory mongoose.digium.com:/tmp/cvs-serv29146
Modified Files:
app.c
Log Message:
fix up lock breakage from bug #4245
Index: app.c
===================================================================
RCS file: /usr/cvsroot/asterisk/app.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- app.c 9 Jun 2005 19:27:19 -0000 1.68
+++ app.c 13 Jul 2005 19:27:09 -0000 1.69
@@ -1095,36 +1095,42 @@
return x;
}
-int ast_lock_path(const char *path)
+enum AST_LOCK_RESULT ast_lock_path(const char *path)
{
char *s;
char *fs;
int res;
int fd;
time_t start;
+
s = alloca(strlen(path) + 10);
fs = alloca(strlen(path) + 20);
+
if (!fs || !s) {
ast_log(LOG_WARNING, "Out of memory!\n");
- return -1;
+ return AST_LOCK_FAILURE;
}
- snprintf(fs, strlen(path) + 19, "%s/%s-%08x", path, ".lock", rand());
+
+ snprintf(fs, strlen(path) + 19, "%s/.lock-%08x", path, rand());
fd = open(fs, O_WRONLY | O_CREAT | O_EXCL, 0600);
if (fd < 0) {
- fprintf(stderr, "Unable to create lock file: %s\n", strerror(errno));
- return -1;
+ fprintf(stderr, "Unable to create lock file '%s': %s\n", path, strerror(errno));
+ return AST_LOCK_PATH_NOT_FOUND;
}
close(fd);
- snprintf(s, strlen(path) + 9, "%s/%s", path, ".lock");
+
+ snprintf(s, strlen(path) + 9, "%s/.lock", path);
time(&start);
while (((res = link(fs, s)) < 0) && (errno == EEXIST) && (time(NULL) - start < 5))
usleep(1);
- if (res < 0) {
+ 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;
}
- unlink(fs);
- ast_log(LOG_DEBUG, "Locked path '%s'\n", path);
- return res;
}
int ast_unlock_path(const char *path)
More information about the svn-commits
mailing list