Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
emacs
emacs
Commits
7c4f6873
Commit
7c4f6873
authored
Apr 14, 2002
by
Colin Walters
Browse files
(lock_file): If the lock file is older than an hour, delete it. Reset
attempts to zero if we have to break the lock.
parent
4cb72a54
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
1 deletion
+9
-1
lib-src/update-game-score.c
lib-src/update-game-score.c
+9
-1
No files found.
lib-src/update-game-score.c
View file @
7c4f6873
...
...
@@ -416,6 +416,7 @@ int
lock_file
(
const
char
*
filename
,
void
**
state
)
{
int
fd
;
struct
stat
buf
;
int
attempts
=
0
;
char
*
lockext
=
".lockfile"
;
char
*
lockpath
=
malloc
(
strlen
(
filename
)
+
strlen
(
lockext
)
+
60
);
...
...
@@ -426,6 +427,10 @@ lock_file(const char *filename, void **state)
*
state
=
lockpath
;
trylock:
attempts
++
;
/* If the lock is over an hour old, delete it. */
if
(
stat
(
lockpath
,
&
buf
)
==
0
&&
(
difftime
(
buf
.
st_ctime
,
time
(
NULL
)
>
60
*
60
)))
unlink
(
lockpath
);
if
((
fd
=
open
(
lockpath
,
O_CREAT
|
O_EXCL
,
0600
))
<
0
)
{
if
(
errno
==
EEXIST
)
...
...
@@ -433,7 +438,10 @@ lock_file(const char *filename, void **state)
/* Break the lock; we won't corrupt the file, but we might
lose some scores. */
if
(
attempts
>
MAX_ATTEMPTS
)
unlink
(
lockpath
);
{
unlink
(
lockpath
);
attempts
=
0
;
}
sleep
((
rand
()
%
2
)
+
1
);
goto
trylock
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment