Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
LSH
lsh
Commits
7c10afdb
Commit
7c10afdb
authored
Dec 12, 2001
by
Niels Möller
Browse files
(do_lsh_file_lock): If locking fails,
optionally retry a few times. Rev: src/lock_file.c:1.3
parent
6cc2a3b3
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/lock_file.c
View file @
7c10afdb
...
...
@@ -28,8 +28,12 @@
#include "format.h"
#include "resource.h"
#include "werror.h"
#include "xalloc.h"
#include <errno.h>
#include <string.h>
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
...
...
@@ -65,17 +69,38 @@ do_kill_file_lock(struct resource *s)
/* FIXME: Probably doesn't work right with NFS */
static
struct
resource
*
do_lsh_file_lock
(
struct
lsh_file_lock_info
*
self
)
do_lsh_file_lock
(
struct
lsh_file_lock_info
*
self
,
unsigned
retries
)
{
int
fd
=
open
(
lsh_get_cstring
(
self
->
lockname
),
int
fd
=
-
1
;
unsigned
i
;
fd
=
open
(
lsh_get_cstring
(
self
->
lockname
),
O_CREAT
|
O_EXCL
|
O_WRONLY
,
0666
);
for
(
i
=
0
;
(
fd
<
0
)
&&
(
errno
==
EEXIST
)
&&
(
i
<
retries
);
i
++
)
{
/* Wait a few seconds and try again. */
sleep
(
17
);
fd
=
open
(
lsh_get_cstring
(
self
->
lockname
),
O_CREAT
|
O_EXCL
|
O_WRONLY
,
0666
);
}
if
(
fd
<
0
)
return
NULL
;
{
if
(
errno
!=
EEXIST
)
werror
(
"Could not create lock file `%S' (errno = %i): %z"
,
self
->
lockname
,
errno
,
STRERROR
(
errno
));
return
NULL
;
}
else
{
NEW
(
lsh_file_lock
,
lock
);
trace
(
"lock_file.c: Creation of lock file `%S' succeeded.
\n
"
,
self
->
lockname
);
init_resource
(
&
lock
->
super
,
do_kill_file_lock
);
lock
->
info
=
self
;
...
...
@@ -86,7 +111,7 @@ do_lsh_file_lock(struct lsh_file_lock_info *self)
}
/* Checks if a file is locked, without actually trying to lock it. */
static
struct
resource
*
static
int
do_lsh_file_lock_p
(
struct
lsh_file_lock_info
*
self
)
{
struct
stat
sbuf
;
...
...
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