aboutsummaryrefslogtreecommitdiffstats
path: root/app.c
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-13 19:27:09 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-07-13 19:27:09 +0000
commit90a8bcf11ab1f795cf560ace7b60178a6c32a014 (patch)
tree859ad2ea8849226a0f89cbffd8d03220c5ab21d5 /app.c
parent553a20be66788ada158109ca2cc06d7e93e1a90b (diff)
fix up lock breakage from bug #4245
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6125 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'app.c')
-rwxr-xr-xapp.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/app.c b/app.c
index 5e5230e96..5f96478e3 100755
--- a/app.c
+++ b/app.c
@@ -1095,36 +1095,42 @@ int ast_separate_app_args(char *buf, char delim, char **array, int arraylen)
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)