summaryrefslogtreecommitdiff
path: root/AuLock.c
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremy@yuffie.local>2009-02-22 11:14:04 -0800
committerJeremy Huddleston <jeremy@yuffie.local>2009-02-22 11:14:04 -0800
commitfc54a4f03b926dfdb590b112c7128516ffc25539 (patch)
tree939021775e321d5fe377a4532cbdd4e9cce1a681 /AuLock.c
parent742ff03dcad4d16ca8901ed47be91b303523a385 (diff)
Make file locking more robust for network shares like AFP
Diffstat (limited to 'AuLock.c')
-rw-r--r--AuLock.c30
1 files changed, 22 insertions, 8 deletions
diff --git a/AuLock.c b/AuLock.c
index 0012356..69b1fd6 100644
--- a/AuLock.c
+++ b/AuLock.c
@@ -90,14 +90,28 @@ long dead)
(void) close (creat_fd);
}
if (creat_fd != -1) {
- if (link (creat_name, link_name) != -1)
- return LOCK_SUCCESS;
- if (errno == ENOENT) {
- creat_fd = -1; /* force re-creat next time around */
- continue;
- }
- if (errno != EEXIST)
- return LOCK_ERROR;
+#ifndef X_NOT_POSIX
+ /* The file system may not support hard links, and pathconf should tell us that. */
+ if (1 == pathconf(creat_name, _PC_LINK_MAX)) {
+ if (-1 == rename(creat_name, link_name)) {
+ /* Is this good enough? Perhaps we should retry. TEST */
+ return LOCK_ERROR;
+ } else {
+ return LOCK_SUCCESS;
+ }
+ } else {
+#endif
+ if (link (creat_name, link_name) != -1)
+ return LOCK_SUCCESS;
+ if (errno == ENOENT) {
+ creat_fd = -1; /* force re-creat next time around */
+ continue;
+ }
+ if (errno != EEXIST)
+ return LOCK_ERROR;
+#ifndef X_NOT_POSIX
+ }
+#endif
}
(void) sleep ((unsigned) timeout);
--retries;