diff options
author | Jeremy Huddleston <jeremy@yuffie.local> | 2009-02-22 11:14:04 -0800 |
---|---|---|
committer | Jeremy Huddleston <jeremy@yuffie.local> | 2009-02-22 11:14:04 -0800 |
commit | fc54a4f03b926dfdb590b112c7128516ffc25539 (patch) | |
tree | 939021775e321d5fe377a4532cbdd4e9cce1a681 /AuLock.c | |
parent | 742ff03dcad4d16ca8901ed47be91b303523a385 (diff) |
Make file locking more robust for network shares like AFP
Diffstat (limited to 'AuLock.c')
-rw-r--r-- | AuLock.c | 30 |
1 files changed, 22 insertions, 8 deletions
@@ -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; |