diff options
author | Kevin P. Fleming <kpfleming@digium.com> | 2005-07-13 19:27:09 +0000 |
---|---|---|
committer | Kevin P. Fleming <kpfleming@digium.com> | 2005-07-13 19:27:09 +0000 |
commit | 9a7a5d56237c32bc59ea1e4be6d8591db9aab76b (patch) | |
tree | 859ad2ea8849226a0f89cbffd8d03220c5ab21d5 /app.c | |
parent | f62a613d241ce6587b82a5d6d55a3c6af775fb9d (diff) |
fix up lock breakage from bug #4245
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6125 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'app.c')
-rwxr-xr-x | app.c | 26 |
1 files changed, 16 insertions, 10 deletions
@@ -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) |