summaryrefslogtreecommitdiffstats
path: root/dotlock.c
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1999-07-26 21:04:15 +0000
committerThomas Roessler <roessler@does-not-exist.org>1999-07-26 21:04:15 +0000
commit7b23687043bad611e5602233e3b51856f1617e88 (patch)
treed990d4dde2ac73e24b4cfe63a175a78638391398 /dotlock.c
parent472ae6c03a26f37d642c08144848fde03b46a983 (diff)
Impose a hard limit on dotlock attempts.
Diffstat (limited to 'dotlock.c')
-rw-r--r--dotlock.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/dotlock.c b/dotlock.c
index a9b891dd..5dfc2923 100644
--- a/dotlock.c
+++ b/dotlock.c
@@ -563,6 +563,8 @@ dotlock_deference_symlink(char *d, size_t l, const char *path)
*
*/
+#define HARDMAXATTEMPTS 10
+
static int
dotlock_lock(const char *realpath)
{
@@ -571,6 +573,7 @@ dotlock_lock(const char *realpath)
size_t prev_size = 0;
int fd;
int count = 0;
+ int hard_count = 0;
struct stat sb;
time_t t;
@@ -603,25 +606,25 @@ dotlock_lock(const char *realpath)
close(fd);
- while(1)
+ while (hard_count++ < HARDMAXATTEMPTS)
{
BEGIN_PRIVILEGED();
- link(nfslockfile, lockfile);
+ link (nfslockfile, lockfile);
END_PRIVILEGED();
- if(stat(nfslockfile, &sb) != 0)
+ if (stat(nfslockfile, &sb) != 0)
{
/* perror("stat"); */
return DL_EX_ERROR;
}
-
+
if(sb.st_nlink == 2)
break;
-
+
if(count == 0)
prev_size = sb.st_size;
-
+
if(prev_size == sb.st_size && ++count > Retry)
{
if(f_force)
@@ -653,7 +656,7 @@ dotlock_lock(const char *realpath)
sleep(1);
} while (time(NULL) == t);
}
-
+
BEGIN_PRIVILEGED();
unlink(nfslockfile);
END_PRIVILEGED();