From fc54a4f03b926dfdb590b112c7128516ffc25539 Mon Sep 17 00:00:00 2001 From: Jeremy Huddleston Date: Sun, 22 Feb 2009 11:14:04 -0800 Subject: Make file locking more robust for network shares like AFP --- AuLock.c | 30 ++++++++++++++++++++++-------- 1 file 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; -- cgit v1.2.3