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
L
lsh
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
1
Issues
1
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
Operations
Operations
Incidents
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
LSH
lsh
Commits
7c10afdb
Commit
7c10afdb
authored
Dec 12, 2001
by
Niels Möller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(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
Showing
1 changed file
with
30 additions
and
5 deletions
+30
-5
src/lock_file.c
src/lock_file.c
+30
-5
No files found.
src/lock_file.c
View file @
7c10afdb
...
@@ -28,8 +28,12 @@
...
@@ -28,8 +28,12 @@
#include "format.h"
#include "format.h"
#include "resource.h"
#include "resource.h"
#include "werror.h"
#include "xalloc.h"
#include "xalloc.h"
#include <errno.h>
#include <string.h>
#if HAVE_UNISTD_H
#if HAVE_UNISTD_H
#include <unistd.h>
#include <unistd.h>
#endif
#endif
...
@@ -65,17 +69,38 @@ do_kill_file_lock(struct resource *s)
...
@@ -65,17 +69,38 @@ do_kill_file_lock(struct resource *s)
/* FIXME: Probably doesn't work right with NFS */
/* FIXME: Probably doesn't work right with NFS */
static
struct
resource
*
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
,
O_CREAT
|
O_EXCL
|
O_WRONLY
,
0666
);
0666
);
}
if
(
fd
<
0
)
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
else
{
{
NEW
(
lsh_file_lock
,
lock
);
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
);
init_resource
(
&
lock
->
super
,
do_kill_file_lock
);
lock
->
info
=
self
;
lock
->
info
=
self
;
...
@@ -86,7 +111,7 @@ do_lsh_file_lock(struct lsh_file_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. */
/* 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
)
do_lsh_file_lock_p
(
struct
lsh_file_lock_info
*
self
)
{
{
struct
stat
sbuf
;
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